React Native
React Native
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 React Native Downloads
import { Http, HttpResponse, JsonObject, StringBuilder } from '@chilkat/react-native'
async function chilkatExample() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = new Http();
// 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"
// }
const json = new JsonObject();
json.updateString('title', 'Owner');
http.setRequestHeader('User-Agent', 'MyApp (yourname@example.com)');
http.setRequestHeader('Content-Type', 'application/json');
http.setRequestHeader('Authorization', 'Bearer ACCESS_TOKEN');
http.setRequestHeader('Harvest-Account-Id', 'ACCOUNT_ID');
const sbRequestBody = new StringBuilder();
json.emitSb(sbRequestBody);
const resp = new HttpResponse();
try {
await http.httpSbAsync('PATCH', 'https://api.harvestapp.com/v2/contacts/CONTACT_ID', sbRequestBody, 'utf-8', 'application/json', resp);
} catch {
console.log(http.lastErrorText);
return;
}
const sbResponseBody = new StringBuilder();
resp.getBodySb(sbResponseBody);
const jResp = new JsonObject();
jResp.loadSb(sbResponseBody);
jResp.emitCompact = false;
console.log('Response Body:');
console.log(jResp.emit());
const respStatusCode = resp.statusCode;
console.log(`Response Status Code = ${respStatusCode}`);
if (respStatusCode >= 400) {
console.log('Response Header:');
console.log(resp.header);
console.log('Failed.');
return;
}
// 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
const id = jResp.intOf('id');
const title = jResp.stringOf('title');
const firstName = jResp.stringOf('first_name');
const lastName = jResp.stringOf('last_name');
const email = jResp.stringOf('email');
const phoneOffice = jResp.stringOf('phone_office');
const phoneMobile = jResp.stringOf('phone_mobile');
const fax = jResp.stringOf('fax');
const createdAt = jResp.stringOf('created_at');
const updatedAt = jResp.stringOf('updated_at');
const clientId = jResp.intOf('client.id');
const clientName = jResp.stringOf('client.name');
}