This repository has been archived by the owner on Oct 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Read Module Collection By Page
mattkol edited this page Dec 18, 2016
·
5 revisions
This sample usage shows how to read "Contacts" module entity collection data by page. It highlights usage of fields selection option. For more request options make changes to the [Options parameter](Request Options).
This also shows the async request.
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";
var client = new SugarRestClient(url, username, password);
var request = new SugarRestRequest(RequestType.PagedRead);
// Select fields.
List<string> selectFields = new List<string>();
selectFields.Add(nameof(Contact.FirstName));
// You can mix C# type and json type.
selectFields.Add("last_name");
request.Options.SelectFields = selectFields;
// Sets page options
request.Options.CurrentPage = 1;
request.Options.NumberPerPage = 10;
SugarRestResponse response = await client.ExecuteAsync<Contact>(request);
List<Contact> contacts = (List<Contact>)response.Data;
[
{
"first_name": "Casandra",
"last_name": "Adamek"
},
{
"first_name": "Jerry",
"last_name": "Allaire"
},
{
"first_name": "Clayton",
"last_name": "Antonucci"
},
{
"first_name": "Isabel",
"last_name": "Babineaux"
},
{
"first_name": "Antionette",
"last_name": "Bak"
},
{
"first_name": "Jenifer",
"last_name": "Bane"
},
{
"first_name": "Fidel",
"last_name": "Barbeau"
},
{
"first_name": "Pauline",
"last_name": "Beall"
},
{
"first_name": "Norman",
"last_name": "Beals"
},
{
"first_name": "Jeremy",
"last_name": "Beazley"
}
]
{
"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\":\"4cokjaoulof3gq9321e3614ks0\",\"module_name\":\"Contacts\",\"query\":\"\",\"order_by\":\"\",\"offset\":0,\"select_fields\":[\"first_name\",\"last_name\"],\"link_name_to_fields_array\":\"\",\"max_results\":10,\"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"
}
{
"statusCode": 200,
"content": "{\"result_count\":10,\"total_count\":\"202\",\"next_offset\":10,\"entry_list\":[{\"id\":\"5d94eba9-7d74-3d5b-ea4c-5777b52d4aa8\",\"module_name\":\"Contacts\",\"name_value_list\":{\"first_name\":{\"name\":\"first_name\",\"value\":\"Casandra\"},\"last_name\":{\"name\":\"last_name\",\"value\":\"Adamek\"}}},{\"id\":\"5f15a083-8425-522a-ccae-5777b5d642be\",\"module_name\":\"Contacts\",\"name_value_list\":{\"first_name\":{\"name\":\"first_name\",\"value\":\"Jerry\"},\"last_name\":{\"name\":\"last_name\",\"value\":\"Allaire\"}}},{\"id\":\"ca515799-217f-2f08-8941-5777b5c7121d\",\"module_name\":\"Contacts\",\"name_value_list\":{\"first_name\":{\"name\":\"first_name\",\"value\":\"Clayton\"},\"last_name\":{\"name\":\"last_name\",\"value\":\"Antonucci\"}}},{\"id\":\"c62d3b57-4cbb-48f1-c7cf-5777b514e6c2\",\"module_name\":\"Contacts\",\"name_value_list\":{\"first_name\":{\"name\":\"first_name\",\"value\":\"Isabel\"},\"last_name\":{\"name\":\"last_name\",\"value\":\"Babineaux\"}}},{\"id\":\"43853b34-d868-b2c2-0ff4-5777b5e93bf2\",\"module_name\":\"Contacts\",\"name_value_list\":{\"first_name\":{\"name\":\"first_name\",\"value\":\"Antionette\"},\"last_name\":{\"name\":\"last_name\",\"value\":\"Bak\"}}},{\"id\":\"68e97780-40ca-16e3-ba85-5777b5c2ebdb\",\"module_name\":\"Contacts\",\"name_value_list\":{\"first_name\":{\"name\":\"first_name\",\"value\":\"Jenifer\"},\"last_name\":{\"name\":\"last_name\",\"value\":\"Bane\"}}},{\"id\":\"ebe8fa2f-388c-f224-68bb-5777b5ce19a2\",\"module_name\":\"Contacts\",\"name_value_list\":{\"first_name\":{\"name\":\"first_name\",\"value\":\"Fidel\"},\"last_name\":{\"name\":\"last_name\",\"value\":\"Barbeau\"}}},{\"id\":\"18c96bca-d74d-9d9b-5711-5777b58059db\",\"module_name\":\"Contacts\",\"name_value_list\":{\"first_name\":{\"name\":\"first_name\",\"value\":\"Pauline\"},\"last_name\":{\"name\":\"last_name\",\"value\":\"Beall\"}}},{\"id\":\"a55e2d30-3904-1a11-7b1a-5777b53dcc8f\",\"module_name\":\"Contacts\",\"name_value_list\":{\"first_name\":{\"name\":\"first_name\",\"value\":\"Norman\"},\"last_name\":{\"name\":\"last_name\",\"value\":\"Beals\"}}},{\"id\":\"dcc0b00a-56b7-2995-ddc8-5777b59faee6\",\"module_name\":\"Contacts\",\"name_value_list\":{\"first_name\":{\"name\":\"first_name\",\"value\":\"Jeremy\"},\"last_name\":{\"name\":\"last_name\",\"value\":\"Beazley\"}}}],\"relationship_list\":[]}",
"headers": [
{
"Name": "Pragma",
"Value": "no-cache",
"Type": 3,
"ContentType": null
},
{
"Name": "Content-Length",
"Value": "2033",
"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:56:52 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=4cokjaoulof3gq9321e3614ks0; 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
}
SugarRestSharp
- Home
- Request
- Request Types
- Request Options
- Response
- Read Module By Id
- Read Module Collection By Page
- Read Module Collection
- Create Module
- Create Module Collection
- Update Module
- Update Module Collection
- Delete Module
- Linked Modules 1
- Linked Modules 2
- Linked Modules 3
- Query Options 1
- Query Options 2
- Query Options 3