Sample code for 30+ languages & platforms
Xbase++

SimpleTexting - Send MMS Message

See more SimpleTexting Examples

Send a multimedia message to an individual contact.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL oReq
LOCAL oResp
LOCAL oSbResponseBody
LOCAL oJResp
LOCAL nRespStatusCode
LOCAL nCode
LOCAL cMessage
LOCAL cSmsid

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:

//  curl --request POST \
//    --url 'https://app2.simpletexting.com/v1/sendmms?token=YOUR_API_TOKEN&phone=SOME_STRING_VALUE&message=SOME_STRING_VALUE&subject=SOME_STRING_VALUE&mediaUrl=SOME_ARRAY_VALUE' \
//    --header 'accept: application/json' \
//    --header 'content-type: application/x-www-form-urlencoded'

//  Use the following online tool to generate HTTP code from a CURL command
//  Convert a cURL Command to HTTP Source Code

oHttp:SetRequestHeader("accept", "application/json")
oHttp:SetRequestHeader("content-type", "application/x-www-form-urlencoded")

oReq := CreateObject("Chilkat.HttpRequest")
oReq:AddParam("token", "YOUR_API_TOKEN")
oReq:AddParam("phone", "SOME_10_DIGIT_PHONE_NUMBER")
oReq:AddParam("message", "Hello: This is a sample MMS message.")
oReq:AddParam("subject", "Starfish")
oReq:AddParam("mediaUrl", "https://www.chilkatsoft.com/images/starfish.jpg")

oReq:AddHeader("Accept", "application/json")

oReq:HttpVerb := "POST"
oReq:ContentType := "application/x-www-form-urlencoded"

oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpReq("https://app2.simpletexting.com/v1/sendmms", 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()

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)

//  {
//    "code": 1,
//    "message": "The request succeeded",
//    "smsid": "5bec5b9d0a975a238808ffb2"
//  }

//  Sample code for parsing the JSON response...
//  Use the following online tool to generate parsing code from sample JSON:
//  Generate Parsing Code from JSON

nCode := oJResp:IntOf("code")
cMessage := oJResp:StringOf("message")
cSmsid := oJResp:StringOf("smsid")

oHttp:destroy()
oReq:destroy()
oResp:destroy()
oSbResponseBody:destroy()
oJResp:destroy()