DataFlex
DataFlex
GetHarvest - Update Contact
See more GetHarvest Examples
Updates 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.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoHttp
Handle hoJson
Variant vSbRequestBody
Handle hoSbRequestBody
Variant vResp
Handle hoResp
Variant vSbResponseBody
Handle hoSbResponseBody
Handle hoJResp
Integer iRespStatusCode
Integer iId
String sTitle
String sFirst_name
String sLast_name
String sEmail
String sPhone_office
String sPhone_mobile
String sFax
String sCreated_at
String sUpdated_at
Integer iClientId
String sClientName
String sTemp1
Move False To iSuccess
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
// 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"
// }
Get Create (RefClass(cComChilkatJsonObject)) To hoJson
If (Not(IsComObjectCreated(hoJson))) Begin
Send CreateComObject of hoJson
End
Get ComUpdateString Of hoJson "title" "Owner" To iSuccess
Send ComSetRequestHeader To hoHttp "User-Agent" "MyApp (yourname@example.com)"
Send ComSetRequestHeader To hoHttp "Content-Type" "application/json"
Send ComSetRequestHeader To hoHttp "Authorization" "Bearer ACCESS_TOKEN"
Send ComSetRequestHeader To hoHttp "Harvest-Account-Id" "ACCOUNT_ID"
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbRequestBody
If (Not(IsComObjectCreated(hoSbRequestBody))) Begin
Send CreateComObject of hoSbRequestBody
End
Get pvComObject of hoSbRequestBody to vSbRequestBody
Get ComEmitSb Of hoJson vSbRequestBody To iSuccess
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
If (Not(IsComObjectCreated(hoResp))) Begin
Send CreateComObject of hoResp
End
Get pvComObject of hoSbRequestBody to vSbRequestBody
Get pvComObject of hoResp to vResp
Get ComHttpSb Of hoHttp "PATCH" "https://api.harvestapp.com/v2/contacts/CONTACT_ID" vSbRequestBody "utf-8" "application/json" vResp To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
Send CreateComObject of hoSbResponseBody
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess
Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
If (Not(IsComObjectCreated(hoJResp))) Begin
Send CreateComObject of hoJResp
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
Set ComEmitCompact Of hoJResp To False
Showln "Response Body:"
Get ComEmit Of hoJResp To sTemp1
Showln sTemp1
Get ComStatusCode Of hoResp To iRespStatusCode
Showln "Response Status Code = " iRespStatusCode
If (iRespStatusCode >= 400) Begin
Showln "Response Header:"
Get ComHeader Of hoResp To sTemp1
Showln sTemp1
Showln "Failed."
Procedure_Return
End
// 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
Get ComIntOf Of hoJResp "id" To iId
Get ComStringOf Of hoJResp "title" To sTitle
Get ComStringOf Of hoJResp "first_name" To sFirst_name
Get ComStringOf Of hoJResp "last_name" To sLast_name
Get ComStringOf Of hoJResp "email" To sEmail
Get ComStringOf Of hoJResp "phone_office" To sPhone_office
Get ComStringOf Of hoJResp "phone_mobile" To sPhone_mobile
Get ComStringOf Of hoJResp "fax" To sFax
Get ComStringOf Of hoJResp "created_at" To sCreated_at
Get ComStringOf Of hoJResp "updated_at" To sUpdated_at
Get ComIntOf Of hoJResp "client.id" To iClientId
Get ComStringOf Of hoJResp "client.name" To sClientName
End_Procedure