Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Delphi ActiveX) SugarCRM Updating a RecordDemonstrates how to update a record in the Sugar instance using the / For more information, see https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_7.9/Integration/Web_Services/v10/Examples/Bash/How_to_Manipulate_Records_CRUD/#Updating_a_Record
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Chilkat_TLB; ... procedure TForm1.Button1Click(Sender: TObject); var http: TChilkatHttp; success: Integer; json: TChilkatJsonObject; sbRequestBody: TChilkatStringBuilder; resp: IChilkatHttpResponse; sbResponseBody: TChilkatStringBuilder; jResp: TChilkatJsonObject; respStatusCode: Integer; id: WideString; name: WideString; date_entered: WideString; date_modified: WideString; modified_user_id: WideString; modified_by_name: WideString; modified_user_linkFull_name: WideString; modified_user_linkId: WideString; modified_user_link_aclDelete: WideString; modified_user_link_acl_hash: WideString; created_by: WideString; created_by_name: WideString; created_by_linkFull_name: WideString; created_by_linkId: WideString; created_by_link_aclDelete: WideString; created_by_link_acl_hash: WideString; description: WideString; deleted: Integer; facebook: WideString; twitter: WideString; googleplus: WideString; account_type: WideString; industry: WideString; annual_revenue: WideString; phone_fax: WideString; billing_address_street: WideString; billing_address_street_2: WideString; billing_address_street_3: WideString; billing_address_street_4: WideString; billing_address_city: WideString; billing_address_state: WideString; billing_address_postalcode: WideString; billing_address_country: WideString; rating: WideString; phone_office: WideString; phone_alternate: WideString; website: WideString; ownership: WideString; employees: WideString; ticker_symbol: WideString; shipping_address_street: WideString; shipping_address_street_2: WideString; shipping_address_street_3: WideString; shipping_address_street_4: WideString; shipping_address_city: WideString; shipping_address_state: WideString; shipping_address_postalcode: WideString; shipping_address_country: WideString; parent_id: WideString; sic_code: WideString; duns_num: WideString; parent_name: WideString; member_ofName: WideString; member_ofId: WideString; member_of_acl_hash: WideString; campaign_id: WideString; campaign_name: WideString; campaign_accountsName: WideString; campaign_accountsId: WideString; campaign_accounts_acl_hash: WideString; following: Integer; my_favorite: Integer; assigned_user_id: WideString; assigned_user_name: WideString; assigned_user_linkFull_name: WideString; assigned_user_linkId: WideString; assigned_user_link_acl_hash: WideString; team_count: WideString; team_count_linkTeam_count: WideString; team_count_linkId: WideString; team_count_link_acl_hash: WideString; email1: WideString; email2: WideString; invalid_email: Integer; email_opt_out: Integer; email_addresses_non_primary: WideString; v_module: WideString; i: Integer; count_i: Integer; id_int: Integer; name_2: WideString; primary: Integer; email_address: WideString; opt_out: Integer; primary_address: Integer; reply_to_address: Integer; begin // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http := TChilkatHttp.Create(Self); // 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 := TChilkatJsonObject.Create(Self); json.UpdateString('name','Updated Record'); http.SetRequestHeader('Cache-Control','no-cache'); http.SetRequestHeader('OAuth-Token','<access_token>'); sbRequestBody := TChilkatStringBuilder.Create(Self); json.EmitSb(sbRequestBody.ControlInterface); resp := http.PTextSb('PUT','http://<site_url>/rest/v10/Accounts/<record_id>',sbRequestBody.ControlInterface,'utf-8','application/json',0,0); if (http.LastMethodSuccess = 0) then begin Memo1.Lines.Add(http.LastErrorText); Exit; end; sbResponseBody := TChilkatStringBuilder.Create(Self); resp.GetBodySb(sbResponseBody.ControlInterface); jResp := TChilkatJsonObject.Create(Self); jResp.LoadSb(sbResponseBody.ControlInterface); jResp.EmitCompact := 0; Memo1.Lines.Add('Response Body:'); Memo1.Lines.Add(jResp.Emit()); respStatusCode := resp.StatusCode; Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode)); if (respStatusCode >= 400) then begin Memo1.Lines.Add('Response Header:'); Memo1.Lines.Add(resp.Header); 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 := jResp.StringOf('id'); name := jResp.StringOf('name'); date_entered := jResp.StringOf('date_entered'); date_modified := jResp.StringOf('date_modified'); modified_user_id := jResp.StringOf('modified_user_id'); modified_by_name := jResp.StringOf('modified_by_name'); modified_user_linkFull_name := jResp.StringOf('modified_user_link.full_name'); modified_user_linkId := jResp.StringOf('modified_user_link.id'); modified_user_link_aclDelete := jResp.StringOf('modified_user_link._acl.delete'); modified_user_link_acl_hash := jResp.StringOf('modified_user_link._acl._hash'); created_by := jResp.StringOf('created_by'); created_by_name := jResp.StringOf('created_by_name'); created_by_linkFull_name := jResp.StringOf('created_by_link.full_name'); created_by_linkId := jResp.StringOf('created_by_link.id'); created_by_link_aclDelete := jResp.StringOf('created_by_link._acl.delete'); created_by_link_acl_hash := jResp.StringOf('created_by_link._acl._hash'); description := jResp.StringOf('description'); deleted := jResp.BoolOf('deleted'); facebook := jResp.StringOf('facebook'); twitter := jResp.StringOf('twitter'); googleplus := jResp.StringOf('googleplus'); account_type := jResp.StringOf('account_type'); industry := jResp.StringOf('industry'); annual_revenue := jResp.StringOf('annual_revenue'); phone_fax := jResp.StringOf('phone_fax'); billing_address_street := jResp.StringOf('billing_address_street'); billing_address_street_2 := jResp.StringOf('billing_address_street_2'); billing_address_street_3 := jResp.StringOf('billing_address_street_3'); billing_address_street_4 := jResp.StringOf('billing_address_street_4'); billing_address_city := jResp.StringOf('billing_address_city'); billing_address_state := jResp.StringOf('billing_address_state'); billing_address_postalcode := jResp.StringOf('billing_address_postalcode'); billing_address_country := jResp.StringOf('billing_address_country'); rating := jResp.StringOf('rating'); phone_office := jResp.StringOf('phone_office'); phone_alternate := jResp.StringOf('phone_alternate'); website := jResp.StringOf('website'); ownership := jResp.StringOf('ownership'); employees := jResp.StringOf('employees'); ticker_symbol := jResp.StringOf('ticker_symbol'); shipping_address_street := jResp.StringOf('shipping_address_street'); shipping_address_street_2 := jResp.StringOf('shipping_address_street_2'); shipping_address_street_3 := jResp.StringOf('shipping_address_street_3'); shipping_address_street_4 := jResp.StringOf('shipping_address_street_4'); shipping_address_city := jResp.StringOf('shipping_address_city'); shipping_address_state := jResp.StringOf('shipping_address_state'); shipping_address_postalcode := jResp.StringOf('shipping_address_postalcode'); shipping_address_country := jResp.StringOf('shipping_address_country'); parent_id := jResp.StringOf('parent_id'); sic_code := jResp.StringOf('sic_code'); duns_num := jResp.StringOf('duns_num'); parent_name := jResp.StringOf('parent_name'); member_ofName := jResp.StringOf('member_of.name'); member_ofId := jResp.StringOf('member_of.id'); member_of_acl_hash := jResp.StringOf('member_of._acl._hash'); campaign_id := jResp.StringOf('campaign_id'); campaign_name := jResp.StringOf('campaign_name'); campaign_accountsName := jResp.StringOf('campaign_accounts.name'); campaign_accountsId := jResp.StringOf('campaign_accounts.id'); campaign_accounts_acl_hash := jResp.StringOf('campaign_accounts._acl._hash'); following := jResp.BoolOf('following'); my_favorite := jResp.BoolOf('my_favorite'); assigned_user_id := jResp.StringOf('assigned_user_id'); assigned_user_name := jResp.StringOf('assigned_user_name'); assigned_user_linkFull_name := jResp.StringOf('assigned_user_link.full_name'); assigned_user_linkId := jResp.StringOf('assigned_user_link.id'); assigned_user_link_acl_hash := jResp.StringOf('assigned_user_link._acl._hash'); team_count := jResp.StringOf('team_count'); team_count_linkTeam_count := jResp.StringOf('team_count_link.team_count'); team_count_linkId := jResp.StringOf('team_count_link.id'); team_count_link_acl_hash := jResp.StringOf('team_count_link._acl._hash'); email1 := jResp.StringOf('email1'); email2 := jResp.StringOf('email2'); invalid_email := jResp.BoolOf('invalid_email'); email_opt_out := jResp.BoolOf('email_opt_out'); email_addresses_non_primary := jResp.StringOf('email_addresses_non_primary'); v_module := jResp.StringOf('_module'); i := 0; count_i := jResp.SizeOfArray('modified_user_link._acl.fields'); while i < count_i do begin jResp.I := i; i := i + 1; end; i := 0; count_i := jResp.SizeOfArray('created_by_link._acl.fields'); while i < count_i do begin jResp.I := i; i := i + 1; end; i := 0; count_i := jResp.SizeOfArray('member_of._acl.fields'); while i < count_i do begin jResp.I := i; i := i + 1; end; i := 0; count_i := jResp.SizeOfArray('campaign_accounts._acl.fields'); while i < count_i do begin jResp.I := i; i := i + 1; end; i := 0; count_i := jResp.SizeOfArray('tag'); while i < count_i do begin jResp.I := i; i := i + 1; end; i := 0; count_i := jResp.SizeOfArray('assigned_user_link._acl.fields'); while i < count_i do begin jResp.I := i; i := i + 1; end; i := 0; count_i := jResp.SizeOfArray('team_count_link._acl.fields'); while i < count_i do begin jResp.I := i; i := i + 1; end; i := 0; count_i := jResp.SizeOfArray('team_name'); while i < count_i do begin jResp.I := i; id_int := jResp.IntOf('team_name[i].id'); name := jResp.StringOf('team_name[i].name'); name_2 := jResp.StringOf('team_name[i].name_2'); primary := jResp.BoolOf('team_name[i].primary'); i := i + 1; end; i := 0; count_i := jResp.SizeOfArray('email'); while i < count_i do begin jResp.I := i; email_address := jResp.StringOf('email[i].email_address'); invalid_email := jResp.BoolOf('email[i].invalid_email'); opt_out := jResp.BoolOf('email[i].opt_out'); primary_address := jResp.BoolOf('email[i].primary_address'); reply_to_address := jResp.BoolOf('email[i].reply_to_address'); i := i + 1; end; end; |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.