Menu

Create Module Collection

Kola Oyewumi

Basic Usage

This sample usage shows how to create "Bugs" module entity collection data. For more request options make changes to the Options parameter.

This implements the set_entries 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.BulkCreate);

Bug bugToCreate1 = new Bug();
bugToCreate1.Name = "System crashed while running new photo upload.";
bugToCreate1.Description = "Tumblr app";
bugToCreate1.Status = "Pending";

Bug bugToCreate2 = new Bug();
bugToCreate2.Name = "Warning is displayed in file after exporting.";
bugToCreate2.Description = "";
bugToCreate2.Status = "New";

Bug bugToCreate3 = new Bug();
bugToCreate3.Name = "Fatal error during installation.";
bugToCreate3.Description = "Fifth floor printer.";
bugToCreate3.Status = "Closed";

List<Bug> bugsToCreate = new List<Bug>();
bugsToCreate.Add(bugToCreate1);
bugsToCreate.Add(bugToCreate2);
bugsToCreate.Add(bugToCreate3);

request.Parameter = bugsToCreate;

// 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);

Response (Data)

List<string> createdBugIds = (List<string>)response.Data;

Response (JData)

[
  "e0b5b164-1bb4-65e9-5166-5855bfb57264",
  "e17fd976-d109-a0cb-87e7-5855bf00f6f7",
  "e1e827c0-102b-966c-0d38-5855bfa55a24"
]

Response (JsonRawRequest)

{
  "resource": "",
  "parameters": [
    {
      "name": "method",
      "value": "set_entries",
      "type": "GetOrPost"
    },
    {
      "name": "input_type",
      "value": "json",
      "type": "GetOrPost"
    },
    {
      "name": "response_type",
      "value": "json",
      "type": "GetOrPost"
    },
    {
      "name": "rest_data",
      "value": "{\"session\":\"af0e1jfidpm97vftgos7ii67e6\",\"module_name\":\"Bugs\",\"name_value_lists\":[{\"name\":{\"name\":\"name\",\"value\":\"System crashed while running new photo upload.\"},\"description\":{\"name\":\"description\",\"value\":\"Tumblr app\"},\"status\":{\"name\":\"status\",\"value\":\"Pending\"}},{\"name\":{\"name\":\"name\",\"value\":\"Warning is displayed in file after exporting.\"},\"description\":{\"name\":\"description\",\"value\":\"\"},\"status\":{\"name\":\"status\",\"value\":\"New\"}},{\"name\":{\"name\":\"name\",\"value\":\"Fatal error during installation.\"},\"description\":{\"name\":\"description\",\"value\":\"Fifth floor printer.\"},\"status\":{\"name\":\"status\",\"value\":\"Closed\"}}]}",
      "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": "{\"ids\":[\"e0b5b164-1bb4-65e9-5166-5855bfb57264\",\"e17fd976-d109-a0cb-87e7-5855bf00f6f7\",\"e1e827c0-102b-966c-0d38-5855bfa55a24\"]}",
  "headers": [
    {
      "Name": "Pragma",
      "Value": "no-cache",
      "Type": 3,
      "ContentType": null
    },
    {
      "Name": "Content-Length",
      "Value": "126",
      "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 22:41:30 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=af0e1jfidpm97vftgos7ii67e6; 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.