Sample code for 30+ languages & platforms
Xbase++

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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL oReq
LOCAL oResp
LOCAL oSbResponseBody
LOCAL oJResp
LOCAL nRespStatusCode
LOCAL oDate_created
LOCAL oDate_updated
LOCAL oDate_sent
LOCAL cSid
LOCAL cAccount_sid
LOCAL cV_to
LOCAL cFrom
LOCAL cMessaging_service_sid
LOCAL cBody
LOCAL cStatus
LOCAL cNum_segments
LOCAL cNum_media
LOCAL cDirection
LOCAL cApi_version
LOCAL cPrice
LOCAL cPrice_unit
LOCAL cError_code
LOCAL cError_message
LOCAL cUri
LOCAL cSubresource_urisMedia

nSuccess := 0

//  This example assumes the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

oHttp := CreateObject("Chilkat.Http")

//  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

oHttp:Login := "TWILIO_ACCOUNT_SID"
oHttp:Password := "TWILIO_AUTH_TOKEN"

oReq := CreateObject("Chilkat.HttpRequest")
oReq:HttpVerb := "POST"
oReq:Path := "/2010-04-01/Accounts/TWILIO_ACCOUNT_SID/Messages.json"
oReq:ContentType := "application/x-www-form-urlencoded"
oReq:AddParam("From", "+15005550006")
oReq:AddParam("Body", "body")
oReq:AddParam("To", "+15005551212")
oReq:AddParam("MediaUrl", "https://www.chilkatsoft.com/images/starfish.jpg")

oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpReq("https://api.twilio.com/2010-04-01/Accounts/TWILIO_ACCOUNT_SID/Messages.json", oReq, oResp)
IF (nSuccess == 0)
    ? oHttp:LastErrorText
    oHttp:destroy()
    oReq:destroy()
    oResp:destroy()
    RETURN
ENDIF

oSbResponseBody := CreateObject("Chilkat.StringBuilder")
oResp:GetBodySb(oSbResponseBody)
oJResp := CreateObject("Chilkat.JsonObject")
oJResp:LoadSb(oSbResponseBody)
oJResp:EmitCompact := 0

? "Response Body:"
? oJResp:Emit()

//  A 201 status code indicates success.
nRespStatusCode := oResp:StatusCode
? "Response Status Code = " + Str(nRespStatusCode)
IF (nRespStatusCode >= 400)
    ? "Response Header:"
    ? oResp:Header
    ? "Failed."
    oHttp:destroy()
    oReq:destroy()
    oResp:destroy()
    oSbResponseBody:destroy()
    oJResp:destroy()
    RETURN
ENDIF

//  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

oDate_created := CreateObject("Chilkat.DtObj")
oDate_updated := CreateObject("Chilkat.DtObj")
oDate_sent := CreateObject("Chilkat.DtObj")

cSid := oJResp:StringOf("sid")
oJResp:DtOf("date_created", 0, oDate_created)
oJResp:DtOf("date_updated", 0, oDate_updated)
oJResp:DtOf("date_sent", 0, oDate_sent)
cAccount_sid := oJResp:StringOf("account_sid")
cV_to := oJResp:StringOf("to")
cFrom := oJResp:StringOf("from")
cMessaging_service_sid := oJResp:StringOf("messaging_service_sid")
cBody := oJResp:StringOf("body")
cStatus := oJResp:StringOf("status")
cNum_segments := oJResp:StringOf("num_segments")
cNum_media := oJResp:StringOf("num_media")
cDirection := oJResp:StringOf("direction")
cApi_version := oJResp:StringOf("api_version")
cPrice := oJResp:StringOf("price")
cPrice_unit := oJResp:StringOf("price_unit")
cError_code := oJResp:StringOf("error_code")
cError_message := oJResp:StringOf("error_message")
cUri := oJResp:StringOf("uri")
cSubresource_urisMedia := oJResp:StringOf("subresource_uris.media")

oHttp:destroy()
oReq:destroy()
oResp:destroy()
oSbResponseBody:destroy()
oJResp:destroy()
oDate_created:destroy()
oDate_updated:destroy()
oDate_sent:destroy()