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
(PureBasic) SugarCRM Create a RecordSubmit a record to 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/#Creating_a_Record
IncludeFile "CkHttpResponse.pb" IncludeFile "CkHttp.pb" IncludeFile "CkStringBuilder.pb" IncludeFile "CkJsonObject.pb" Procedure ChilkatExample() ; This example assumes the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. http.i = CkHttp::ckCreate() If http.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success.i ; Implements the following CURL command: ; curl -X POST -H OAuth-Token:<access_token> -H Cache-Control:no-cache -d '{ ; "name":"Test Record", ; "email1":"test@sugar.com" ; }' http://<site_url>/rest/v10/Accounts ; 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": "Test Record", ; "email1": "test@sugar.com" ; } json.i = CkJsonObject::ckCreate() If json.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckUpdateString(json,"name","Test Record") CkJsonObject::ckUpdateString(json,"email1","test@sugar.com") CkHttp::ckSetRequestHeader(http,"Cache-Control","no-cache") CkHttp::ckSetRequestHeader(http,"OAuth-Token","<access_token>") resp.i = CkHttp::ckPostJson3(http,"http://<site_url>/rest/v10/Accounts","application/json",json) If CkHttp::ckLastMethodSuccess(http) = 0 Debug CkHttp::ckLastErrorText(http) CkHttp::ckDispose(http) CkJsonObject::ckDispose(json) ProcedureReturn EndIf sbResponseBody.i = CkStringBuilder::ckCreate() If sbResponseBody.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkHttpResponse::ckGetBodySb(resp,sbResponseBody) jResp.i = CkJsonObject::ckCreate() If jResp.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckLoadSb(jResp,sbResponseBody) CkJsonObject::setCkEmitCompact(jResp, 0) Debug "Response Body:" Debug CkJsonObject::ckEmit(jResp) respStatusCode.i = CkHttpResponse::ckStatusCode(resp) Debug "Response Status Code = " + Str(respStatusCode) If respStatusCode >= 400 Debug "Response Header:" Debug CkHttpResponse::ckHeader(resp) Debug "Failed." CkHttpResponse::ckDispose(resp) CkHttp::ckDispose(http) CkJsonObject::ckDispose(json) CkStringBuilder::ckDispose(sbResponseBody) CkJsonObject::ckDispose(jResp) ProcedureReturn EndIf CkHttpResponse::ckDispose(resp) ; Sample JSON response: ; (Sample code for parsing the JSON response is shown below) ; { ; "id": "ab2222df-73da-0e92-6887-5705428f4d68", ; "name": "Test Record", ; "date_entered": "2016-04-06T13:07:41-04:00", ; "date_modified": "2016-04-06T13:07:41-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.s name.s date_entered.s date_modified.s modified_user_id.s modified_by_name.s modified_user_linkFull_name.s modified_user_linkId.s modified_user_link_aclDelete.s modified_user_link_acl_hash.s created_by.s created_by_name.s created_by_linkFull_name.s created_by_linkId.s created_by_link_aclDelete.s created_by_link_acl_hash.s description.s deleted.i facebook.s twitter.s googleplus.s account_type.s industry.s annual_revenue.s phone_fax.s billing_address_street.s billing_address_street_2.s billing_address_street_3.s billing_address_street_4.s billing_address_city.s billing_address_state.s billing_address_postalcode.s billing_address_country.s rating.s phone_office.s phone_alternate.s website.s ownership.s employees.s ticker_symbol.s shipping_address_street.s shipping_address_street_2.s shipping_address_street_3.s shipping_address_street_4.s shipping_address_city.s shipping_address_state.s shipping_address_postalcode.s shipping_address_country.s parent_id.s sic_code.s duns_num.s parent_name.s member_ofName.s member_ofId.s member_of_acl_hash.s campaign_id.s campaign_name.s campaign_accountsName.s campaign_accountsId.s campaign_accounts_acl_hash.s following.i my_favorite.i assigned_user_id.s assigned_user_name.s assigned_user_linkFull_name.s assigned_user_linkId.s assigned_user_link_acl_hash.s team_count.s team_count_linkTeam_count.s team_count_linkId.s team_count_link_acl_hash.s email1.s email2.s invalid_email.i email_opt_out.i email_addresses_non_primary.s v_module.s i.i count_i.i id_int.i name_2.s primary.i email_address.s opt_out.i primary_address.i reply_to_address.i id = CkJsonObject::ckStringOf(jResp,"id") name = CkJsonObject::ckStringOf(jResp,"name") date_entered = CkJsonObject::ckStringOf(jResp,"date_entered") date_modified = CkJsonObject::ckStringOf(jResp,"date_modified") modified_user_id = CkJsonObject::ckStringOf(jResp,"modified_user_id") modified_by_name = CkJsonObject::ckStringOf(jResp,"modified_by_name") modified_user_linkFull_name = CkJsonObject::ckStringOf(jResp,"modified_user_link.full_name") modified_user_linkId = CkJsonObject::ckStringOf(jResp,"modified_user_link.id") modified_user_link_aclDelete = CkJsonObject::ckStringOf(jResp,"modified_user_link._acl.delete") modified_user_link_acl_hash = CkJsonObject::ckStringOf(jResp,"modified_user_link._acl._hash") created_by = CkJsonObject::ckStringOf(jResp,"created_by") created_by_name = CkJsonObject::ckStringOf(jResp,"created_by_name") created_by_linkFull_name = CkJsonObject::ckStringOf(jResp,"created_by_link.full_name") created_by_linkId = CkJsonObject::ckStringOf(jResp,"created_by_link.id") created_by_link_aclDelete = CkJsonObject::ckStringOf(jResp,"created_by_link._acl.delete") created_by_link_acl_hash = CkJsonObject::ckStringOf(jResp,"created_by_link._acl._hash") description = CkJsonObject::ckStringOf(jResp,"description") deleted = CkJsonObject::ckBoolOf(jResp,"deleted") facebook = CkJsonObject::ckStringOf(jResp,"facebook") twitter = CkJsonObject::ckStringOf(jResp,"twitter") googleplus = CkJsonObject::ckStringOf(jResp,"googleplus") account_type = CkJsonObject::ckStringOf(jResp,"account_type") industry = CkJsonObject::ckStringOf(jResp,"industry") annual_revenue = CkJsonObject::ckStringOf(jResp,"annual_revenue") phone_fax = CkJsonObject::ckStringOf(jResp,"phone_fax") billing_address_street = CkJsonObject::ckStringOf(jResp,"billing_address_street") billing_address_street_2 = CkJsonObject::ckStringOf(jResp,"billing_address_street_2") billing_address_street_3 = CkJsonObject::ckStringOf(jResp,"billing_address_street_3") billing_address_street_4 = CkJsonObject::ckStringOf(jResp,"billing_address_street_4") billing_address_city = CkJsonObject::ckStringOf(jResp,"billing_address_city") billing_address_state = CkJsonObject::ckStringOf(jResp,"billing_address_state") billing_address_postalcode = CkJsonObject::ckStringOf(jResp,"billing_address_postalcode") billing_address_country = CkJsonObject::ckStringOf(jResp,"billing_address_country") rating = CkJsonObject::ckStringOf(jResp,"rating") phone_office = CkJsonObject::ckStringOf(jResp,"phone_office") phone_alternate = CkJsonObject::ckStringOf(jResp,"phone_alternate") website = CkJsonObject::ckStringOf(jResp,"website") ownership = CkJsonObject::ckStringOf(jResp,"ownership") employees = CkJsonObject::ckStringOf(jResp,"employees") ticker_symbol = CkJsonObject::ckStringOf(jResp,"ticker_symbol") shipping_address_street = CkJsonObject::ckStringOf(jResp,"shipping_address_street") shipping_address_street_2 = CkJsonObject::ckStringOf(jResp,"shipping_address_street_2") shipping_address_street_3 = CkJsonObject::ckStringOf(jResp,"shipping_address_street_3") shipping_address_street_4 = CkJsonObject::ckStringOf(jResp,"shipping_address_street_4") shipping_address_city = CkJsonObject::ckStringOf(jResp,"shipping_address_city") shipping_address_state = CkJsonObject::ckStringOf(jResp,"shipping_address_state") shipping_address_postalcode = CkJsonObject::ckStringOf(jResp,"shipping_address_postalcode") shipping_address_country = CkJsonObject::ckStringOf(jResp,"shipping_address_country") parent_id = CkJsonObject::ckStringOf(jResp,"parent_id") sic_code = CkJsonObject::ckStringOf(jResp,"sic_code") duns_num = CkJsonObject::ckStringOf(jResp,"duns_num") parent_name = CkJsonObject::ckStringOf(jResp,"parent_name") member_ofName = CkJsonObject::ckStringOf(jResp,"member_of.name") member_ofId = CkJsonObject::ckStringOf(jResp,"member_of.id") member_of_acl_hash = CkJsonObject::ckStringOf(jResp,"member_of._acl._hash") campaign_id = CkJsonObject::ckStringOf(jResp,"campaign_id") campaign_name = CkJsonObject::ckStringOf(jResp,"campaign_name") campaign_accountsName = CkJsonObject::ckStringOf(jResp,"campaign_accounts.name") campaign_accountsId = CkJsonObject::ckStringOf(jResp,"campaign_accounts.id") campaign_accounts_acl_hash = CkJsonObject::ckStringOf(jResp,"campaign_accounts._acl._hash") following = CkJsonObject::ckBoolOf(jResp,"following") my_favorite = CkJsonObject::ckBoolOf(jResp,"my_favorite") assigned_user_id = CkJsonObject::ckStringOf(jResp,"assigned_user_id") assigned_user_name = CkJsonObject::ckStringOf(jResp,"assigned_user_name") assigned_user_linkFull_name = CkJsonObject::ckStringOf(jResp,"assigned_user_link.full_name") assigned_user_linkId = CkJsonObject::ckStringOf(jResp,"assigned_user_link.id") assigned_user_link_acl_hash = CkJsonObject::ckStringOf(jResp,"assigned_user_link._acl._hash") team_count = CkJsonObject::ckStringOf(jResp,"team_count") team_count_linkTeam_count = CkJsonObject::ckStringOf(jResp,"team_count_link.team_count") team_count_linkId = CkJsonObject::ckStringOf(jResp,"team_count_link.id") team_count_link_acl_hash = CkJsonObject::ckStringOf(jResp,"team_count_link._acl._hash") email1 = CkJsonObject::ckStringOf(jResp,"email1") email2 = CkJsonObject::ckStringOf(jResp,"email2") invalid_email = CkJsonObject::ckBoolOf(jResp,"invalid_email") email_opt_out = CkJsonObject::ckBoolOf(jResp,"email_opt_out") email_addresses_non_primary = CkJsonObject::ckStringOf(jResp,"email_addresses_non_primary") v_module = CkJsonObject::ckStringOf(jResp,"_module") i = 0 count_i = CkJsonObject::ckSizeOfArray(jResp,"modified_user_link._acl.fields") While i < count_i CkJsonObject::setCkI(jResp, i) i = i + 1 Wend i = 0 count_i = CkJsonObject::ckSizeOfArray(jResp,"created_by_link._acl.fields") While i < count_i CkJsonObject::setCkI(jResp, i) i = i + 1 Wend i = 0 count_i = CkJsonObject::ckSizeOfArray(jResp,"member_of._acl.fields") While i < count_i CkJsonObject::setCkI(jResp, i) i = i + 1 Wend i = 0 count_i = CkJsonObject::ckSizeOfArray(jResp,"campaign_accounts._acl.fields") While i < count_i CkJsonObject::setCkI(jResp, i) i = i + 1 Wend i = 0 count_i = CkJsonObject::ckSizeOfArray(jResp,"tag") While i < count_i CkJsonObject::setCkI(jResp, i) i = i + 1 Wend i = 0 count_i = CkJsonObject::ckSizeOfArray(jResp,"assigned_user_link._acl.fields") While i < count_i CkJsonObject::setCkI(jResp, i) i = i + 1 Wend i = 0 count_i = CkJsonObject::ckSizeOfArray(jResp,"team_count_link._acl.fields") While i < count_i CkJsonObject::setCkI(jResp, i) i = i + 1 Wend i = 0 count_i = CkJsonObject::ckSizeOfArray(jResp,"team_name") While i < count_i CkJsonObject::setCkI(jResp, i) id_int = CkJsonObject::ckIntOf(jResp,"team_name[i].id") name = CkJsonObject::ckStringOf(jResp,"team_name[i].name") name_2 = CkJsonObject::ckStringOf(jResp,"team_name[i].name_2") primary = CkJsonObject::ckBoolOf(jResp,"team_name[i].primary") i = i + 1 Wend i = 0 count_i = CkJsonObject::ckSizeOfArray(jResp,"email") While i < count_i CkJsonObject::setCkI(jResp, i) email_address = CkJsonObject::ckStringOf(jResp,"email[i].email_address") invalid_email = CkJsonObject::ckBoolOf(jResp,"email[i].invalid_email") opt_out = CkJsonObject::ckBoolOf(jResp,"email[i].opt_out") primary_address = CkJsonObject::ckBoolOf(jResp,"email[i].primary_address") reply_to_address = CkJsonObject::ckBoolOf(jResp,"email[i].reply_to_address") i = i + 1 Wend CkHttp::ckDispose(http) CkJsonObject::ckDispose(json) CkStringBuilder::ckDispose(sbResponseBody) CkJsonObject::ckDispose(jResp) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.