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
Linked Modules 2
mattkol edited this page Dec 18, 2016
·
7 revisions
This sample usage shows how to read "Accounts" module entity collection data with linked modules (link "Contacts" module). For more request options make changes to the [Options parameter](Request Options).
This implements the get_entry_list SugarCRM REST API method setting the link_name_to_fields_array parameter.
using SugarRestSharp;
using CustomModels;
using Newtonsoft.Json;
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.LinkedBulkRead);
request.Parameter = null;
request.Options.MaxResult = 5;
List<string> selectedFields = new List<string>();
selectedFields.Add(nameof(Account.Id));
selectedFields.Add(nameof(Account.Name));
selectedFields.Add(nameof(Account.Industry));
selectedFields.Add(nameof(Account.Website));
selectedFields.Add(nameof(Account.ShippingAddressCity));
request.Options.SelectFields = selectedFields;
Dictionary<object, List<string>> linkedListInfo = new Dictionary<object, List<string>>();
List<string> selectContactFields = new List<string>();
selectContactFields.Add(nameof(Contact.FirstName));
selectContactFields.Add(nameof(Contact.LastName));
selectContactFields.Add(nameof(Contact.Title));
selectContactFields.Add(nameof(Contact.Description));
selectContactFields.Add(nameof(Contact.PrimaryAddressPostalcode));
linkedListInfo[typeof(Contact)] = selectContactFields;
request.Options.LinkedModules = linkedListInfo;
SugarRestResponse response = client.Execute<Account>(request);
using Newtonsoft.Json;
using SugarRestSharp.Models;
using System.Collections.Generic;
public class CustomAcccount : Account
{
[JsonProperty(PropertyName = "contacts")]
public virtual List<Contact> ContactLink { get; set; }
}
Data = null;
// Deserialize json data to custom object
List<CustomAcccount> customAccounts = JsonConvert.DeserializeObject<List<CustomAcccount>>(response.JData);
[
{
"id": "28270ac1-2a6b-e674-b751-5777b5c57439",
"name": "X-Sell Holdings",
"industry": "Banking",
"website": "www.qaqa.co.uk",
"shipping_address_city": "Santa Fe",
"contacts": [
{
"first_name": "Benedict",
"last_name": "Vanzandt",
"title": "VP Sales",
"description": "",
"primary_address_postalcode": "93781"
},
{
"first_name": "Roxie",
"last_name": "Stamps",
"title": "IT Developer",
"description": "",
"primary_address_postalcode": "18342"
},
{
"first_name": "Dick",
"last_name": "Shipe",
"title": "Director Operations",
"description": "",
"primary_address_postalcode": "65363"
},
{
"first_name": "Buck",
"last_name": "Fraley",
"title": "Senior Product Manager",
"description": "",
"primary_address_postalcode": "23391"
},
{
"first_name": "Florence",
"last_name": "Klimas",
"title": "Director Operations",
"description": "",
"primary_address_postalcode": "45224"
},
{
"first_name": "Cheryl",
"last_name": "Coniglio",
"title": "Director Operations",
"description": "",
"primary_address_postalcode": "25516"
}
]
},
{
"id": "54bf59bc-ec61-1860-a97e-5777b5e92066",
"name": "Southern Realty",
"industry": "Telecommunications",
"website": "www.veganqa.tv",
"shipping_address_city": "Santa Monica",
"contacts": [
{
"first_name": "Cameron",
"last_name": "Vanwingerden",
"title": "IT Developer",
"description": "",
"primary_address_postalcode": "89219"
},
{
"first_name": "Jessica",
"last_name": "Mumma",
"title": "VP Sales",
"description": "",
"primary_address_postalcode": "26988"
},
{
"first_name": "Brianna",
"last_name": "Gleeson",
"title": "VP Operations",
"description": "",
"primary_address_postalcode": "70525"
},
{
"first_name": "Miles",
"last_name": "Gore",
"title": "Director Sales",
"description": "",
"primary_address_postalcode": "82591"
},
{
"first_name": "Georgia",
"last_name": "Brendel",
"title": "Director Sales",
"description": "",
"primary_address_postalcode": "63582"
}
]
},
{
"id": "66a60fba-47e4-9a8c-0774-5777b5c6aac9",
"name": "A.G. Parr PLC",
"industry": "Shipping",
"website": "www.beanskid.it",
"shipping_address_city": "Salt Lake City",
"contacts": [
{
"first_name": "Curt",
"last_name": "Turbeville",
"title": "VP Operations",
"description": "",
"primary_address_postalcode": "55320"
},
{
"first_name": "Jerry",
"last_name": "Allaire",
"title": "Director Sales",
"description": "",
"primary_address_postalcode": "77801"
},
{
"first_name": "Lillian",
"last_name": "Toombs",
"title": "VP Operations",
"description": "",
"primary_address_postalcode": "23790"
}
]
}
]
{
"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\":\"ohhkl3dfq1tj6ldafrj2i3usc0\",\"module_name\":\"Accounts\",\"query\":\"\",\"order_by\":\"\",\"offset\":0,\"select_fields\":[\"id\",\"name\",\"industry\",\"website\",\"shipping_address_city\"],\"link_name_to_fields_array\":[{\"name\":\"contacts\",\"value\":[\"first_name\",\"last_name\",\"title\",\"description\",\"primary_address_postalcode\"]}],\"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"
}
{
"statusCode": 200,
"content": "{\"result_count\":3,\"total_count\":\"50\",\"next_offset\":3,\"entry_list\":[{\"id\":\"28270ac1-2a6b-e674-b751-5777b5c57439\",\"module_name\":\"Accounts\",\"name_value_list\":{\"id\":{\"name\":\"id\",\"value\":\"28270ac1-2a6b-e674-b751-5777b5c57439\"},\"name\":{\"name\":\"name\",\"value\":\"X-Sell Holdings\"},\"industry\":{\"name\":\"industry\",\"value\":\"Banking\"},\"website\":{\"name\":\"website\",\"value\":\"www.qaqa.co.uk\"},\"shipping_address_city\":{\"name\":\"shipping_address_city\",\"value\":\"Santa Fe\"}}},{\"id\":\"54bf59bc-ec61-1860-a97e-5777b5e92066\",\"module_name\":\"Accounts\",\"name_value_list\":{\"id\":{\"name\":\"id\",\"value\":\"54bf59bc-ec61-1860-a97e-5777b5e92066\"},\"name\":{\"name\":\"name\",\"value\":\"Southern Realty\"},\"industry\":{\"name\":\"industry\",\"value\":\"Telecommunications\"},\"website\":{\"name\":\"website\",\"value\":\"www.veganqa.tv\"},\"shipping_address_city\":{\"name\":\"shipping_address_city\",\"value\":\"Santa Monica\"}}},{\"id\":\"66a60fba-47e4-9a8c-0774-5777b5c6aac9\",\"module_name\":\"Accounts\",\"name_value_list\":{\"id\":{\"name\":\"id\",\"value\":\"66a60fba-47e4-9a8c-0774-5777b5c6aac9\"},\"name\":{\"name\":\"name\",\"value\":\"A.G. Parr PLC\"},\"industry\":{\"name\":\"industry\",\"value\":\"Shipping\"},\"website\":{\"name\":\"website\",\"value\":\"www.beanskid.it\"},\"shipping_address_city\":{\"name\":\"shipping_address_city\",\"value\":\"Salt Lake City\"}}}],\"relationship_list\":[{\"link_list\":[{\"name\":\"contacts\",\"records\":[{\"link_value\":{\"first_name\":{\"name\":\"first_name\",\"value\":\"Benedict\"},\"last_name\":{\"name\":\"last_name\",\"value\":\"Vanzandt\"},\"title\":{\"name\":\"title\",\"value\":\"VP Sales\"},\"description\":{\"name\":\"description\",\"value\":\"\"},\"primary_address_postalcode\":{\"name\":\"primary_address_postalcode\",\"value\":\"93781\"}}},{\"link_value\":{\"first_name\":{\"name\":\"first_name\",\"value\":\"Roxie\"},\"last_name\":{\"name\":\"last_name\",\"value\":\"Stamps\"},\"title\":{\"name\":\"title\",\"value\":\"IT Developer\"},\"description\":{\"name\":\"description\",\"value\":\"\"},\"primary_address_postalcode\":{\"name\":\"primary_address_postalcode\",\"value\":\"18342\"}}},{\"link_value\":{\"first_name\":{\"name\":\"first_name\",\"value\":\"Dick\"},\"last_name\":{\"name\":\"last_name\",\"value\":\"Shipe\"},\"title\":{\"name\":\"title\",\"value\":\"Director Operations\"},\"description\":{\"name\":\"description\",\"value\":\"\"},\"primary_address_postalcode\":{\"name\":\"primary_address_postalcode\",\"value\":\"65363\"}}},{\"link_value\":{\"first_name\":{\"name\":\"first_name\",\"value\":\"Buck\"},\"last_name\":{\"name\":\"last_name\",\"value\":\"Fraley\"},\"title\":{\"name\":\"title\",\"value\":\"Senior Product Manager\"},\"description\":{\"name\":\"description\",\"value\":\"\"},\"primary_address_postalcode\":{\"name\":\"primary_address_postalcode\",\"value\":\"23391\"}}},{\"link_value\":{\"first_name\":{\"name\":\"first_name\",\"value\":\"Florence\"},\"last_name\":{\"name\":\"last_name\",\"value\":\"Klimas\"},\"title\":{\"name\":\"title\",\"value\":\"Director Operations\"},\"description\":{\"name\":\"description\",\"value\":\"\"},\"primary_address_postalcode\":{\"name\":\"primary_address_postalcode\",\"value\":\"45224\"}}},{\"link_value\":{\"first_name\":{\"name\":\"first_name\",\"value\":\"Cheryl\"},\"last_name\":{\"name\":\"last_name\",\"value\":\"Coniglio\"},\"title\":{\"name\":\"title\",\"value\":\"Director Operations\"},\"description\":{\"name\":\"description\",\"value\":\"\"},\"primary_address_postalcode\":{\"name\":\"primary_address_postalcode\",\"value\":\"25516\"}}}]}]},{\"link_list\":[{\"name\":\"contacts\",\"records\":[{\"link_value\":{\"first_name\":{\"name\":\"first_name\",\"value\":\"Cameron\"},\"last_name\":{\"name\":\"last_name\",\"value\":\"Vanwingerden\"},\"title\":{\"name\":\"title\",\"value\":\"IT Developer\"},\"description\":{\"name\":\"description\",\"value\":\"\"},\"primary_address_postalcode\":{\"name\":\"primary_address_postalcode\",\"value\":\"89219\"}}},{\"link_value\":{\"first_name\":{\"name\":\"first_name\",\"value\":\"Jessica\"},\"last_name\":{\"name\":\"last_name\",\"value\":\"Mumma\"},\"title\":{\"name\":\"title\",\"value\":\"VP Sales\"},\"description\":{\"name\":\"description\",\"value\":\"\"},\"primary_address_postalcode\":{\"name\":\"primary_address_postalcode\",\"value\":\"26988\"}}},{\"link_value\":{\"first_name\":{\"name\":\"first_name\",\"value\":\"Brianna\"},\"last_name\":{\"name\":\"last_name\",\"value\":\"Gleeson\"},\"title\":{\"name\":\"title\",\"value\":\"VP Operations\"},\"description\":{\"name\":\"description\",\"value\":\"\"},\"primary_address_postalcode\":{\"name\":\"primary_address_postalcode\",\"value\":\"70525\"}}},{\"link_value\":{\"first_name\":{\"name\":\"first_name\",\"value\":\"Miles\"},\"last_name\":{\"name\":\"last_name\",\"value\":\"Gore\"},\"title\":{\"name\":\"title\",\"value\":\"Director Sales\"},\"description\":{\"name\":\"description\",\"value\":\"\"},\"primary_address_postalcode\":{\"name\":\"primary_address_postalcode\",\"value\":\"82591\"}}},{\"link_value\":{\"first_name\":{\"name\":\"first_name\",\"value\":\"Georgia\"},\"last_name\":{\"name\":\"last_name\",\"value\":\"Brendel\"},\"title\":{\"name\":\"title\",\"value\":\"Director Sales\"},\"description\":{\"name\":\"description\",\"value\":\"\"},\"primary_address_postalcode\":{\"name\":\"primary_address_postalcode\",\"value\":\"63582\"}}}]}]},{\"link_list\":[{\"name\":\"contacts\",\"records\":[{\"link_value\":{\"first_name\":{\"name\":\"first_name\",\"value\":\"Curt\"},\"last_name\":{\"name\":\"last_name\",\"value\":\"Turbeville\"},\"title\":{\"name\":\"title\",\"value\":\"VP Operations\"},\"description\":{\"name\":\"description\",\"value\":\"\"},\"primary_address_postalcode\":{\"name\":\"primary_address_postalcode\",\"value\":\"55320\"}}},{\"link_value\":{\"first_name\":{\"name\":\"first_name\",\"value\":\"Jerry\"},\"last_name\":{\"name\":\"last_name\",\"value\":\"Allaire\"},\"title\":{\"name\":\"title\",\"value\":\"Director Sales\"},\"description\":{\"name\":\"description\",\"value\":\"\"},\"primary_address_postalcode\":{\"name\":\"primary_address_postalcode\",\"value\":\"77801\"}}},{\"link_value\":{\"first_name\":{\"name\":\"first_name\",\"value\":\"Lillian\"},\"last_name\":{\"name\":\"last_name\",\"value\":\"Toombs\"},\"title\":{\"name\":\"title\",\"value\":\"VP Operations\"},\"description\":{\"name\":\"description\",\"value\":\"\"},\"primary_address_postalcode\":{\"name\":\"primary_address_postalcode\",\"value\":\"23790\"}}}]}]}]}",
"headers": [
{
"Name": "Pragma",
"Value": "no-cache",
"Type": 3,
"ContentType": null
},
{
"Name": "Content-Length",
"Value": "5627",
"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 12:07:23 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=ohhkl3dfq1tj6ldafrj2i3usc0; 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