Sample code for 30+ languages & platforms
PureBasic

CallRail API - Update a Call

See more CallRail Examples

Updates a call object in the target account. You can use the API to add a Tag or a Note to a call, or to set the call’s lead status.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkHttpResponse.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkJsonObject.pb"

Procedure ChilkatExample()

    success.i = 0

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    ; Implements the following CURL command:

    ; curl -H "Authorization: Token token={api_token}" \
    ;      -X PUT \
    ;      -H "Content-Type: application/json" \
    ;      -v \
    ;      -d '{
    ;            "note": "Call customer back tomorrow",
    ;            "tags": ["New Client"],
    ;            "lead_status": "good_lead",
    ;            "value": "$1.00",
    ;            "append_tags": true,
    ;          }' \
    ;         "https://api.callrail.com/v3/a/{account_id}/calls/{call_id}.json"

    ; Use the following online tool to generate HTTP code from a CURL command
    ; Convert a cURL Command to HTTP Source Code

    ; Use this online tool to generate code from sample JSON:
    ; Generate Code to Create JSON

    ; The following JSON is sent in the request body.

    ; {
    ;   "note": "Call customer back tomorrow",
    ;   "tags": [
    ;     "New Client"
    ;   ],
    ;   "lead_status": "good_lead",
    ;   "value": "$1.00",
    ;   "append_tags": true
    ; }

    json.i = CkJsonObject::ckCreate()
    If json.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckUpdateString(json,"note","Call customer back tomorrow")
    CkJsonObject::ckUpdateString(json,"tags[0]","New Client")
    CkJsonObject::ckUpdateString(json,"lead_status","good_lead")
    CkJsonObject::ckUpdateString(json,"value","$1.00")
    CkJsonObject::ckUpdateBool(json,"append_tags",1)

    CkHttp::ckSetRequestHeader(http,"Authorization","Token token={api_token}")
    CkHttp::ckSetRequestHeader(http,"Content-Type","application/json")

    sbRequestBody.i = CkStringBuilder::ckCreate()
    If sbRequestBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckEmitSb(json,sbRequestBody)

    resp.i = CkHttpResponse::ckCreate()
    If resp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkHttp::ckHttpSb(http,"PUT","https://api.callrail.com/v3/a/{account_id}/calls/{call_id}.json",sbRequestBody,"utf-8","application/json",resp)
    If success = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(json)
        CkStringBuilder::ckDispose(sbRequestBody)
        CkHttpResponse::ckDispose(resp)
        ProcedureReturn
    EndIf

    sbResponseBody.i = CkStringBuilder::ckCreate()
    If sbResponseBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkHttpResponse::ckGetBodySb(resp,sbResponseBody)
    jResp.i = CkJsonObject::ckCreate()
    If jResp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoadSb(jResp,sbResponseBody)
    CkJsonObject::setCkEmitCompact(jResp, 0)

    Debug "Response Body:"
    Debug CkJsonObject::ckEmit(jResp)

    respStatusCode.i = CkHttpResponse::ckStatusCode(resp)
    Debug "Response Status Code = " + Str(respStatusCode)
    If respStatusCode >= 400
        Debug "Response Header:"
        Debug CkHttpResponse::ckHeader(resp)
        Debug "Failed."
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(json)
        CkStringBuilder::ckDispose(sbRequestBody)
        CkHttpResponse::ckDispose(resp)
        CkStringBuilder::ckDispose(sbResponseBody)
        CkJsonObject::ckDispose(jResp)
        ProcedureReturn
    EndIf

    ; Sample JSON response:
    ; (Sample code for parsing the JSON response is shown below)

    ; {
    ;   "answered": false,
    ;   "business_phone_number": null,
    ;   "customer_city": "Denver",
    ;   "customer_country": "US",
    ;   "customer_name": "RUEGSEGGER SIMO",
    ;   "customer_phone_number": "+13036231131",
    ;   "customer_state": "CO",
    ;   "direction": "inbound",
    ;   "duration": 4,
    ;   "id": "CAL8154748ae6bd4e278a7cddd38a662f4f",
    ;   "recording": "https://api.callrail.com/v3/a/227799611/calls/213472384/recording.json",
    ;   "recording_duration": "27",
    ;   "start_time": "2017-01-24T11:27:48.119-05:00",
    ;   "tracking_phone_number": "+13038163491",
    ;   "voicemail": false
    ; }

    ; Sample code for parsing the JSON response...
    ; Use the following online tool to generate parsing code from sample JSON:
    ; Generate Parsing Code from JSON

    answered.i = CkJsonObject::ckBoolOf(jResp,"answered")
    business_phone_number.s = CkJsonObject::ckStringOf(jResp,"business_phone_number")
    customer_city.s = CkJsonObject::ckStringOf(jResp,"customer_city")
    customer_country.s = CkJsonObject::ckStringOf(jResp,"customer_country")
    customer_name.s = CkJsonObject::ckStringOf(jResp,"customer_name")
    customer_phone_number.s = CkJsonObject::ckStringOf(jResp,"customer_phone_number")
    customer_state.s = CkJsonObject::ckStringOf(jResp,"customer_state")
    direction.s = CkJsonObject::ckStringOf(jResp,"direction")
    duration.i = CkJsonObject::ckIntOf(jResp,"duration")
    id.s = CkJsonObject::ckStringOf(jResp,"id")
    recording.s = CkJsonObject::ckStringOf(jResp,"recording")
    recording_duration.s = CkJsonObject::ckStringOf(jResp,"recording_duration")
    start_time.s = CkJsonObject::ckStringOf(jResp,"start_time")
    tracking_phone_number.s = CkJsonObject::ckStringOf(jResp,"tracking_phone_number")
    voicemail.i = CkJsonObject::ckBoolOf(jResp,"voicemail")


    CkHttp::ckDispose(http)
    CkJsonObject::ckDispose(json)
    CkStringBuilder::ckDispose(sbRequestBody)
    CkHttpResponse::ckDispose(resp)
    CkStringBuilder::ckDispose(sbResponseBody)
    CkJsonObject::ckDispose(jResp)


    ProcedureReturn
EndProcedure