Sample code for 30+ languages & platforms
AutoIt

MessageMedia - Send Messages

See more MessageMedia Examples

Submit one or more (up to 100 per request) SMS, MMS, or text to voice messages for delivery.

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

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

$oHttp = ObjCreate("Chilkat.Http")

;  Implements the following CURL command:

;  curl --request POST \
;       --header "Content-Type: application/json" \
;       --header "Accept: application/json" \
;       --data-binary "{
;      \"messages\": [
;          {
;              \"callback_url\": \"https://my.callback.url.com\",
;              \"content\": \"My first message\",
;              \"destination_number\": \"+61491570156\",
;              \"delivery_report\": true,
;              \"format\": \"SMS\",
;              \"message_expiry_timestamp\": \"2016-11-03T11:49:02.807Z\",
;              \"metadata\": {
;                  \"myKey\": \"myValue\",
;                  \"anotherKey\": \"anotherValue\"
;              },
;              \"scheduled\": \"2016-11-03T11:49:02.807Z\",
;              \"source_number\": \"+61491570157\",
;              \"source_number_type\": \"INTERNATIONAL\"
;          },
;          {
;              \"callback_url\": \"https://my.callback.url.com\",
;              \"content\": \"My second message\",
;              \"destination_number\": \"+61491570158\",
;              \"delivery_report\": true,
;              \"format\": \"MMS\",
;              \"subject\": \"This is an MMS message\",
;              \"media\": [ \"https://images.pexels.com/photos/1018350/pexels-photo-1018350.jpeg?cs=srgb&dl=architecture-buildings-city-1018350.jpg\" ],
;              \"message_expiry_timestamp\": \"2016-11-03T11:49:02.807Z\",
;              \"metadata\": {
;                  \"myKey\": \"myValue\",
;                  \"anotherKey\": \"anotherValue\"
;              },
;              \"scheduled\": \"2016-11-03T11:49:02.807Z\",
;              \"source_number\": \"+61491570159\",
;              \"source_number_type\": \"INTERNATIONAL\"
;          }
;      ]
;  }" \
;  https://private-anon-ecbaffbc28-messages32.apiary-mock.com/v1/messages

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

;  Use this online tool to generate code from sample JSON:
;  Generate Code to Create JSON

;  The following JSON is sent in the request body.

;  {
;    "messages": [
;      {
;        "callback_url": "https://my.callback.url.com",
;        "content": "My first message",
;        "destination_number": "+61491570156",
;        "delivery_report": true,
;        "format": "SMS",
;        "message_expiry_timestamp": "2016-11-03T11:49:02.807Z",
;        "metadata": {
;          "myKey": "myValue",
;          "anotherKey": "anotherValue"
;        },
;        "scheduled": "2016-11-03T11:49:02.807Z",
;        "source_number": "+61491570157",
;        "source_number_type": "INTERNATIONAL"
;      },
;      {
;        "callback_url": "https://my.callback.url.com",
;        "content": "My second message",
;        "destination_number": "+61491570158",
;        "delivery_report": true,
;        "format": "MMS",
;        "subject": "This is an MMS message",
;        "media": [
;          "https://images.pexels.com/photos/1018350/pexels-photo-1018350.jpeg?cs=srgb&dl=architecture-buildings-city-1018350.jpg"
;        ],
;        "message_expiry_timestamp": "2016-11-03T11:49:02.807Z",
;        "metadata": {
;          "myKey": "myValue",
;          "anotherKey": "anotherValue"
;        },
;        "scheduled": "2016-11-03T11:49:02.807Z",
;        "source_number": "+61491570159",
;        "source_number_type": "INTERNATIONAL"
;      }
;    ]
;  }

