Lua Requires Chilkat v11.0.0+
Lua
Activix CRM Create a Communication
See more Activix CRM Examples
Create a communication. Returns the created communication.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local http = chilkat.Http.new()
http.auth_token = "ACCESS_TOKEN"
http.accept = "application/json"
-- The following JSON is sent in the request body:
-- {
-- "lead_id": "LEAD_ID",
-- "method": "phone",
-- "type": "outgoing",
-- "call_status": "calling"
-- }
-- Use this online tool to generate the code from sample JSON:
-- Generate Code to Create JSON
local jsonRequestBody = chilkat.JsonObject.new()
jsonRequestBody:update_string("lead_id", "LEAD_ID")
jsonRequestBody:update_string("method", "phone")
jsonRequestBody:update_string("type", "outgoing")
jsonRequestBody:update_string("call_status", "calling")
local url = "https://crm.activix.ca/api/v2/communications"
local resp = chilkat.HttpResponse.new()
local success = http:http_json("POST", url, jsonRequestBody, "application/json", resp)
if not success then
print(http.last_error_text)
return
end
print("Response Status Code: " .. resp.status_code)
local jsonResponse = chilkat.JsonObject.new()
jsonResponse:load(resp.body_str)
jsonResponse.emit_compact = false
print(jsonResponse:emit())
if resp.status_code >= 300 then
print("Failed.")
return
end
-- 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": 5411998,
-- "created_at": "2019-06-10T13:01:40+00:00",
-- "updated_at": "2019-06-10T13:01:40+00:00",
-- "lead_id": 7135833,
-- "user_id": 13705,
-- "method": "phone",
-- "type": "outgoing",
-- "email_subject": null,
-- "email_body": null,
-- "email_client": null,
-- "email_user": null,
-- "call_duration": null,
-- "call_phone": null,
-- "call_status": "calling"
-- }
-- }
--
local dataId = jsonResponse:int_of("data.id")
local dataCreated_at = jsonResponse:string_of("data.created_at")
local dataUpdated_at = jsonResponse:string_of("data.updated_at")
local dataLead_id = jsonResponse:int_of("data.lead_id")
local dataUser_id = jsonResponse:int_of("data.user_id")
local dataMethod = jsonResponse:string_of("data.method")
local dataType = jsonResponse:string_of("data.type")
local dataEmail_subject = jsonResponse:string_of("data.email_subject")
local dataEmail_body = jsonResponse:string_of("data.email_body")
local dataEmail_client = jsonResponse:string_of("data.email_client")
local dataEmail_user = jsonResponse:string_of("data.email_user")
local dataCall_duration = jsonResponse:string_of("data.call_duration")
local dataCall_phone = jsonResponse:string_of("data.call_phone")
local dataCall_status = jsonResponse:string_of("data.call_status")