Xbase++ Requires Chilkat v11.0.0+
Xbase++
Send an MMS with Twilio using a media URL
See more Twilio Examples
Send an image and an optional caption from an MMS-capable Twilio number. Supply an MMS-supported destination in E.164 format and replace the example media URL with an HTTPS URL Twilio can fetch. The host must handle HEAD and GET and return the correct Content-Type for the file.
Live send. With live credentials and valid inputs, this request submits a billable message. Save the Message SID to check delivery later. Supported media types and size limits.
Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL cAccountSid
LOCAL oUrl
LOCAL oReq
LOCAL oResp
LOCAL oReply
LOCAL nParsed
nSuccess := 0
// Assumes Chilkat is unlocked. See Global Unlock Sample.
oHttp := CreateObject("Chilkat.Http")
oHttp:RequireSslCertVerify := 1
oHttp:BasicAuth := 1
// Load the owning Account SID and an API key from application configuration.
cAccountSid := "YOUR_ACCOUNT_SID"
oHttp:Login := "YOUR_API_KEY_SID"
oHttp:Password := "YOUR_API_KEY_SECRET"
oUrl := CreateObject("Chilkat.StringBuilder")
oUrl:Append("https://api.twilio.com/2010-04-01/Accounts/")
oUrl:Append(cAccountSid)
oUrl:Append("/Messages.json")
// Add raw field values. Chilkat form-encodes them, including the + in a phone number.
oReq := CreateObject("Chilkat.HttpRequest")
oReq:HttpVerb := "POST"
oReq:ContentType := "application/x-www-form-urlencoded"
oReq:AddParam("From", "YOUR_MMS_ENABLED_NUMBER")
oReq:AddParam("To", "RECIPIENT_E164_NUMBER")
// Supply a URL for the file itself so Twilio can retrieve the media.
oReq:AddParam("MediaUrl", "https://media.example.com/photo.jpg")
oReq:AddParam("Body", "Photo attached.")
oResp := CreateObject("Chilkat.HttpResponse")
oReply := CreateObject("Chilkat.JsonObject")
nSuccess := oHttp:HttpReq(oUrl:GetAsString(), oReq, oResp)
IF (oResp:StatusCode == 0)
? oHttp:LastErrorText
oHttp:destroy()
oUrl:destroy()
oReq:destroy()
oResp:destroy()
oReply:destroy()
RETURN
ENDIF
nParsed := oReply:Load(oResp:BodyStr)
IF ((nSuccess != 1) .OR. (oResp:StatusCode != 201))
? "HTTP " + Str(oResp:StatusCode)
IF ((nParsed == 1) .AND. (oReply:HasMember("code") == 1))
? "Twilio error " + Str(oReply:IntOf("code")) + ": " + oReply:StringOf("message")
ENDIF
oHttp:destroy()
oUrl:destroy()
oReq:destroy()
oResp:destroy()
oReply:destroy()
RETURN
ENDIF
IF (nParsed != 1)
? "Expected a JSON response."
oHttp:destroy()
oUrl:destroy()
oReq:destroy()
oResp:destroy()
oReply:destroy()
RETURN
ENDIF
IF ((oReply:JsonTypeOf("sid") != 1) .OR. (oReply:JsonTypeOf("status") != 1))
? "The create response is missing the message SID or status."
oHttp:destroy()
oUrl:destroy()
oReq:destroy()
oResp:destroy()
oReply:destroy()
RETURN
ENDIF
? "Message SID: " + oReply:StringOf("sid")
? "Initial status: " + oReply:StringOf("status")
oHttp:destroy()
oUrl:destroy()
oReq:destroy()
oResp:destroy()
oReply:destroy()