Lua
Lua
Activix CRM Update a Phone
See more Activix CRM Examples
Updates a phone and returns the updated phone.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:
-- {
-- "number": "+15141234459",
-- "type": "home",
-- "mobile": true
-- }
-- Use this online tool to generate the code from sample JSON:
-- Generate Code to Create JSON
local jsonRequestBody = chilkat.JsonObject.new()
jsonRequestBody:update_string("number", "+15141234459")
jsonRequestBody:update_string("type", "home")
jsonRequestBody:update_bool("mobile", true)
local url = "https://crm.activix.ca/api/v2/lead-phones/PHONE_ID"
local resp = chilkat.HttpResponse.new()
local success = http:http_json("PUT", 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": 34566,
-- "created_at": "2018-04-09T18:05:00+00:00",
-- "updated_at": "2018-04-09T18:07:00+00:00",
-- "lead_id": 3466512,
-- "number": "+15141234455",
-- ...
-- }
-- }
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 dataExtension = jsonResponse:string_of("data.extension")
local dataNumber = jsonResponse:string_of("data.number")
local dataType = jsonResponse:string_of("data.type")
local dataValid = jsonResponse:bool_of("data.valid")
local dataValidated = jsonResponse:bool_of("data.validated")
local dataMobile = jsonResponse:bool_of("data.mobile")