This sample usage shows how to update "Bugs" module entity data. For more request options make changes to the Options parameter.
This implements the set_entry 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 readRequest = new SugarRestRequest("Bugs", RequestType.ReadById); string bugId = "e0b5b164-1bb4-65e9-5166-5855bfb57264"; readRequest.Parameter = bugId; SugarRestResponse bugReadResponse = client.Execute(readRequest); Bug bugToUpdate = (Bug)bugReadResponse.Data; var request = new SugarRestRequest(RequestType.Update); // Update description bugToUpdate.Description = "Now 7th floor printer"; request.Parameter = bugToUpdate; // Select fields. List<string> selectFields = new List<string>(); selectFields.Add(nameof(Bug.Name)); selectFields.Add(nameof(Bug.Description)); selectFields.Add(nameof(Bug.Status)); request.Options.SelectFields = selectFields; SugarRestResponse response = client.Execute<Bug>(request);
string updatedBugId = (string)response.Data;
"e0b5b164-1bb4-65e9-5166-5855bfb57264"
{ "resource": "", "parameters": [ { "name": "method", "value": "set_entry", "type": "GetOrPost" }, { "name": "input_type", "value": "json", "type": "GetOrPost" }, { "name": "response_type", "value": "json", "type": "GetOrPost" }, { "name": "rest_data", "value": "{\"session\":\"5d5rgiksi7qdivcu14ck80ahu2\",\"module_name\":\"Bugs\",\"name_value_list\":{\"id\":{\"name\":\"id\",\"value\":\"e0b5b164-1bb4-65e9-5166-5855bfb57264\"},\"name\":{\"name\":\"name\",\"value\":\"System crashed while running new photo upload.\"},\"description\":{\"name\":\"description\",\"value\":\"Now 7th floor printer\"},\"status\":{\"name\":\"status\",\"value\":\"Pending\"}}}", "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": "{\"id\":\"e0b5b164-1bb4-65e9-5166-5855bfb57264\",\"entry_list\":{\"id\":{\"name\":\"id\",\"value\":\"e0b5b164-1bb4-65e9-5166-5855bfb57264\"},\"name\":{\"name\":\"name\",\"value\":\"System crashed while running new photo upload.\"},\"description\":{\"name\":\"description\",\"value\":\"Now 7th floor printer\"},\"status\":{\"name\":\"status\",\"value\":\"Pending\"}}}", "headers": [ { "Name": "Pragma", "Value": "no-cache", "Type": 3, "ContentType": null }, { "Name": "Content-Length", "Value": "320", "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 23:37:26 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=5d5rgiksi7qdivcu14ck80ahu2; 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 }
Wiki: Home
Wiki: Request Options
Wiki: Welcome to SugarRestSharp wiki!
Wiki: _Sidebar