Skip to content
This repository has been archived by the owner on Oct 12, 2021. It is now read-only.

Query Options 1

mattkol edited this page Dec 18, 2016 · 7 revisions

Basic Usage

This sample usage shows how to read "Cases" module entity collection data with query predicates. For more request options make changes to the [Options parameter](Request Options).

This implements the get_entry_list SugarCRM REST API method setting the query parameter.

using SugarRestSharp;

string url = "http://191.101.224.189/sugar/service/v4_1/rest.php";
string username = "will";
string password = "will";

var client = new SugarRestClient(url, username, password);

var request = new SugarRestRequest(RequestType.BulkRead);
request.Options.MaxResult = 3;

request.Options.QueryPredicates = new List<QueryPredicate>();
request.Options.QueryPredicates.Add(new QueryPredicate(nameof(Case.Name), QueryOperator.StartsWith, "Warning"));
request.Options.QueryPredicates.Add(new QueryPredicate("name", QueryOperator.Contains, "message"));
request.Options.QueryPredicates.Add(new QueryPredicate(nameof(Case.Status), QueryOperator.Equal, "Assigned"));
DateTime date = DateTime.Parse("07/02/2016");
request.Options.QueryPredicates.Add(new QueryPredicate(nameof(Case.DateEntered), 
                                              QueryOperator.Between, null, date.AddDays(-1), 
                                              DateTime.Now));

SugarRestResponse response = await client.ExecuteAsync<Case>(request);

Response (Data)

List<Case> cases = (List<Case>)response.Data;

Response (JData)

[
  {
    "assigned_user_name": "Sally Bronsen",
    "modified_by_name": "Administrator",
    "created_by_name": "Administrator",
    "id": "35958ef4-d1f3-e486-c952-5777b5585832",
    "name": "Warning message when using the wrong browser",
    "date_entered": "2016-07-02 12:36:44",
    "date_modified": "2016-07-02 12:36:44",
    "modified_user_id": "1",
    "created_by": "1",
    "description": "",
    "deleted": "0",
    "assigned_user_id": "seed_sally_id",
    "case_number": "33",
    "type": "",
    "status": "Assigned",
    "priority": "P1",
    "resolution": "",
    "work_log": "",
    "account_name": "360 Vacations",
    "account_name1": "",
    "account_id": "2b8eae60-d3c6-a655-c395-5777b5e69603"
  },
  {
    "assigned_user_name": "Chris Olliver",
    "modified_by_name": "Administrator",
    "created_by_name": "Administrator",
    "id": "cdd99d3c-24c2-0944-4f56-5777b5c03d8f",
    "name": "Warning message when using the wrong browser",
    "date_entered": "2016-07-02 12:36:44",
    "date_modified": "2016-07-02 12:36:44",
    "modified_user_id": "1",
    "created_by": "1",
    "description": "",
    "deleted": "0",
    "assigned_user_id": "seed_chris_id",
    "case_number": "50",
    "type": "",
    "status": "Assigned",
    "priority": "P3",
    "resolution": "",
    "work_log": "",
    "account_name": "Complete Holding",
    "account_name1": "",
    "account_id": "c4f1333b-d524-6562-ce77-5777b51048f7"
  }
]

Response (JsonRawRequest)

{
  "resource": "",
  "parameters": [
    {
      "name": "method",
      "value": "get_entry_list",
      "type": "GetOrPost"
    },
    {
      "name": "input_type",
      "value": "json",
      "type": "GetOrPost"
    },
    {
      "name": "response_type",
      "value": "json",
      "type": "GetOrPost"
    },
    {
      "name": "rest_data",
      "value": "{\"session\":\"scdu377t3mo17717hbf5o2qr56\",\"module_name\":\"Cases\",\"query\":\" cases.name LIKE 'Warning%' AND cases.name LIKE '%message%' AND cases.status = 'Assigned' AND cases.date_entered BETWEEN '2016-07-01 12:00:00 AM' AND '2016-12-18 8:17:25 AM' \",\"order_by\":\"\",\"offset\":0,\"select_fields\":[],\"link_name_to_fields_array\":\"\",\"max_results\":3,\"deleted\":0,\"favorites\":false}",
      "type": "GetOrPost"
    },
    {
      "name": "Accept",
      "value": "application\/json, application\/xml, text\/json, text\/x-json, text\/javascript, text\/xml",
      "type": "HttpHeader"
    }
  ],
  "method": "POST",
  "uri": "http:\/\/191.101.224.189\/sugar\/service\/v4_1\/rest.php"
}

Response (JsonRawResponse)

