Sample code for 30+ languages & platforms
React Native

Activix CRM Update a Phone

See more Activix CRM Examples

Updates a phone and returns the updated phone.

Chilkat React Native Downloads

React Native
import { Http, HttpResponse, JsonObject } from '@chilkat/react-native'

async function chilkatExample() {
  // This example requires the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  const http = new Http();

  http.authToken = 'ACCESS_TOKEN';

  http.accept = 'application/json';

  // The following JSON is sent in the request body:

  // {
  //   "number": "+15141234459",
  //   "type": "home",
  //   "mobile": true
  // }

  // Use this online tool to generate the code from sample JSON: 
  // Generate Code to Create JSON

  const jsonRequestBody = new JsonObject();
  jsonRequestBody.updateString('number', '+15141234459');
  jsonRequestBody.updateString('type', 'home');
  jsonRequestBody.updateBool('mobile', true);

  const url = 'https://crm.activix.ca/api/v2/lead-phones/PHONE_ID';

  const resp = new HttpResponse();
  try {
    await http.httpJsonAsync('PUT', url, jsonRequestBody, 'application/json', resp);
  } catch {
    console.log(http.lastErrorText);
    return;
  }

  console.log(`Response Status Code: ${resp.statusCode}`);

  const jsonResponse = new JsonObject();
  jsonResponse.load(resp.bodyStr);
  jsonResponse.emitCompact = false;
  console.log(jsonResponse.emit());

  if (resp.statusCode >= 300) {
    console.log('Failed.');
    return;
  }

  // Sample output...
  // (See the parsing code below..)
  // 
  // Use the this online tool to generate parsing code from sample JSON: 
  // Generate Parsing Code from JSON

  // {
  //     "data": {
  //         "id": 34566,
  //         "created_at": "2018-04-09T18:05:00+00:00",
  //         "updated_at": "2018-04-09T18:07:00+00:00",
  //         "lead_id": 3466512,
  //         "number": "+15141234455",
  //         ...
  //     }
  // }

  const dataId = jsonResponse.intOf('data.id');
  const dataCreatedAt = jsonResponse.stringOf('data.created_at');
  const dataUpdatedAt = jsonResponse.stringOf('data.updated_at');
  const dataLeadId = jsonResponse.intOf('data.lead_id');
  const dataExtension = jsonResponse.stringOf('data.extension');
  const dataNumber = jsonResponse.stringOf('data.number');
  const dataType = jsonResponse.stringOf('data.type');
}