Sample code for 30+ languages & platforms
Delphi DLL

SugarCRM Create a Record List

See more SugarCRM Examples

Create a record list in Sugar consisting of a set of ids.

Chilkat Delphi DLL Downloads

Delphi DLL
uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, StringBuilder, Rest, JsonObject;

...

procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
rest: HCkRest;
jsonReq: HCkJsonObject;
sbReq: HCkStringBuilder;
sbJson: HCkStringBuilder;
json: HCkJsonObject;
id: PWideChar;
assigned_user_id: PWideChar;
module_name: PWideChar;
date_modified: PWideChar;
i: Integer;
count_i: Integer;
strVal: PWideChar;

begin
success := False;

rest := CkRest_Create();

success := CkRest_Connect(rest,'your.site.domain',443,True,True);
if (success <> True) then
  begin
    Memo1.Lines.Add(CkRest__lastErrorText(rest));
    Exit;
  end;

CkRest_AddHeader(rest,'Cache-Control','no-cache');
CkRest_AddHeader(rest,'OAuth-Token','<access_token>');

// The following code creates the JSON request body.
// The JSON created by this code is shown below.
jsonReq := CkJsonObject_Create();
CkJsonObject_UpdateString(jsonReq,'records[0]','f16760a4-3a52-f77d-1522-5703ca28925f');
CkJsonObject_UpdateString(jsonReq,'records[1]','ec409fbb-2b22-4f32-7fa1-5703caf78dc3');

// The JSON request body created by the above code:

// {
//   "records": [
//     "f16760a4-3a52-f77d-1522-5703ca28925f",
//     "ec409fbb-2b22-4f32-7fa1-5703caf78dc3"
//   ]
// }

sbReq := CkStringBuilder_Create();
CkJsonObject_EmitSb(jsonReq,sbReq);

CkRest_AddHeader(rest,'Content-Type','application/json');

sbJson := CkStringBuilder_Create();
success := CkRest_FullRequestSb(rest,'POST','/rest/v10/Accounts/record_list',sbReq,sbJson);
if (success <> True) then
  begin
    Memo1.Lines.Add(CkRest__lastErrorText(rest));
    Exit;
  end;

if (CkRest_getResponseStatusCode(rest) <> 200) then
  begin
    Memo1.Lines.Add('Received error response code: ' + IntToStr(CkRest_getResponseStatusCode(rest)));
    Memo1.Lines.Add('Response body:');
    Memo1.Lines.Add(CkStringBuilder__getAsString(sbJson));
    Exit;
  end;

json := CkJsonObject_Create();
CkJsonObject_LoadSb(json,sbJson);

// The following code parses the JSON response.
// A sample JSON response is shown below the sample code.

id := CkJsonObject__stringOf(json,'id');
assigned_user_id := CkJsonObject__stringOf(json,'assigned_user_id');
module_name := CkJsonObject__stringOf(json,'module_name');
date_modified := CkJsonObject__stringOf(json,'date_modified');
i := 0;
count_i := CkJsonObject_SizeOfArray(json,'records');
while i < count_i do
  begin
    CkJsonObject_putI(json,i);
    strVal := CkJsonObject__stringOf(json,'records[i]');
    i := i + 1;
  end;

// A sample JSON response body that is parsed by the above code:

// {
//   "id": "ef963176-4845-bc55-b03e-570430b4173c",
//   "assigned_user_id": "1",
//   "module_name": "Accounts",
//   "records": [
//     "f16760a4-3a52-f77d-1522-5703ca28925f",
//     "ec409fbb-2b22-4f32-7fa1-5703caf78dc3"
//   ],
//   "date_modified": "2016-04-05 21:39:19"
// }

Memo1.Lines.Add('Example Completed.');

CkRest_Dispose(rest);
CkJsonObject_Dispose(jsonReq);
CkStringBuilder_Dispose(sbReq);
CkStringBuilder_Dispose(sbJson);
CkJsonObject_Dispose(json);

end;