Sample code for 30+ languages & platforms
React Native Requires Chilkat v11.0.0+

Activix CRM Create a Phone

See more Activix CRM Examples

Create a phone. Returns the created 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:

  // {
  //   "lead_id": 7135833,
  //   "number": "+15141234455",
  //   "type": "home"
  // }

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

  const jsonRequestBody = new JsonObject();
  jsonRequestBody.updateInt('lead_id', 7135833);
  jsonRequestBody.updateString('number', '+15141234455');
  jsonRequestBody.updateString('type', 'home');

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

  const resp = new HttpResponse();
  try {
    await http.httpJsonAsync('POST', 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:05: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');
  const dataValidated = jsonResponse.stringOf('data.validated');
}