Sample code for 30+ languages & platforms
Visual FoxPro Requires Chilkat v11.0.0+

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.

Twilio Messages API reference

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loHttp
LOCAL lcAccountSid
LOCAL loUrl
LOCAL loReq
LOCAL loResp
LOCAL loReply
LOCAL lnParsed

lnSuccess = 0

*  Assumes Chilkat is unlocked. See Global Unlock Sample.
loHttp = CreateObject('Chilkat.Http')
loHttp.RequireSslCertVerify = 1
loHttp.BasicAuth = 1
*  Load the owning Account SID and an API key from application configuration.
lcAccountSid = "YOUR_ACCOUNT_SID"
loHttp.Login = "YOUR_API_KEY_SID"
loHttp.Password = "YOUR_API_KEY_SECRET"
loUrl = CreateObject('Chilkat.StringBuilder')
loUrl.Append("https://api.twilio.com/2010-04-01/Accounts/")
loUrl.Append(lcAccountSid)
loUrl.Append("/Messages.json")

*  Add raw field values. Chilkat form-encodes them, including the + in a phone number.
loReq = CreateObject('Chilkat.HttpRequest')
loReq.HttpVerb = "POST"
loReq.ContentType = "application/x-www-form-urlencoded"
loReq.AddParam("From","YOUR_MMS_ENABLED_NUMBER")
loReq.AddParam("To","RECIPIENT_E164_NUMBER")
*  Supply a URL for the file itself so Twilio can retrieve the media.
loReq.AddParam("MediaUrl","https://media.example.com/photo.jpg")
loReq.AddParam("Body","Photo attached.")

loResp = CreateObject('Chilkat.HttpResponse')
loReply = CreateObject('Chilkat.JsonObject')
lnSuccess = loHttp.HttpReq(loUrl.GetAsString(),loReq,loResp)
IF (loResp.StatusCode = 0) THEN
    ? loHttp.LastErrorText
    RELEASE loHttp
    RELEASE loUrl
    RELEASE loReq
    RELEASE loResp
    RELEASE loReply
    CANCEL
ENDIF

lnParsed = loReply.Load(loResp.BodyStr)
IF ((lnSuccess <> 1) OR (loResp.StatusCode <> 201)) THEN
    ? "HTTP " + STR(loResp.StatusCode)
    IF ((lnParsed = 1) AND (loReply.HasMember("code") = 1)) THEN
        ? "Twilio error " + STR(loReply.IntOf("code")) + ": " + loReply.StringOf("message")
    ENDIF

    RELEASE loHttp
    RELEASE loUrl
    RELEASE loReq
    RELEASE loResp
    RELEASE loReply
    CANCEL
ENDIF

IF (lnParsed <> 1) THEN
    ? "Expected a JSON response."
    RELEASE loHttp
    RELEASE loUrl
    RELEASE loReq
    RELEASE loResp
    RELEASE loReply
    CANCEL
ENDIF

IF ((loReply.JsonTypeOf("sid") <> 1) OR (loReply.JsonTypeOf("status") <> 1)) THEN
    ? "The create response is missing the message SID or status."
    RELEASE loHttp
    RELEASE loUrl
    RELEASE loReq
    RELEASE loResp
    RELEASE loReply
    CANCEL
ENDIF

? "Message SID: " + loReply.StringOf("sid")
? "Initial status: " + loReply.StringOf("status")

RELEASE loHttp
RELEASE loUrl
RELEASE loReq
RELEASE loResp
RELEASE loReply