$oJson = ObjCreate("Chilkat.JsonObject")
$oJson.UpdateString("messages[0].callback_url","https://my.callback.url.com")
$oJson.UpdateString("messages[0].content","My first message")
$oJson.UpdateString("messages[0].destination_number","+61491570156")
$oJson.UpdateBool("messages[0].delivery_report",True)
$oJson.UpdateString("messages[0].format","SMS")
$oJson.UpdateString("messages[0].message_expiry_timestamp","2016-11-03T11:49:02.807Z")
$oJson.UpdateString("messages[0].metadata.myKey","myValue")
$oJson.UpdateString("messages[0].metadata.anotherKey","anotherValue")
$oJson.UpdateString("messages[0].scheduled","2016-11-03T11:49:02.807Z")
$oJson.UpdateString("messages[0].source_number","+61491570157")
$oJson.UpdateString("messages[0].source_number_type","INTERNATIONAL")
$oJson.UpdateString("messages[1].callback_url","https://my.callback.url.com")
$oJson.UpdateString("messages[1].content","My second message")
$oJson.UpdateString("messages[1].destination_number","+61491570158")
$oJson.UpdateBool("messages[1].delivery_report",True)
$oJson.UpdateString("messages[1].format","MMS")
$oJson.UpdateString("messages[1].subject","This is an MMS message")
$oJson.UpdateString("messages[1].media[0]","https://images.pexels.com/photos/1018350/pexels-photo-1018350.jpeg?cs=srgb&dl=architecture-buildings-city-1018350.jpg")
$oJson.UpdateString("messages[1].message_expiry_timestamp","2016-11-03T11:49:02.807Z")
$oJson.UpdateString("messages[1].metadata.myKey","myValue")
$oJson.UpdateString("messages[1].metadata.anotherKey","anotherValue")
$oJson.UpdateString("messages[1].scheduled","2016-11-03T11:49:02.807Z")
$oJson.UpdateString("messages[1].source_number","+61491570159")
$oJson.UpdateString("messages[1].source_number_type","INTERNATIONAL")

$oHttp.SetRequestHeader "Content-Type","application/json"
$oHttp.SetRequestHeader "Accept","application/json"

$oResp = ObjCreate("Chilkat.HttpResponse")
$bSuccess = $oHttp.HttpJson("POST","https://private-anon-ecbaffbc28-messages32.apiary-mock.com/v1/messages",$oJson,"application/json",$oResp)
If ($bSuccess = False) Then
    ConsoleWrite($oHttp.LastErrorText & @CRLF)
    Exit
EndIf

$oSbResponseBody = ObjCreate("Chilkat.StringBuilder")
$oResp.GetBodySb($oSbResponseBody)

$oJResp = ObjCreate("Chilkat.JsonObject")
$oJResp.LoadSb($oSbResponseBody)
$oJResp.EmitCompact = False

ConsoleWrite("Response Body:" & @CRLF)
ConsoleWrite($oJResp.Emit() & @CRLF)

Local $iRespStatusCode = $oResp.StatusCode
ConsoleWrite("Response Status Code = " & $iRespStatusCode & @CRLF)
If ($iRespStatusCode >= 400) Then
    ConsoleWrite("Response Header:" & @CRLF)
    ConsoleWrite($oResp.Header & @CRLF)
    ConsoleWrite("Failed." & @CRLF)
    Exit
EndIf

;  Sample JSON response:
;  (Sample code for parsing the JSON response is shown below)

;  {
;    "messages": [
;      {
;        "message_id": "04fe9a97-a579-43c5-bb1a-58ed29bf0a6a",
;        "callback_url": "https://my.url.com",
;        "status": "delivered",
;        "content": "My first message",
;        "destination_number": "+61491570156",
;        "delivery_report": true,
;        "format": "SMS",
;        "message_expiry_timestamp": "2016-11-03T11:49:02.807Z",
;        "metadata": {
;          "myKey": "myValue",
;          "anotherKey": "anotherValue"
;        },
;        "scheduled": "2016-11-03T11:49:02.807Z",
;        "source_number": "+61491570157",
;        "source_number_type": "INTERNATIONAL"
;      }
;    ]
;  }

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

Local $sMessage_id
Local $sCallback_url
Local $status
Local $sContent
Local $sDestination_number
Local $bDelivery_report
Local $sFormat
Local $sMessage_expiry_timestamp
Local $sMyKey
Local $sAnotherKey
Local $scheduled
Local $source_number
Local $source_number_type

Local $i = 0
Local $iCount_i = $oJResp.SizeOfArray("messages")
While $i < $iCount_i
    $oJResp.I = $i
    $sMessage_id = $oJResp.StringOf("messages[i].message_id")
    $sCallback_url = $oJResp.StringOf("messages[i].callback_url")
    $status = $oJResp.StringOf("messages[i].status")
    $sContent = $oJResp.StringOf("messages[i].content")
    $sDestination_number = $oJResp.StringOf("messages[i].destination_number")
    $bDelivery_report = $oJResp.BoolOf("messages[i].delivery_report")
    $sFormat = $oJResp.StringOf("messages[i].format")
    $sMessage_expiry_timestamp = $oJResp.StringOf("messages[i].message_expiry_timestamp")
    $sMyKey = $oJResp.StringOf("messages[i].metadata.myKey")
    $sAnotherKey = $oJResp.StringOf("messages[i].metadata.anotherKey")
    $scheduled = $oJResp.StringOf("messages[i].scheduled")
    $source_number = $oJResp.StringOf("messages[i].source_number")
    $source_number_type = $oJResp.StringOf("messages[i].source_number_type")
    $i = $i + 1
Wend