Delphi DLL
/:record endpoint, and the PUT Http method. In this example we update the Account record and change it's name to "Updated Test Record".
Delphi DLL
SugarCRM Updating a Record
See more SugarCRM Examples
Demonstrates how to update a record in the Sugar instance using the /Chilkat Delphi DLL Downloads
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Http, StringBuilder, HttpResponse, JsonObject;
...
procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
http: HCkHttp;
json: HCkJsonObject;
sbRequestBody: HCkStringBuilder;
resp: HCkHttpResponse;
sbResponseBody: HCkStringBuilder;
jResp: HCkJsonObject;
respStatusCode: Integer;
id: PWideChar;
name: PWideChar;
date_entered: PWideChar;
date_modified: PWideChar;
modified_user_id: PWideChar;
modified_by_name: PWideChar;
modified_user_linkFull_name: PWideChar;
modified_user_linkId: PWideChar;
modified_user_link_aclDelete: PWideChar;
modified_user_link_acl_hash: PWideChar;
created_by: PWideChar;
created_by_name: PWideChar;
created_by_linkFull_name: PWideChar;
created_by_linkId: PWideChar;
created_by_link_aclDelete: PWideChar;
created_by_link_acl_hash: PWideChar;
description: PWideChar;
deleted: Boolean;
facebook: PWideChar;
twitter: PWideChar;
googleplus: PWideChar;
account_type: PWideChar;
industry: PWideChar;
annual_revenue: PWideChar;
phone_fax: PWideChar;
billing_address_street: PWideChar;
billing_address_street_2: PWideChar;
billing_address_street_3: PWideChar;
billing_address_street_4: PWideChar;
billing_address_city: PWideChar;
billing_address_state: PWideChar;
billing_address_postalcode: PWideChar;
billing_address_country: PWideChar;
rating: PWideChar;
phone_office: PWideChar;
phone_alternate: PWideChar;
website: PWideChar;
ownership: PWideChar;
employees: PWideChar;
ticker_symbol: PWideChar;
shipping_address_street: PWideChar;
shipping_address_street_2: PWideChar;
shipping_address_street_3: PWideChar;
shipping_address_street_4: PWideChar;
shipping_address_city: PWideChar;
shipping_address_state: PWideChar;
shipping_address_postalcode: PWideChar;
shipping_address_country: PWideChar;
parent_id: PWideChar;
sic_code: PWideChar;
duns_num: PWideChar;
parent_name: PWideChar;
member_ofName: PWideChar;
member_ofId: PWideChar;
member_of_acl_hash: PWideChar;
campaign_id: PWideChar;
campaign_name: PWideChar;
campaign_accountsName: PWideChar;
campaign_accountsId: PWideChar;
campaign_accounts_acl_hash: PWideChar;
following: Boolean;
my_favorite: Boolean;
assigned_user_id: PWideChar;
assigned_user_name: PWideChar;
assigned_user_linkFull_name: PWideChar;
assigned_user_linkId: PWideChar;
assigned_user_link_acl_hash: PWideChar;
team_count: PWideChar;
team_count_linkTeam_count: PWideChar;
team_count_linkId: PWideChar;
team_count_link_acl_hash: PWideChar;
email1: PWideChar;
email2: PWideChar;
invalid_email: Boolean;
email_opt_out: Boolean;
email_addresses_non_primary: PWideChar;
v_module: PWideChar;
i: Integer;
count_i: Integer;
id_int: Integer;
name_2: PWideChar;
primary: Boolean;
email_address: PWideChar;
opt_out: Boolean;
primary_address: Boolean;
reply_to_address: Boolean;
begin
success := False;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http := CkHttp_Create();
// Implements the following CURL command:
// curl -X PUT -H OAuth-Token:<access_token> -H Cache-Control:no-cache -d '{
// "name":"Updated Record"
// }' http://<site_url>/rest/v10/Accounts/<record_id>
// Use this online tool to generate code from sample JSON:
// Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "name": "Updated Record"
// }
json := CkJsonObject_Create();
CkJsonObject_UpdateString(json,'name','Updated Record');
CkHttp_SetRequestHeader(http,'Cache-Control','no-cache');
CkHttp_SetRequestHeader(http,'OAuth-Token','<access_token>');
sbRequestBody := CkStringBuilder_Create();
CkJsonObject_EmitSb(json,sbRequestBody);
resp := CkHttpResponse_Create();
success := CkHttp_HttpSb(http,'PUT','http://<site_url>/rest/v10/Accounts/<record_id>',sbRequestBody,'utf-8','application/json',resp);
if (success = False) then
begin
Memo1.Lines.Add(CkHttp__lastErrorText(http));
Exit;
end;
sbResponseBody := CkStringBuilder_Create();
CkHttpResponse_GetBodySb(resp,sbResponseBody);
jResp := CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,False);
Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(CkJsonObject__emit(jResp));
respStatusCode := CkHttpResponse_getStatusCode(resp);
Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
if (respStatusCode >= 400) then
begin
Memo1.Lines.Add('Response Header:');
Memo1.Lines.Add(CkHttpResponse__header(resp));
Memo1.Lines.Add('Failed.');
Exit;
end;
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "id": "ab2222df-73da-0e92-6887-5705428f4d68",
// "name": "Updated Test Record",
// "date_entered": "2016-04-06T15:03:21-04:00",
// "date_modified": "2016-04-06T15:03:22-04:00",
// "modified_user_id": "1",
// "modified_by_name": "Administrator",
// "modified_user_link": {
// "full_name": "Administrator",
// "id": "1",
// "_acl": {
// "fields": [
// ],
// "delete": "no",
// "_hash": "8e11bf9be8f04daddee9d08d44ea891e"
// }
// },
// "created_by": "1",
// "created_by_name": "Administrator",
// "created_by_link": {
// "full_name": "Administrator",
// "id": "1",
// "_acl": {
// "fields": [
// ],
// "delete": "no",
// "_hash": "8e11bf9be8f04daddee9d08d44ea891e"
// }
// },
// "description": "",
// "deleted": false,
// "facebook": "",
// "twitter": "",
// "googleplus": "",
// "account_type": "",
// "industry": "",
// "annual_revenue": "",
// "phone_fax": "",
// "billing_address_street": "",
// "billing_address_street_2": "",
// "billing_address_street_3": "",
// "billing_address_street_4": "",
// "billing_address_city": "",
// "billing_address_state": "",
// "billing_address_postalcode": "",
// "billing_address_country": "",
// "rating": "",
// "phone_office": "",
// "phone_alternate": "",
// "website": "",
// "ownership": "",
// "employees": "",
// "ticker_symbol": "",
// "shipping_address_street": "",
// "shipping_address_street_2": "",
// "shipping_address_street_3": "",
// "shipping_address_street_4": "",
// "shipping_address_city": "",
// "shipping_address_state": "",
// "shipping_address_postalcode": "",
// "shipping_address_country": "",
// "parent_id": "",
// "sic_code": "",
// "duns_num": "",
// "parent_name": "",
// "member_of": {
// "name": "",
// "id": "",
// "_acl": {
// "fields": [
// ],
// "_hash": "654d337e0e912edaa00dbb0fb3dc3c17"
// }
// },
// "campaign_id": "",
// "campaign_name": "",
// "campaign_accounts": {
// "name": "",
// "id": "",
// "_acl": {
// "fields": [
// ],
// "_hash": "654d337e0e912edaa00dbb0fb3dc3c17"
// }
// },
// "following": true,
// "my_favorite": false,
// "tag": [
// ],
// "assigned_user_id": "",
// "assigned_user_name": "",
// "assigned_user_link": {
// "full_name": "",
// "id": "",
// "_acl": {
// "fields": [
// ],
// "_hash": "654d337e0e912edaa00dbb0fb3dc3c17"
// }
// },
// "team_count": "",
// "team_count_link": {
// "team_count": "",
// "id": "1",
// "_acl": {
// "fields": [
// ],
// "_hash": "654d337e0e912edaa00dbb0fb3dc3c17"
// }
// },
// "team_name": [
// {
// "id": 1,
// "name": "Global",
// "name_2": "",
// "primary": true
// }
// ],
// "email": [
// {
// "email_address": "test@sugar.com",
// "invalid_email": false,
// "opt_out": false,
// "primary_address": true,
// "reply_to_address": false
// }
// ],
// "email1": "test@sugar.com",
// "email2": "",
// "invalid_email": false,
// "email_opt_out": false,
// "email_addresses_non_primary": "",
// "_acl": {
// "fields": {}
// },
// "_module": "Accounts"
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
id := CkJsonObject__stringOf(jResp,'id');
name := CkJsonObject__stringOf(jResp,'name');
date_entered := CkJsonObject__stringOf(jResp,'date_entered');
date_modified := CkJsonObject__stringOf(jResp,'date_modified');
modified_user_id := CkJsonObject__stringOf(jResp,'modified_user_id');
modified_by_name := CkJsonObject__stringOf(jResp,'modified_by_name');
modified_user_linkFull_name := CkJsonObject__stringOf(jResp,'modified_user_link.full_name');
modified_user_linkId := CkJsonObject__stringOf(jResp,'modified_user_link.id');
modified_user_link_aclDelete := CkJsonObject__stringOf(jResp,'modified_user_link._acl.delete');
modified_user_link_acl_hash := CkJsonObject__stringOf(jResp,'modified_user_link._acl._hash');
created_by := CkJsonObject__stringOf(jResp,'created_by');
created_by_name := CkJsonObject__stringOf(jResp,'created_by_name');
created_by_linkFull_name := CkJsonObject__stringOf(jResp,'created_by_link.full_name');
created_by_linkId := CkJsonObject__stringOf(jResp,'created_by_link.id');
created_by_link_aclDelete := CkJsonObject__stringOf(jResp,'created_by_link._acl.delete');
created_by_link_acl_hash := CkJsonObject__stringOf(jResp,'created_by_link._acl._hash');
description := CkJsonObject__stringOf(jResp,'description');
deleted := CkJsonObject_BoolOf(jResp,'deleted');
facebook := CkJsonObject__stringOf(jResp,'facebook');
twitter := CkJsonObject__stringOf(jResp,'twitter');
googleplus := CkJsonObject__stringOf(jResp,'googleplus');
account_type := CkJsonObject__stringOf(jResp,'account_type');
industry := CkJsonObject__stringOf(jResp,'industry');
annual_revenue := CkJsonObject__stringOf(jResp,'annual_revenue');
phone_fax := CkJsonObject__stringOf(jResp,'phone_fax');
billing_address_street := CkJsonObject__stringOf(jResp,'billing_address_street');
billing_address_street_2 := CkJsonObject__stringOf(jResp,'billing_address_street_2');
billing_address_street_3 := CkJsonObject__stringOf(jResp,'billing_address_street_3');
billing_address_street_4 := CkJsonObject__stringOf(jResp,'billing_address_street_4');
billing_address_city := CkJsonObject__stringOf(jResp,'billing_address_city');
billing_address_state := CkJsonObject__stringOf(jResp,'billing_address_state');
billing_address_postalcode := CkJsonObject__stringOf(jResp,'billing_address_postalcode');
billing_address_country := CkJsonObject__stringOf(jResp,'billing_address_country');
rating := CkJsonObject__stringOf(jResp,'rating');
phone_office := CkJsonObject__stringOf(jResp,'phone_office');
phone_alternate := CkJsonObject__stringOf(jResp,'phone_alternate');
website := CkJsonObject__stringOf(jResp,'website');
ownership := CkJsonObject__stringOf(jResp,'ownership');
employees := CkJsonObject__stringOf(jResp,'employees');
ticker_symbol := CkJsonObject__stringOf(jResp,'ticker_symbol');
shipping_address_street := CkJsonObject__stringOf(jResp,'shipping_address_street');
shipping_address_street_2 := CkJsonObject__stringOf(jResp,'shipping_address_street_2');
shipping_address_street_3 := CkJsonObject__stringOf(jResp,'shipping_address_street_3');
shipping_address_street_4 := CkJsonObject__stringOf(jResp,'shipping_address_street_4');
shipping_address_city := CkJsonObject__stringOf(jResp,'shipping_address_city');
shipping_address_state := CkJsonObject__stringOf(jResp,'shipping_address_state');
shipping_address_postalcode := CkJsonObject__stringOf(jResp,'shipping_address_postalcode');
shipping_address_country := CkJsonObject__stringOf(jResp,'shipping_address_country');
parent_id := CkJsonObject__stringOf(jResp,'parent_id');
sic_code := CkJsonObject__stringOf(jResp,'sic_code');
duns_num := CkJsonObject__stringOf(jResp,'duns_num');
parent_name := CkJsonObject__stringOf(jResp,'parent_name');
member_ofName := CkJsonObject__stringOf(jResp,'member_of.name');
member_ofId := CkJsonObject__stringOf(jResp,'member_of.id');
member_of_acl_hash := CkJsonObject__stringOf(jResp,'member_of._acl._hash');
campaign_id := CkJsonObject__stringOf(jResp,'campaign_id');
campaign_name := CkJsonObject__stringOf(jResp,'campaign_name');
campaign_accountsName := CkJsonObject__stringOf(jResp,'campaign_accounts.name');
campaign_accountsId := CkJsonObject__stringOf(jResp,'campaign_accounts.id');
campaign_accounts_acl_hash := CkJsonObject__stringOf(jResp,'campaign_accounts._acl._hash');
following := CkJsonObject_BoolOf(jResp,'following');
my_favorite := CkJsonObject_BoolOf(jResp,'my_favorite');
assigned_user_id := CkJsonObject__stringOf(jResp,'assigned_user_id');
assigned_user_name := CkJsonObject__stringOf(jResp,'assigned_user_name');
assigned_user_linkFull_name := CkJsonObject__stringOf(jResp,'assigned_user_link.full_name');
assigned_user_linkId := CkJsonObject__stringOf(jResp,'assigned_user_link.id');
assigned_user_link_acl_hash := CkJsonObject__stringOf(jResp,'assigned_user_link._acl._hash');
team_count := CkJsonObject__stringOf(jResp,'team_count');
team_count_linkTeam_count := CkJsonObject__stringOf(jResp,'team_count_link.team_count');
team_count_linkId := CkJsonObject__stringOf(jResp,'team_count_link.id');
team_count_link_acl_hash := CkJsonObject__stringOf(jResp,'team_count_link._acl._hash');
email1 := CkJsonObject__stringOf(jResp,'email1');
email2 := CkJsonObject__stringOf(jResp,'email2');
invalid_email := CkJsonObject_BoolOf(jResp,'invalid_email');
email_opt_out := CkJsonObject_BoolOf(jResp,'email_opt_out');
email_addresses_non_primary := CkJsonObject__stringOf(jResp,'email_addresses_non_primary');
v_module := CkJsonObject__stringOf(jResp,'_module');
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'modified_user_link._acl.fields');
while i < count_i do
begin
CkJsonObject_putI(jResp,i);
i := i + 1;
end;
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'created_by_link._acl.fields');
while i < count_i do
begin
CkJsonObject_putI(jResp,i);
i := i + 1;
end;
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'member_of._acl.fields');
while i < count_i do
begin
CkJsonObject_putI(jResp,i);
i := i + 1;
end;
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'campaign_accounts._acl.fields');
while i < count_i do
begin
CkJsonObject_putI(jResp,i);
i := i + 1;
end;
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'tag');
while i < count_i do
begin
CkJsonObject_putI(jResp,i);
i := i + 1;
end;
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'assigned_user_link._acl.fields');
while i < count_i do
begin
CkJsonObject_putI(jResp,i);
i := i + 1;
end;
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'team_count_link._acl.fields');
while i < count_i do
begin
CkJsonObject_putI(jResp,i);
i := i + 1;
end;
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'team_name');
while i < count_i do
begin
CkJsonObject_putI(jResp,i);
id_int := CkJsonObject_IntOf(jResp,'team_name[i].id');
name := CkJsonObject__stringOf(jResp,'team_name[i].name');
name_2 := CkJsonObject__stringOf(jResp,'team_name[i].name_2');
primary := CkJsonObject_BoolOf(jResp,'team_name[i].primary');
i := i + 1;
end;
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'email');
while i < count_i do
begin
CkJsonObject_putI(jResp,i);
email_address := CkJsonObject__stringOf(jResp,'email[i].email_address');
invalid_email := CkJsonObject_BoolOf(jResp,'email[i].invalid_email');
opt_out := CkJsonObject_BoolOf(jResp,'email[i].opt_out');
primary_address := CkJsonObject_BoolOf(jResp,'email[i].primary_address');
reply_to_address := CkJsonObject_BoolOf(jResp,'email[i].reply_to_address');
i := i + 1;
end;
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbRequestBody);
CkHttpResponse_Dispose(resp);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
end;