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
(PowerBuilder) Twilio Send SMS (using Chilkat HTTP)Send an outgoing SMS message. For more information, see https://www.twilio.com/docs/sms/api/message-resource#create-a-message-resource
integer li_rc oleobject loo_Http integer li_Success oleobject loo_Req oleobject loo_Resp oleobject loo_SbResponseBody oleobject loo_JResp integer li_RespStatusCode string ls_Account_sid string ls_Api_version string ls_Body string ls_Date_created string ls_Date_sent string ls_Date_updated string ls_Direction string ls_Error_code string ls_Error_message string ls_From string ls_Messaging_service_sid string ls_Num_media string ls_Num_segments string ls_Price string ls_Price_unit string ls_Sid string ls_Status string ls_Subresource_urisMedia string ls_V_to string ls_Uri // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loo_Http = create oleobject // Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0 li_rc = loo_Http.ConnectToNewObject("Chilkat.Http") if li_rc < 0 then destroy loo_Http MessageBox("Error","Connecting to COM object failed") return end if // Implements the following CURL command: // (See information about using test credentials and phone numbers: https://www.twilio.com/docs/iam/test-credentials) // curl -X POST https://api.twilio.com/2010-04-01/Accounts/TWILIO_ACCOUNT_SID/Messages.json \ // --data-urlencode "From=+15005550006" \ // --data-urlencode "Body=body" \ // --data-urlencode "To=+15005551212" \ // -u TWILIO_ACCOUNT_SID:TWILIO_AUTH_TOKEN // Use the following online tool to generate HTTP code from a CURL command // Convert a cURL Command to HTTP Source Code loo_Http.Login = "TWILIO_ACCOUNT_SID" loo_Http.Password = "TWILIO_AUTH_TOKEN" loo_Req = create oleobject // Use "Chilkat_9_5_0.HttpRequest" for versions of Chilkat < 10.0.0 li_rc = loo_Req.ConnectToNewObject("Chilkat.HttpRequest") loo_Req.HttpVerb = "POST" loo_Req.Path = "/2010-04-01/Accounts/TWILIO_ACCOUNT_SID/Messages.json" loo_Req.ContentType = "application/x-www-form-urlencoded" loo_Req.AddParam("From","+15005550006") loo_Req.AddParam("Body","body") loo_Req.AddParam("To","+15005551212") loo_Resp = loo_Http.PostUrlEncoded("https://api.twilio.com/2010-04-01/Accounts/TWILIO_ACCOUNT_SID/Messages.json",loo_Req) if loo_Http.LastMethodSuccess = 0 then Write-Debug loo_Http.LastErrorText destroy loo_Http destroy loo_Req return end if loo_SbResponseBody = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder") loo_Resp.GetBodySb(loo_SbResponseBody) loo_JResp = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject") loo_JResp.LoadSb(loo_SbResponseBody) loo_JResp.EmitCompact = 0 Write-Debug "Response Body:" Write-Debug loo_JResp.Emit() // A 201 status code indicates success. li_RespStatusCode = loo_Resp.StatusCode Write-Debug "Response Status Code = " + string(li_RespStatusCode) if li_RespStatusCode >= 400 then Write-Debug "Response Header:" Write-Debug loo_Resp.Header Write-Debug "Failed." destroy loo_Resp destroy loo_Http destroy loo_Req destroy loo_SbResponseBody destroy loo_JResp return end if destroy loo_Resp // Sample JSON response: // (Sample code for parsing the JSON response is shown below) // { // "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", // "api_version": "2010-04-01", // "body": "body", // "date_created": "Thu, 30 Jul 2015 20:12:31 +0000", // "date_sent": "Thu, 30 Jul 2015 20:12:33 +0000", // "date_updated": "Thu, 30 Jul 2015 20:12:33 +0000", // "direction": "outbound-api", // "error_code": null, // "error_message": null, // "from": "+15017122661", // "messaging_service_sid": "MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", // "num_media": "0", // "num_segments": "1", // "price": null, // "price_unit": null, // "sid": "MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", // "status": "sent", // "subresource_uris": { // "media": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Media.json" // }, // "to": "+15558675310", // "uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.json" // } // Sample code for parsing the JSON response... // Use the following online tool to generate parsing code from sample JSON: // Generate Parsing Code from JSON ls_Account_sid = loo_JResp.StringOf("account_sid") ls_Api_version = loo_JResp.StringOf("api_version") ls_Body = loo_JResp.StringOf("body") ls_Date_created = loo_JResp.StringOf("date_created") ls_Date_sent = loo_JResp.StringOf("date_sent") ls_Date_updated = loo_JResp.StringOf("date_updated") ls_Direction = loo_JResp.StringOf("direction") ls_Error_code = loo_JResp.StringOf("error_code") ls_Error_message = loo_JResp.StringOf("error_message") ls_From = loo_JResp.StringOf("from") ls_Messaging_service_sid = loo_JResp.StringOf("messaging_service_sid") ls_Num_media = loo_JResp.StringOf("num_media") ls_Num_segments = loo_JResp.StringOf("num_segments") ls_Price = loo_JResp.StringOf("price") ls_Price_unit = loo_JResp.StringOf("price_unit") ls_Sid = loo_JResp.StringOf("sid") ls_Status = loo_JResp.StringOf("status") ls_Subresource_urisMedia = loo_JResp.StringOf("subresource_uris.media") ls_V_to = loo_JResp.StringOf("to") ls_Uri = loo_JResp.StringOf("uri") destroy loo_Http destroy loo_Req destroy loo_SbResponseBody destroy loo_JResp |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.