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) GetHarvest - Update ContactUpdates the specific contact by setting the values of the parameters passed. Any parameters not provided will be left unchanged. Returns a contact object and a 200 OK response code if the call succeeded. For more information, see https://help.getharvest.com/api-v2/clients-api/clients/contacts/
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 "https://api.harvestapp.com/v2/contacts/CONTACT_ID" \ ; -H "Authorization: Bearer ACCESS_TOKEN" \ ; -H "Harvest-Account-Id: ACCOUNT_ID" \ ; -H "User-Agent: MyApp (yourname@example.com)" \ ; -X PATCH \ ; -H "Content-Type: application/json" \ ; -d '{"title":"Owner"}' ; Use this online tool to generate code from sample JSON: ; Generate Code to Create JSON ; The following JSON is sent in the request body. ; { ; "title": "Owner" ; } json.i = CkJsonObject::ckCreate() If json.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckUpdateString(json,"title","Owner") CkHttp::ckSetRequestHeader(http,"User-Agent","MyApp (yourname@example.com)") CkHttp::ckSetRequestHeader(http,"Content-Type","application/json") CkHttp::ckSetRequestHeader(http,"Authorization","Bearer ACCESS_TOKEN") CkHttp::ckSetRequestHeader(http,"Harvest-Account-Id","ACCOUNT_ID") sbRequestBody.i = CkStringBuilder::ckCreate() If sbRequestBody.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckEmitSb(json,sbRequestBody) resp.i = CkHttp::ckPTextSb(http,"PATCH","https://api.harvestapp.com/v2/contacts/CONTACT_ID",sbRequestBody,"utf-8","application/json",0,0) If CkHttp::ckLastMethodSuccess(http) = 0 Debug CkHttp::ckLastErrorText(http) CkHttp::ckDispose(http) CkJsonObject::ckDispose(json) CkStringBuilder::ckDispose(sbRequestBody) 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(sbRequestBody) CkStringBuilder::ckDispose(sbResponseBody) CkJsonObject::ckDispose(jResp) ProcedureReturn EndIf CkHttpResponse::ckDispose(resp) ; Sample JSON response: ; { ; "id": 4706510, ; "title": "Owner", ; "first_name": "George", ; "last_name": "Frank", ; "email": "georgefrank@example.com", ; "phone_office": "", ; "phone_mobile": "", ; "fax": "", ; "created_at": "2017-06-26T21:44:57Z", ; "updated_at": "2017-06-26T21:46:48Z", ; "client": { ; "id": 5735776, ; "name": "123 Industries" ; } ; } ; 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.i title.s first_name.s last_name.s email.s phone_office.s phone_mobile.s fax.s created_at.s updated_at.s clientId.i clientName.s id = CkJsonObject::ckIntOf(jResp,"id") title = CkJsonObject::ckStringOf(jResp,"title") first_name = CkJsonObject::ckStringOf(jResp,"first_name") last_name = CkJsonObject::ckStringOf(jResp,"last_name") email = CkJsonObject::ckStringOf(jResp,"email") phone_office = CkJsonObject::ckStringOf(jResp,"phone_office") phone_mobile = CkJsonObject::ckStringOf(jResp,"phone_mobile") fax = CkJsonObject::ckStringOf(jResp,"fax") created_at = CkJsonObject::ckStringOf(jResp,"created_at") updated_at = CkJsonObject::ckStringOf(jResp,"updated_at") clientId = CkJsonObject::ckIntOf(jResp,"client.id") clientName = CkJsonObject::ckStringOf(jResp,"client.name") CkHttp::ckDispose(http) CkJsonObject::ckDispose(json) CkStringBuilder::ckDispose(sbRequestBody) CkStringBuilder::ckDispose(sbResponseBody) CkJsonObject::ckDispose(jResp) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.