Sample code for 30+ languages & platforms
Dart

Activix CRM Update a Phone

See more Activix CRM Examples

Updates a phone and returns the updated phone.

Chilkat Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

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

  final http = CkHttp();

  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

  final jsonRequestBody = CkJsonObject();
  jsonRequestBody.updateString('number', '+15141234459');
  jsonRequestBody.updateString('type', 'home');
  jsonRequestBody.updateBool('mobile', true);

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

  final resp = CkHttpResponse();
  try {
    http.httpJson('PUT', url, jsonRequestBody, 'application/json', resp);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  print('Response Status Code: ${resp.statusCode}');

  final jsonResponse = CkJsonObject();
  jsonResponse.load(resp.bodyStr);
  jsonResponse.emitCompact = false;
  print(jsonResponse.emit());

  if (resp.statusCode >= 300) {
    print('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",
  //         ...
  //     }
  // }

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