PowerBuilder
PowerBuilder
Twilio Send MMS (using Chilkat HTTP)
See more Twilio Examples
Send an outgoing MMS message. The only difference with MMS (as compared with SMS) is that a MediaUrl parameter is added to the POST. This means your image must be accessible on the web -- the Twilio server must be able to download the image from the URL you provide to include it in the MMS mesage to be sent.Also, see Twilio MMS for more information about MMS.
Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Http
oleobject loo_Req
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
oleobject loo_Date_created
oleobject loo_Date_updated
oleobject loo_Date_sent
string ls_Sid
string ls_Account_sid
string ls_V_to
string ls_From
string ls_Messaging_service_sid
string ls_Body
string ls_Status
string ls_Num_segments
string ls_Num_media
string ls_Direction
string ls_Api_version
string ls_Price
string ls_Price_unit
string ls_Error_code
string ls_Error_message
string ls_Uri
string ls_Subresource_urisMedia
li_Success = 0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Http = create oleobject
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
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_Req.AddParam("MediaUrl","https://www.chilkatsoft.com/images/starfish.jpg")
loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")
li_Success = loo_Http.HttpReq("https://api.twilio.com/2010-04-01/Accounts/TWILIO_ACCOUNT_SID/Messages.json",loo_Req,loo_Resp)
if li_Success = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_Req
destroy loo_Resp
return
end if
loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")
loo_Resp.GetBodySb(loo_SbResponseBody)
loo_JResp = create oleobject
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_Http
destroy loo_Req
destroy loo_Resp
destroy loo_SbResponseBody
destroy loo_JResp
return
end if
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "sid": "SM477111c301794f14b11eca5eefd5c350",
// "date_created": "Tue, 18 Aug 2020 15:04:47 +0000",
// "date_updated": "Tue, 18 Aug 2020 15:04:47 +0000",
// "date_sent": null,
// "account_sid": "AC2e9b6bc0f51133df24926f07341d3824",
// "to": "+15005551212",
// "from": "+15005550006",
// "messaging_service_sid": null,
// "body": "body",
// "status": "queued",
// "num_segments": "1",
// "num_media": "0",
// "direction": "outbound-api",
// "api_version": "2010-04-01",
// "price": null,
// "price_unit": "USD",
// "error_code": null,
// "error_message": null,
// "uri": "/2010-04-01/Accounts/AC2e9b6bc0f51133df24926f07341d3824/Messages/SM477111c301794f14b11eca5eefd5c350.json",
// "subresource_uris": {
// "media": "/2010-04-01/Accounts/AC2e9b6bc0f51133df24926f07341d3824/Messages/SM477111c301794f14b11eca5eefd5c350/Media.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
loo_Date_created = create oleobject
li_rc = loo_Date_created.ConnectToNewObject("Chilkat.DtObj")
loo_Date_updated = create oleobject
li_rc = loo_Date_updated.ConnectToNewObject("Chilkat.DtObj")
loo_Date_sent = create oleobject
li_rc = loo_Date_sent.ConnectToNewObject("Chilkat.DtObj")
ls_Sid = loo_JResp.StringOf("sid")
loo_JResp.DtOf("date_created",0,loo_Date_created)
loo_JResp.DtOf("date_updated",0,loo_Date_updated)
loo_JResp.DtOf("date_sent",0,loo_Date_sent)
ls_Account_sid = loo_JResp.StringOf("account_sid")
ls_V_to = loo_JResp.StringOf("to")
ls_From = loo_JResp.StringOf("from")
ls_Messaging_service_sid = loo_JResp.StringOf("messaging_service_sid")
ls_Body = loo_JResp.StringOf("body")
ls_Status = loo_JResp.StringOf("status")
ls_Num_segments = loo_JResp.StringOf("num_segments")
ls_Num_media = loo_JResp.StringOf("num_media")
ls_Direction = loo_JResp.StringOf("direction")
ls_Api_version = loo_JResp.StringOf("api_version")
ls_Price = loo_JResp.StringOf("price")
ls_Price_unit = loo_JResp.StringOf("price_unit")
ls_Error_code = loo_JResp.StringOf("error_code")
ls_Error_message = loo_JResp.StringOf("error_message")
ls_Uri = loo_JResp.StringOf("uri")
ls_Subresource_urisMedia = loo_JResp.StringOf("subresource_uris.media")
destroy loo_Http
destroy loo_Req
destroy loo_Resp
destroy loo_SbResponseBody
destroy loo_JResp
destroy loo_Date_created
destroy loo_Date_updated
destroy loo_Date_sent