Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PureBasic) CallRail API - Create an Outbound Phone CallInitiates an outbound call from the target account. For more information, see https://apidocs.callrail.com/#creating-an-outbound-phone-call
IncludeFile "CkHttpResponse.pb" IncludeFile "CkHttp.pb" IncludeFile "CkStringBuilder.pb" IncludeFile "CkJsonObject.pb" Procedure ChilkatExample() ; 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 success.i ; Implements the following CURL command: ; curl -H "Authorization: Token token={api_token}" \ ; -X POST \ ; -H "Content-Type: application/json" \ ; -d '{ ; "caller_id": "+17703334455", ; "business_phone_number": "+14045556666", ; "customer_phone_number": "+14044442233", ; "recording_enabled": true, ; "outbound_greeting_recording_url": "http://www.test.com/greeting.mp3", ; "outbound_greeting_text": "These are not the droids you are looking for." ; }' \ ; "https://api.callrail.com/v3/a/{account_id}/calls.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. ; { ; "caller_id": "+17703334455", ; "business_phone_number": "+14045556666", ; "customer_phone_number": "+14044442233", ; "recording_enabled": true, ; "outbound_greeting_recording_url": "http://www.test.com/greeting.mp3", ; "outbound_greeting_text": "These are not the droids you are looking for." ; } json.i = CkJsonObject::ckCreate() If json.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckUpdateString(json,"caller_id","+17703334455") CkJsonObject::ckUpdateString(json,"business_phone_number","+14045556666") CkJsonObject::ckUpdateString(json,"customer_phone_number","+14044442233") CkJsonObject::ckUpdateBool(json,"recording_enabled",1) CkJsonObject::ckUpdateString(json,"outbound_greeting_recording_url","http://www.test.com/greeting.mp3") CkJsonObject::ckUpdateString(json,"outbound_greeting_text","These are not the droids you are looking for.") CkHttp::ckSetRequestHeader(http,"Authorization","Token token={api_token}") CkHttp::ckSetRequestHeader(http,"Content-Type","application/json") resp.i = CkHttp::ckPostJson3(http,"https://api.callrail.com/v3/a/{account_id}/calls.json","application/json",json) If CkHttp::ckLastMethodSuccess(http) = 0 Debug CkHttp::ckLastErrorText(http) CkHttp::ckDispose(http) CkJsonObject::ckDispose(json) 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." CkHttpResponse::ckDispose(resp) CkHttp::ckDispose(http) CkJsonObject::ckDispose(json) CkStringBuilder::ckDispose(sbResponseBody) CkJsonObject::ckDispose(jResp) ProcedureReturn EndIf CkHttpResponse::ckDispose(resp) ; Sample JSON response: ; (Sample code for parsing the JSON response is shown below) ; { ; "answered": null, ; "business_phone_number": "+19044567899", ; "customer_city": "Atlanta", ; "customer_country": "US", ; "customer_name": null, ; "customer_phone_number": "+14703444700", ; "customer_state": "GA", ; "direction": "outbound", ; "duration": null, ; "id": "CAL8154748ae6bd4e278a7cddd38a662f4f", ; "recording": null, ; "recording_duration": null, ; "start_time": "2017-02-22T15:02:24.916-05:00", ; "tracking_phone_number": "+19044567899", ; "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.s = CkJsonObject::ckStringOf(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.s = CkJsonObject::ckStringOf(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(sbResponseBody) CkJsonObject::ckDispose(jResp) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.