Sample code for 30+ languages & platforms
Xbase++

Activix CRM Update a Phone

See more Activix CRM Examples

Updates a phone and returns the updated phone.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL oJsonRequestBody
LOCAL cUrl
LOCAL oResp
LOCAL oJsonResponse
LOCAL nDataId
LOCAL cDataCreated_at
LOCAL cDataUpdated_at
LOCAL nDataLead_id
LOCAL cDataExtension
LOCAL cDataNumber
LOCAL cDataType
LOCAL nDataValid
LOCAL nDataValidated
LOCAL nDataMobile

nSuccess := 0

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

oHttp := CreateObject("Chilkat.Http")

oHttp:AuthToken := "ACCESS_TOKEN"

oHttp: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

oJsonRequestBody := CreateObject("Chilkat.JsonObject")
oJsonRequestBody:UpdateString("number", "+15141234459")
oJsonRequestBody:UpdateString("type", "home")
oJsonRequestBody:UpdateBool("mobile", 1)

cUrl := "https://crm.activix.ca/api/v2/lead-phones/PHONE_ID"

oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpJson("PUT", cUrl, oJsonRequestBody, "application/json", oResp)
IF (nSuccess == 0)
    ? oHttp:LastErrorText
    oHttp:destroy()
    oJsonRequestBody:destroy()
    oResp:destroy()
    RETURN
ENDIF

? "Response Status Code: " + Str(oResp:StatusCode)

oJsonResponse := CreateObject("Chilkat.JsonObject")
oJsonResponse:Load(oResp:BodyStr)
oJsonResponse:EmitCompact := 0
? oJsonResponse:Emit()

IF (oResp:StatusCode >= 300)
    ? "Failed."
    oHttp:destroy()
    oJsonRequestBody:destroy()
    oResp:destroy()
    oJsonResponse:destroy()
    RETURN
ENDIF

//  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",
//          ...
//      }
//  }

nDataId := oJsonResponse:IntOf("data.id")
cDataCreated_at := oJsonResponse:StringOf("data.created_at")
cDataUpdated_at := oJsonResponse:StringOf("data.updated_at")
nDataLead_id := oJsonResponse:IntOf("data.lead_id")
cDataExtension := oJsonResponse:StringOf("data.extension")
cDataNumber := oJsonResponse:StringOf("data.number")
cDataType := oJsonResponse:StringOf("data.type")
nDataValid := oJsonResponse:BoolOf("data.valid")
nDataValidated := oJsonResponse:BoolOf("data.validated")
nDataMobile := oJsonResponse:BoolOf("data.mobile")

oHttp:destroy()
oJsonRequestBody:destroy()
oResp:destroy()
oJsonResponse:destroy()