{
  "statusCode": 200,
  "content": "{\"result_count\":2,\"total_count\":\"2\",\"next_offset\":2,\"entry_list\":[{\"id\":\"35958ef4-d1f3-e486-c952-5777b5585832\",\"module_name\":\"Cases\",\"name_value_list\":{\"assigned_user_name\":{\"name\":\"assigned_user_name\",\"value\":\"Sally Bronsen\"},\"modified_by_name\":{\"name\":\"modified_by_name\",\"value\":\"Administrator\"},\"created_by_name\":{\"name\":\"created_by_name\",\"value\":\"Administrator\"},\"id\":{\"name\":\"id\",\"value\":\"35958ef4-d1f3-e486-c952-5777b5585832\"},\"name\":{\"name\":\"name\",\"value\":\"Warning message when using the wrong browser\"},\"date_entered\":{\"name\":\"date_entered\",\"value\":\"2016-07-02 12:36:44\"},\"date_modified\":{\"name\":\"date_modified\",\"value\":\"2016-07-02 12:36:44\"},\"modified_user_id\":{\"name\":\"modified_user_id\",\"value\":\"1\"},\"created_by\":{\"name\":\"created_by\",\"value\":\"1\"},\"description\":{\"name\":\"description\",\"value\":\"\"},\"deleted\":{\"name\":\"deleted\",\"value\":\"0\"},\"assigned_user_id\":{\"name\":\"assigned_user_id\",\"value\":\"seed_sally_id\"},\"case_number\":{\"name\":\"case_number\",\"value\":\"33\"},\"type\":{\"name\":\"type\",\"value\":\"\"},\"status\":{\"name\":\"status\",\"value\":\"Assigned\"},\"priority\":{\"name\":\"priority\",\"value\":\"P1\"},\"resolution\":{\"name\":\"resolution\",\"value\":\"\"},\"work_log\":{\"name\":\"work_log\",\"value\":\"\"},\"account_name\":{\"name\":\"account_name\",\"value\":\"360 Vacations\"},\"account_name1\":{\"name\":\"account_name1\",\"value\":\"\"},\"account_id\":{\"name\":\"account_id\",\"value\":\"2b8eae60-d3c6-a655-c395-5777b5e69603\"}}},{\"id\":\"cdd99d3c-24c2-0944-4f56-5777b5c03d8f\",\"module_name\":\"Cases\",\"name_value_list\":{\"assigned_user_name\":{\"name\":\"assigned_user_name\",\"value\":\"Chris Olliver\"},\"modified_by_name\":{\"name\":\"modified_by_name\",\"value\":\"Administrator\"},\"created_by_name\":{\"name\":\"created_by_name\",\"value\":\"Administrator\"},\"id\":{\"name\":\"id\",\"value\":\"cdd99d3c-24c2-0944-4f56-5777b5c03d8f\"},\"name\":{\"name\":\"name\",\"value\":\"Warning message when using the wrong browser\"},\"date_entered\":{\"name\":\"date_entered\",\"value\":\"2016-07-02 12:36:44\"},\"date_modified\":{\"name\":\"date_modified\",\"value\":\"2016-07-02 12:36:44\"},\"modified_user_id\":{\"name\":\"modified_user_id\",\"value\":\"1\"},\"created_by\":{\"name\":\"created_by\",\"value\":\"1\"},\"description\":{\"name\":\"description\",\"value\":\"\"},\"deleted\":{\"name\":\"deleted\",\"value\":\"0\"},\"assigned_user_id\":{\"name\":\"assigned_user_id\",\"value\":\"seed_chris_id\"},\"case_number\":{\"name\":\"case_number\",\"value\":\"50\"},\"type\":{\"name\":\"type\",\"value\":\"\"},\"status\":{\"name\":\"status\",\"value\":\"Assigned\"},\"priority\":{\"name\":\"priority\",\"value\":\"P3\"},\"resolution\":{\"name\":\"resolution\",\"value\":\"\"},\"work_log\":{\"name\":\"work_log\",\"value\":\"\"},\"account_name\":{\"name\":\"account_name\",\"value\":\"Complete Holding\"},\"account_name1\":{\"name\":\"account_name1\",\"value\":\"\"},\"account_id\":{\"name\":\"account_id\",\"value\":\"c4f1333b-d524-6562-ce77-5777b51048f7\"}}}],\"relationship_list\":[]}",
  "headers": [
    {
      "Name": "Pragma",
      "Value": "no-cache",
      "Type": 3,
      "ContentType": null
    },
    {
      "Name": "Content-Length",
      "Value": "2717",
      "Type": 3,
      "ContentType": null
    },
    {
      "Name": "Cache-Control",
      "Value": "no-store, no-cache, must-revalidate, post-check=0, pre-check=0",
      "Type": 3,
      "ContentType": null
    },
    {
      "Name": "Content-Type",
      "Value": "application\/json; charset=UTF-8",
      "Type": 3,
      "ContentType": null
    },
    {
      "Name": "Date",
      "Value": "Sun, 18 Dec 2016 13:17:47 GMT",
      "Type": 3,
      "ContentType": null
    },
    {
      "Name": "Expires",
      "Value": "Thu, 19 Nov 1981 08:52:00 GMT",
      "Type": 3,
      "ContentType": null
    },
    {
      "Name": "Set-Cookie",
      "Value": "PHPSESSID=scdu377t3mo17717hbf5o2qr56; path=\/",
      "Type": 3,
      "ContentType": null
    },
    {
      "Name": "Server",
      "Value": "Apache\/2.4.7 (Ubuntu)",
      "Type": 3,
      "ContentType": null
    },
    {
      "Name": "X-Powered-By",
      "Value": "PHP\/5.5.9-1ubuntu4.17",
      "Type": 3,
      "ContentType": null
    }
  ],
  "responseUri": "http:\/\/191.101.224.189\/sugar\/service\/v4_1\/rest.php",
  "errorMessage": null
}