React Native Requires Chilkat v11.0.0+
React Native
Activix CRM Create a Lead
See more Activix CRM Examples
Demonstrates how to create a lead and returns the created lead.Chilkat React Native Downloads
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:
// {
// "account_id": "MY_ACCOUNT_ID",
// "first_name": "John",
// "last_name": "Doe",
// "type": "email",
// "advisor": {
// "first_name": "John",
// "last_name": "Doe"
// },
// "emails": [
// {
// "address": "hello@example.com",
// "type": "home"
// }
// ],
// "phones": [
// {
// "number": "+15144321214",
// "extension": 12345,
// "type": "home"
// }
// ],
// "vehicles": [
// {
// "make": "Aston Martin",
// "model": "DB11",
// "year": 2018,
// "type": "wanted"
// }
// ]
// }
// Use this online tool to generate the code from sample JSON:
// Generate Code to Create JSON
const jsonRequestBody = new JsonObject();
jsonRequestBody.updateString('account_id', 'MY_ACCOUNT_ID');
jsonRequestBody.updateString('first_name', 'John');
jsonRequestBody.updateString('last_name', 'Doe');
jsonRequestBody.updateString('type', 'email');
jsonRequestBody.updateString('advisor.first_name', 'John');
jsonRequestBody.updateString('advisor.last_name', 'Doe');
jsonRequestBody.updateString('emails[0].address', 'hello@example.com');
jsonRequestBody.updateString('emails[0].type', 'home');
jsonRequestBody.updateString('phones[0].number', '+15144321214');
jsonRequestBody.updateInt('phones[0].extension', 12345);
jsonRequestBody.updateString('phones[0].type', 'home');
jsonRequestBody.updateString('vehicles[0].make', 'Aston Martin');
jsonRequestBody.updateString('vehicles[0].model', 'DB11');
jsonRequestBody.updateInt('vehicles[0].year', 2018);
jsonRequestBody.updateString('vehicles[0].type', 'wanted');
let url = 'https://crm.activix.ca/api/v2/leads';
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": 3387562,
// "created_at": "2018-04-09T18:05:00+00:00",
// "updated_at": "2018-04-09T18:07:00+00:00",
// "first_name": "John",
// "last_name": "Doe",
// ...
// "account": {
// "id": 66,
// ...
// },
// "advisor": {
// "id": 51112,
// ...
// },
// "emails": [
// {
// "id": 3664451,
// ...
// },
// ...
// ],
// "phones": [
// {
// "id": 9465546,
// ...
// },
// ...
// ],
// "vehicles": [
// {
// "id": 4542214,
// ...
// },
// ...
// ]
// }
// }
let dataAccountId = 0;
let i = 0;
let countI = 0;
let id = 0;
let createdAt = '';
let updatedAt = '';
let leadId = 0;
let address = '';
let vType = '';
let extension = '';
let numberArg = '';
let accessories = '';
let allowedOdometer = '';
let balance = 0;
let budgetMax = '';
let budgetMin = '';
let cashDown = '';
let category = '';
let categoryRv = '';
let clientNumber = '';
let colorExterior = '';
let colorInterior = '';
let comment = '';
let condition = '';
let endContractDate = '';
let endWarrantyDate = '';
let engine = '';
let extendedWarranty = '';
let fuel = '';
let lengthMax = '';
let lengthMin = '';
let licensePlate = '';
let make = '';
let modality = '';
let model = '';
let odometer = '';
let offerNumber = '';
let vOption = '';
let orderNumber = '';
let payment = '';
let paymentFrequency = '';
let preparation = '';
let price = '';
let profit = '';
let purchaseDate = '';
let rate = '';
let recall = '';
let recordedDate = '';
let residual = '';
let securityDeposit = '';
let sleeping = '';
let soldBy = '';
let soldDate = '';
let stock = '';
let stockState = '';
let term = '';
let transmission = '';
let trim = '';
let value = '';
let vin = '';
let warranty = '';
let weight = '';
let year = '';
let yearMax = '';
let yearMin = '';
const dataId = jsonResponse.intOf('data.id');
const dataCreatedAt = jsonResponse.stringOf('data.created_at');
const dataUpdatedAt = jsonResponse.stringOf('data.updated_at');
dataAccountId = jsonResponse.intOf('data.account_id');
const dataAddressLine1 = jsonResponse.stringOf('data.address_line1');
const dataAddressLine2 = jsonResponse.stringOf('data.address_line2');
const dataAppointmentDate = jsonResponse.stringOf('data.appointment_date');
const dataApptCall = jsonResponse.stringOf('data.appt_call');
const dataAvailableDate = jsonResponse.stringOf('data.available_date');
const dataAverageSpending = jsonResponse.stringOf('data.average_spending');
const dataBeBackDate = jsonResponse.stringOf('data.be_back_date');
const dataBirthDate = jsonResponse.stringOf('data.birth_date');
const dataBusiness = jsonResponse.stringOf('data.business');
const dataCallDate = jsonResponse.stringOf('data.call_date');
const dataCity = jsonResponse.stringOf('data.city');
const dataCivility = jsonResponse.stringOf('data.civility');
const dataCode = jsonResponse.stringOf('data.code');
const dataCountry = jsonResponse.stringOf('data.country');
const dataCsiDate = jsonResponse.stringOf('data.csi_date');
const dataDeliveredById = jsonResponse.stringOf('data.delivered_by_id');
const dataDeliveredDate = jsonResponse.stringOf('data.delivered_date');
const dataDeliveryDate = jsonResponse.stringOf('data.delivery_date');
const dataDivision = jsonResponse.stringOf('data.division');
const dataEndServiceDate = jsonResponse.stringOf('data.end_service_date');
const dataFirstName = jsonResponse.stringOf('data.first_name');
const dataGas = jsonResponse.stringOf('data.gas');
const dataGender = jsonResponse.intOf('data.gender');
const dataInvoiced = jsonResponse.stringOf('data.invoiced');
const dataLastName = jsonResponse.stringOf('data.last_name');
const dataLastVisitDate = jsonResponse.stringOf('data.last_visit_date');
const dataLocale = jsonResponse.stringOf('data.locale');
const dataLoyalty = jsonResponse.stringOf('data.loyalty');
const dataNextVisitDate = jsonResponse.stringOf('data.next_visit_date');
const dataOdometerLastVisit = jsonResponse.stringOf('data.odometer_last_visit');
const dataOpenWorkOrderDate = jsonResponse.stringOf('data.open_work_order_date');
const dataPlannedPickUpDate = jsonResponse.stringOf('data.planned_pick_up_date');
const dataPostalCode = jsonResponse.stringOf('data.postal_code');
const dataPrepaid = jsonResponse.stringOf('data.prepaid');
const dataPrepared = jsonResponse.stringOf('data.prepared');
const dataPresentedDate = jsonResponse.stringOf('data.presented_date');
const dataPromisedDate = jsonResponse.stringOf('data.promised_date');
const dataProvince = jsonResponse.stringOf('data.province');
const dataRating = jsonResponse.stringOf('data.rating');
const dataReachedClient = jsonResponse.stringOf('data.reached_client');
const dataRefinancedDate = jsonResponse.stringOf('data.refinanced_date');
const dataRepairDate = jsonResponse.stringOf('data.repair_date');
const dataRepairOrder = jsonResponse.stringOf('data.repair_order');
const dataResult = jsonResponse.stringOf('data.result');
const dataRoadTestDate = jsonResponse.stringOf('data.road_test_date');
const dataSaleDate = jsonResponse.stringOf('data.sale_date');
const dataSecondContact = jsonResponse.stringOf('data.second_contact');
const dataSecondContactCivility = jsonResponse.stringOf('data.second_contact_civility');
const dataSegment = jsonResponse.stringOf('data.segment');
const dataServiceCleaned = jsonResponse.stringOf('data.service_cleaned');
const dataServiceIntervalKm = jsonResponse.stringOf('data.service_interval_km');
const dataServiceMonthlyKm = jsonResponse.stringOf('data.service_monthly_km');
const dataSex = jsonResponse.stringOf('data.sex');
const dataSource = jsonResponse.stringOf('data.source');
const dataStatus = jsonResponse.stringOf('data.status');
const dataStorage = jsonResponse.stringOf('data.storage');
const dataTakeOverDate = jsonResponse.stringOf('data.take_over_date');
const dataType = jsonResponse.stringOf('data.type');
const dataUnsubscribeAllDate = jsonResponse.stringOf('data.unsubscribe_all_date');
const dataUnsubscribeCallDate = jsonResponse.stringOf('data.unsubscribe_call_date');
const dataUnsubscribeEmailDate = jsonResponse.stringOf('data.unsubscribe_email_date');
const dataUnsubscribeSmsDate = jsonResponse.stringOf('data.unsubscribe_sms_date');
const dataWorkOrder = jsonResponse.stringOf('data.work_order');
dataAccountId = jsonResponse.intOf('data.account.id');
const dataAccountCreatedAt = jsonResponse.stringOf('data.account.created_at');
const dataAccountUpdatedAt = jsonResponse.stringOf('data.account.updated_at');
const dataAccountPartnerId = jsonResponse.intOf('data.account.partner_id');
const dataAccountActivationDate = jsonResponse.stringOf('data.account.activation_date');
const dataAccountDefaultDeliverymanUserId = jsonResponse.stringOf('data.account.default_deliveryman_user_id');
const dataAccountLeadxpressOptionPriority = jsonResponse.intOf('data.account.leadxpress_option.priority');
const dataAccountLeadxpressOptionReminderFrequency = jsonResponse.intOf('data.account.leadxpress_option.reminder.frequency');
const dataAccountLeadxpressOptionReminderRecurrence = jsonResponse.intOf('data.account.leadxpress_option.reminder.recurrence');
const dataAccountLogo = jsonResponse.stringOf('data.account.logo');
const dataAccountLogoEn = jsonResponse.stringOf('data.account.logo_en');
const dataAccountMergeRule = jsonResponse.stringOf('data.account.merge_rule');
const dataAccountMonthStartDay = jsonResponse.intOf('data.account.month_start_day');
const dataAccountName = jsonResponse.stringOf('data.account.name');
const dataAccountPhone = jsonResponse.stringOf('data.account.phone');
const dataAccountWaitingSaleDate = jsonResponse.stringOf('data.account.waiting_sale_date');
const dataAdvisor = jsonResponse.stringOf('data.advisor');
const dataBdc = jsonResponse.stringOf('data.bdc');
const dataCommercial = jsonResponse.stringOf('data.commercial');
const dataServiceAdvisor = jsonResponse.stringOf('data.service_advisor');
const dataServiceAgent = jsonResponse.stringOf('data.service_agent');
i = 0;
countI = jsonResponse.sizeOfArray('data.service_process');
while (i < countI) {
jsonResponse.i = i;
i++;
}
i = 0;
countI = jsonResponse.sizeOfArray('data.emails');
while (i < countI) {
jsonResponse.i = i;
id = jsonResponse.intOf('data.emails[i].id');
createdAt = jsonResponse.stringOf('data.emails[i].created_at');
updatedAt = jsonResponse.stringOf('data.emails[i].updated_at');
leadId = jsonResponse.intOf('data.emails[i].lead_id');
address = jsonResponse.stringOf('data.emails[i].address');
vType = jsonResponse.stringOf('data.emails[i].type');
jsonResponse.boolOf('data.emails[i].valid');
i++;
}
i = 0;
countI = jsonResponse.sizeOfArray('data.phones');
while (i < countI) {
jsonResponse.i = i;
id = jsonResponse.intOf('data.phones[i].id');
createdAt = jsonResponse.stringOf('data.phones[i].created_at');
updatedAt = jsonResponse.stringOf('data.phones[i].updated_at');
leadId = jsonResponse.intOf('data.phones[i].lead_id');
extension = jsonResponse.stringOf('data.phones[i].extension');
numberArg = jsonResponse.stringOf('data.phones[i].number');
vType = jsonResponse.stringOf('data.phones[i].type');
jsonResponse.boolOf('data.phones[i].valid');
jsonResponse.boolOf('data.phones[i].validated');
jsonResponse.boolOf('data.phones[i].mobile');
i++;
}
i = 0;
countI = jsonResponse.sizeOfArray('data.vehicles');
while (i < countI) {
jsonResponse.i = i;
id = jsonResponse.intOf('data.vehicles[i].id');
createdAt = jsonResponse.stringOf('data.vehicles[i].created_at');
updatedAt = jsonResponse.stringOf('data.vehicles[i].updated_at');
leadId = jsonResponse.intOf('data.vehicles[i].lead_id');
accessories = jsonResponse.stringOf('data.vehicles[i].accessories');
allowedOdometer = jsonResponse.stringOf('data.vehicles[i].allowed_odometer');
balance = jsonResponse.intOf('data.vehicles[i].balance');
budgetMax = jsonResponse.stringOf('data.vehicles[i].budget_max');
budgetMin = jsonResponse.stringOf('data.vehicles[i].budget_min');
cashDown = jsonResponse.stringOf('data.vehicles[i].cash_down');
category = jsonResponse.stringOf('data.vehicles[i].category');
categoryRv = jsonResponse.stringOf('data.vehicles[i].category_rv');
clientNumber = jsonResponse.stringOf('data.vehicles[i].client_number');
colorExterior = jsonResponse.stringOf('data.vehicles[i].color_exterior');
colorInterior = jsonResponse.stringOf('data.vehicles[i].color_interior');
comment = jsonResponse.stringOf('data.vehicles[i].comment');
condition = jsonResponse.stringOf('data.vehicles[i].condition');
endContractDate = jsonResponse.stringOf('data.vehicles[i].end_contract_date');
endWarrantyDate = jsonResponse.stringOf('data.vehicles[i].end_warranty_date');
engine = jsonResponse.stringOf('data.vehicles[i].engine');
extendedWarranty = jsonResponse.stringOf('data.vehicles[i].extended_warranty');
fuel = jsonResponse.stringOf('data.vehicles[i].fuel');
lengthMax = jsonResponse.stringOf('data.vehicles[i].length_max');
lengthMin = jsonResponse.stringOf('data.vehicles[i].length_min');
licensePlate = jsonResponse.stringOf('data.vehicles[i].license_plate');
make = jsonResponse.stringOf('data.vehicles[i].make');
modality = jsonResponse.stringOf('data.vehicles[i].modality');
model = jsonResponse.stringOf('data.vehicles[i].model');
odometer = jsonResponse.stringOf('data.vehicles[i].odometer');
offerNumber = jsonResponse.stringOf('data.vehicles[i].offer_number');
vOption = jsonResponse.stringOf('data.vehicles[i].option');
orderNumber = jsonResponse.stringOf('data.vehicles[i].order_number');
payment = jsonResponse.stringOf('data.vehicles[i].payment');
paymentFrequency = jsonResponse.stringOf('data.vehicles[i].payment_frequency');
preparation = jsonResponse.stringOf('data.vehicles[i].preparation');
price = jsonResponse.stringOf('data.vehicles[i].price');
profit = jsonResponse.stringOf('data.vehicles[i].profit');
purchaseDate = jsonResponse.stringOf('data.vehicles[i].purchase_date');
rate = jsonResponse.stringOf('data.vehicles[i].rate');
recall = jsonResponse.stringOf('data.vehicles[i].recall');
recordedDate = jsonResponse.stringOf('data.vehicles[i].recorded_date');
residual = jsonResponse.stringOf('data.vehicles[i].residual');
securityDeposit = jsonResponse.stringOf('data.vehicles[i].security_deposit');
sleeping = jsonResponse.stringOf('data.vehicles[i].sleeping');
jsonResponse.boolOf('data.vehicles[i].sold');
soldBy = jsonResponse.stringOf('data.vehicles[i].sold_by');
soldDate = jsonResponse.stringOf('data.vehicles[i].sold_date');
stock = jsonResponse.stringOf('data.vehicles[i].stock');
stockState = jsonResponse.stringOf('data.vehicles[i].stock_state');
term = jsonResponse.stringOf('data.vehicles[i].term');
jsonResponse.boolOf('data.vehicles[i].tire');
transmission = jsonResponse.stringOf('data.vehicles[i].transmission');
trim = jsonResponse.stringOf('data.vehicles[i].trim');
vType = jsonResponse.stringOf('data.vehicles[i].type');
url = jsonResponse.stringOf('data.vehicles[i].url');
value = jsonResponse.stringOf('data.vehicles[i].value');
vin = jsonResponse.stringOf('data.vehicles[i].vin');
warranty = jsonResponse.stringOf('data.vehicles[i].warranty');
weight = jsonResponse.stringOf('data.vehicles[i].weight');
year = jsonResponse.stringOf('data.vehicles[i].year');
yearMax = jsonResponse.stringOf('data.vehicles[i].year_max');
yearMin = jsonResponse.stringOf('data.vehicles[i].year_min');
i++;
}
i = 0;
countI = jsonResponse.sizeOfArray('data.related_ids');
while (i < countI) {
jsonResponse.i = i;
i++;
}
}