Menu

Read Module Collection

Kola Oyewumi

Basic Usage

This sample usage shows how to read "Cases" module entity collection data. It highlights usage of fields selection option. For more request options make changes to the Options parameter.

This implements the get_entry_list SugarCRM REST API method.

using SugarRestSharp;

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

string moduleName = "Cases";

var client = new SugarRestClient(url, username, password);
var request = new SugarRestRequest(moduleName, RequestType.BulkRead);

// Parameter can be set to null or leave unset.
request.Parameter = null;

// Select fields.
List<string> selectFields = new List<string>();
selectFields.Add(nameof(Case.Id));
selectFields.Add(nameof(Case.Name));

// You can mix C# type and json type.
selectFields.Add("status");
selectFields.Add("created_by");

request.Options.SelectFields = selectFields;

// Select only 5 entities.
// 5 is maximum, if all cases less than 5, less than 5 will be returned.
request.Options.MaxResult = 5;
SugarRestResponse response = client.Execute(request);

Response (Data)

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

Response (JData)

[
  {
    "id": "10fff1e1-c0fa-6ea1-56bb-5777b523ca95",
    "name": "Need assistance with large customization",
    "status": "New",
    "created_by": "1"
  },
  {
    "id": "162e01d1-a3a9-9bd1-8ce4-5777b5a9fc95",
    "name": "System not responding",
    "status": "Rejected",
    "created_by": "1"
  },
  {
    "id": "1633cd12-7ef4-dcc0-a28c-5777b5ec8115",
    "name": "System not responding",
    "status": "Closed",
    "created_by": "1"
  },
  {
    "id": "24aac5a6-bbb7-03e7-6f9d-5777b511d38a",
    "name": "Need to purchase additional licenses",
    "status": "New",
    "created_by": "1"
  },
  {
    "id": "2c8d193b-8c5b-8cb4-1972-5777b528a47b",
    "name": "Need to purchase additional licenses",
    "status": "Pending Input",
    "created_by": "1"
  }
]

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\":\"lraj27dei2lu66aagipoi27qf4\",\"module_name\":\"Cases\",\"query\":\"\",\"order_by\":\"\",\"offset\":0,\"select_fields\":[\"id\",\"name\",\"status\",\"created_by\"],\"link_name_to_fields_array\":\"\",\"max_results\":5,\"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\":5,\"total_count\":\"50\",\"next_offset\":5,\"entry_list\":[{\"id\":\"10fff1e1-c0fa-6ea1-56bb-5777b523ca95\",\"module_name\":\"Cases\",\"name_value_list\":{\"id\":{\"name\":\"id\",\"value\":\"10fff1e1-c0fa-6ea1-56bb-5777b523ca95\"},\"name\":{\"name\":\"name\",\"value\":\"Need assistance with large customization\"},\"status\":{\"name\":\"status\",\"value\":\"New\"},\"created_by\":{\"name\":\"created_by\",\"value\":\"1\"}}},{\"id\":\"162e01d1-a3a9-9bd1-8ce4-5777b5a9fc95\",\"module_name\":\"Cases\",\"name_value_list\":{\"id\":{\"name\":\"id\",\"value\":\"162e01d1-a3a9-9bd1-8ce4-5777b5a9fc95\"},\"name\":{\"name\":\"name\",\"value\":\"System not responding\"},\"status\":{\"name\":\"status\",\"value\":\"Rejected\"},\"created_by\":{\"name\":\"created_by\",\"value\":\"1\"}}},{\"id\":\"1633cd12-7ef4-dcc0-a28c-5777b5ec8115\",\"module_name\":\"Cases\",\"name_value_list\":{\"id\":{\"name\":\"id\",\"value\":\"1633cd12-7ef4-dcc0-a28c-5777b5ec8115\"},\"name\":{\"name\":\"name\",\"value\":\"System not responding\"},\"status\":{\"name\":\"status\",\"value\":\"Closed\"},\"created_by\":{\"name\":\"created_by\",\"value\":\"1\"}}},{\"id\":\"24aac5a6-bbb7-03e7-6f9d-5777b511d38a\",\"module_name\":\"Cases\",\"name_value_list\":{\"id\":{\"name\":\"id\",\"value\":\"24aac5a6-bbb7-03e7-6f9d-5777b511d38a\"},\"name\":{\"name\":\"name\",\"value\":\"Need to purchase additional licenses\"},\"status\":{\"name\":\"status\",\"value\":\"New\"},\"created_by\":{\"name\":\"created_by\",\"value\":\"1\"}}},{\"id\":\"2c8d193b-8c5b-8cb4-1972-5777b528a47b\",\"module_name\":\"Cases\",\"name_value_list\":{\"id\":{\"name\":\"id\",\"value\":\"2c8d193b-8c5b-8cb4-1972-5777b528a47b\"},\"name\":{\"name\":\"name\",\"value\":\"Need to purchase additional licenses\"},\"status\":{\"name\":\"status\",\"value\":\"Pending Input\"},\"created_by\":{\"name\":\"created_by\",\"value\":\"1\"}}}],\"relationship_list\":[]}",
  "headers": [
    {
      "Name": "Pragma",
      "Value": "no-cache",
      "Type": 3,
      "ContentType": null
    },
    {
      "Name": "Content-Length",
      "Value": "1643",
      "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": "Sat, 17 Dec 2016 21:40:10 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=lraj27dei2lu66aagipoi27qf4; 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
}

Related

Wiki: Home
Wiki: Request Options
Wiki: Welcome to SugarRestSharp wiki!
Wiki: _Sidebar

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.