Swift
Swift
Activix CRM Update a Phone
See more Activix CRM Examples
Updates a phone and returns the updated phone.Chilkat Swift Downloads
func chilkatTest() {
var success: Bool = false
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = CkoHttp()!
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
let jsonRequestBody = CkoJsonObject()!
jsonRequestBody.updateString(jsonPath: "number", value: "+15141234459")
jsonRequestBody.updateString(jsonPath: "type", value: "home")
jsonRequestBody.updateBool(jsonPath: "mobile", value: true)
var url: String? = "https://crm.activix.ca/api/v2/lead-phones/PHONE_ID"
let resp = CkoHttpResponse()!
success = http.httpJson(verb: "PUT", url: url, json: jsonRequestBody, contentType: "application/json", response: resp)
if success == false {
print("\(http.lastErrorText!)")
return
}
print("Response Status Code: \(resp.statusCode.intValue)")
let jsonResponse = CkoJsonObject()!
jsonResponse.load(json: resp.bodyStr)
jsonResponse.emitCompact = false
print("\(jsonResponse.emit()!)")
if resp.statusCode.intValue >= 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",
// ...
// }
// }
var dataId: Int
var dataCreated_at: String?
var dataUpdated_at: String?
var dataLead_id: Int
var dataExtension: String?
var dataNumber: String?
var dataType: String?
var dataValid: Bool
var dataValidated: Bool
var dataMobile: Bool
dataId = jsonResponse.int(of: "data.id").intValue
dataCreated_at = jsonResponse.string(of: "data.created_at")
dataUpdated_at = jsonResponse.string(of: "data.updated_at")
dataLead_id = jsonResponse.int(of: "data.lead_id").intValue
dataExtension = jsonResponse.string(of: "data.extension")
dataNumber = jsonResponse.string(of: "data.number")
dataType = jsonResponse.string(of: "data.type")
dataValid = jsonResponse.bool(of: "data.valid")
dataValidated = jsonResponse.bool(of: "data.validated")
dataMobile = jsonResponse.bool(of: "data.mobile")
}