This method sends an SMS or MMS message to any number of recipients. MMS messages must each be no larger than 1MB in size.

Endpoint

POST:
https://messaging.esendex.us/Messaging.svc/SendMessage

Syntax

SendMessage(Request)

Request Parameters

Parameter NameDescriptionData TypeRequiredSample Value
AttachmentsAttachments for the message. The message must use MMS to have attachments. This value can include either URLs or Media IDs. (Media IDs are for files that you have uploaded to your license key.)Array of String valuesTrue, when sending a message without a Body.17772, https://esendexusa.com/img/docs/example.jpg
BodyText content for the message.StringTrue, when sending a message without Attachments.This is a sample message.
ConcatenateThe API automatically breaks up long SMS messages into fragments. Use concatenation to reunite the fragments as a single message on the recipient’s device. Note that fragments and concatenation are not used with MMS.BooleanFalseTrue
FromNumber to send the message from. If unspecified, one of your numbers will be chosen automatically. (Contact Esendex to add a number to your account.)StringFalse7575550000
IsUnicodeWhether the message should be sent using Unicode encoding. Note that all MMS messages support Unicode.BooleanFalseTrue
LicenseKeyYour license key.GUIDTrue00000000-0000-0000-0000-000000000000
PostbackUrlURL to send postbacks to.StringFalsehttp://www.example.com/postback.aspx
ReferenceIDCustom ID of your choice. You can use this ID to filter incoming messages when you read them.StringFalse123
ScheduledDateTimeUTC date/time when message will send. Specified as milliseconds from the epoch of 1970-01-01T00:00:00Z.DateTimeFalse/Date(1682439497785)/
SubjectSubject line for the message.StringFalseMessaging Test
ToRecipient number.Array of String valuesTrue7575559999
UseMMSWhether to send as an MMS message. MMS is required when sending attachments.BooleanTrueTrue

Response

Returns: Array of OutgoingMessageResponse objects

Code Samples

You can use any programming language you want with our API, as long as it can make a REST or SOAP call. Here are examples for some of the most common platforms.

C#

// https://messaging.esendex.us/Messaging.svc?wsdl was added as a Service Reference and given the name WSDL

using WSDL;

var client = new MessagingClient(MessagingClient.EndpointConfiguration.mms2wsHttpBindingSecure);

var request = new OutgoingMessageRequest
{
    Attachments = new[] { "https://esendexusa.com/img/docs/example.jpg" },
    Body = "Hi, this message was sent using C#.",
    From = YOUR_FROM_NUMBER,
    LicenseKey = YOUR_LICENSE_KEY,
    ScheduledDateTime = DateTime.UtcNow.AddMinutes(1),
    To = new[] { YOUR_TO_NUMBER },
    UseMMS = true
};

var messages = await client.SendMessageAsync(request);

foreach (var m in messages)
{
    Console.WriteLine(
        "Message ID: " + m.MessageID + Environment.NewLine +
        "Message Status: " + m.MessageStatus + Environment.NewLine +
        "To: " + m.To + Environment.NewLine +
        "From: " + m.From + Environment.NewLine +
        "UTC Time Sent: " + m.SentTime + Environment.NewLine +
        "Attachments: " + m.Attachments + Environment.NewLine);
}

Java

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.time.Instant;

public final class App {
    public static void main(String[] args) throws Exception {
        var url = new URL("https://messaging.esendex.us/Messaging.svc/SendMessage");
        var con = (HttpURLConnection) url.openConnection();
        con.setRequestMethod("POST");
        con.setRequestProperty("Content-Type", "application/json");
        con.setRequestProperty("Accept", "application/json");
        con.setDoInput(true);
        con.setDoOutput(true);

        var scheduledMilli = Instant.now().plusSeconds(60).toEpochMilli();
        var scheduledDateTime = String.format("/Date(%s)/", scheduledMilli);
        var json = """
                {
                    "Attachments": [ "https://esendexusa.com/img/docs/example.jpg" ],
                    "Body": "Hi, this message was sent using Java.",
                    "LicenseKey": "00000000-0000-0000-0000-000000000000",
                    "From": "54321",
                    "To": [ "7575559999" ],
                    "ScheduledDateTime": "%s",
                    "UseMMS": true
                }
                """.formatted(scheduledDateTime);

        try (var os = con.getOutputStream()) {
            var input = json.getBytes("utf-8");
            os.write(input, 0, input.length);
        }

        var response = new StringBuilder();
        String responseLine = null;

        if (con.getResponseCode() == 200) {
            try (var br = new BufferedReader(
                    new InputStreamReader(con.getInputStream(), "utf-8"))) {
                while ((responseLine = br.readLine()) != null) {
                    response.append(responseLine.trim());
                }
            }
        } else {
            try (var br = new BufferedReader(
                    new InputStreamReader(con.getErrorStream(), "utf-8"))) {
                while ((responseLine = br.readLine()) != null) {
                    response.append(responseLine.trim());
                }
            }
        }

        System.out.println(response.toString());
    }
}

JavaScript

// Let's send one minute from now.
const ms = Date.now() + 60000;
const scheduledDateTime = `/Date(${ms})/`;

const url = 'https://messaging.esendex.us/Messaging.svc/SendMessage';
const response = await fetch(url, {
    headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({
        'Attachments': ['https://esendexusa.com/img/docs/example.jpg'],
        'Body': 'Hi, this message was sent using JavaScript.',
        'From': '7575550000',
        'LicenseKey': '00000000-0000-0000-0000-000000000000',
        'ScheduledDateTime': scheduledDateTime,
        'To': ['7575559999'],
        'UseMMS': true
    }),
    method: 'POST'
});
const messages = await response.json();

console.log(messages);

JSON POST Request

{
	"Attachments": [
		"String content"
	],
	"Body": "String content",
	"Concatenate": true,
	"From": "String content",
	"IsUnicode": true,
	"LicenseKey": "1627aea5-8e0a-4371-9022-9b504344e724",
	"PostbackUrl": "String content",
	"ReferenceID": "String content",
	"ScheduledDateTime": "/Date(928164000000-0400)/",
	"Subject": "String content",
	"To": [
		"String content"
	],
	"UseMMS": true
}

JSON Response

[
	{
		"Attachments": "String content",
		"From": "String content",
		"MessageID": "1627aea5-8e0a-4371-9022-9b504344e724",
		"MessageStatus": 0,
		"SentTime": "/Date(928164000000-0400)/",
		"To": "String content"
	}
]

PHP with cURL

<?php

$json = '{
  "Attachments":["https://picsum.photos/id/0/100"],
  "Body":"",
  "Concatenate":false,
  "From":"7575550000",
  "IsUnicode":false,
  "LicenseKey":"00000000-0000-0000-0000-000000000000",
  "PostbackUrl":"http://esendex.us/postback.aspx",
  "ReferenceID":"",
  "ScheduledDateTime":"/Date(1239018869048)/",
  "Subject":"",
  "To":["15553096094"],
  "UseMMS":true
}';

$url = 'https://messaging.esendex.us/Messaging.svc/SendMessage';
$cURL = curl_init();

curl_setopt($cURL, CURLOPT_URL, $url);
curl_setopt($cURL, CURLOPT_POST, true);
curl_setopt($cURL, CURLOPT_POSTFIELDS, $json);
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);

curl_setopt($cURL, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json'));
// If you desire your results in XML format, use the following line for your HTTP headers and comment out the HTTP headers code line above.
// curl_setopt($cURL, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));

$result = curl_exec($cURL);
curl_close($cURL);
$array = json_decode($result, true);

// print_r($json);
// print_r("nnnn");
print_r($array);

?>

Python

from datetime import datetime, timedelta
import httpx

headers = {"Accept": "application/json"}
url = "https://messaging.esendex.us/Messaging.svc/SendMessage"

dt = datetime.utcnow() + timedelta(minutes=1)
ms = round(dt.timestamp() * 1000)
scheduled_date_time = f"/Date({ms})/"

request = {
    "Attachments": ["https://esendexusa.com/img/docs/example.jpg"],
    "Body": "Hi, this message was sent using Python.",
    "From": "7575550000",
    "LicenseKey": "00000000-0000-0000-0000-000000000000",
    "ScheduledDateTime": scheduled_date_time,
    "To": ["7575559999"],
    "UseMMS": True,
}

with httpx.Client(headers=headers) as client:
    response = client.post(url=url, json=request)

response.raise_for_status()

print(response.json())

Ruby

require 'date_core'
require 'json'
require 'net/http'

headers = { Accept: 'application/json', 'Content-Type': 'application/json' }
uri = URI('https://messaging.esendex.us/Messaging.svc/SendMessage')

# Let's send one minute from now.
dt = Time.now + 60
ms = dt.to_i * 1000
scheduled_date_time = "/Date(#{ms})/"

data = {
  'Attachments': ['https://esendexusa.com/img/docs/example.jpg'],
  'Body': 'Hi, this message was sent using Ruby.',
  'From': '7575550000',
  'LicenseKey': '00000000-0000-0000-0000-000000000000',
  'ScheduledDateTime': scheduled_date_time,
  'To': ['7575559999'],
  'UseMMS': true
}.to_json

response = Net::HTTP.post(uri, data, headers)
raise response.message if response.is_a?(Net::HTTPClientError) || response.is_a?(Net::HTTPServerError)

puts JSON.parse(response.body)

XML POST Request

<OutgoingMessageRequest xmlns="http://sms2.cdyne.com">
  <Attachments>
    <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">String content</string>
    <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">String content</string>
  </Attachments>
  <Body>String content</Body>
  <Concatenate>true</Concatenate>
  <From>String content</From>
  <IsUnicode>true</IsUnicode>
  <LicenseKey>1627aea5-8e0a-4371-9022-9b504344e724</LicenseKey>
  <PostbackUrl>String content</PostbackUrl>
  <ReferenceID>String content</ReferenceID>
  <ScheduledDateTime>1999-05-31T11:20:00</ScheduledDateTime>
  <Subject>String content</Subject>
  <To>
    <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">String content</string>
    <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">String content</string>
  </To>
  <UseMMS>true</UseMMS>
</OutgoingMessageRequest>

XML Response

<ArrayOfOutgoingMessageResponse xmlns="http://sms2.cdyne.com">
  <OutgoingMessageResponse>
    <Attachments>String content</Attachments>
    <From>String content</From>
    <MessageID>1627aea5-8e0a-4371-9022-9b504344e724</MessageID>
    <MessageStatus>Hold</MessageStatus>
    <SentTime>1999-05-31T11:20:00</SentTime>
    <To>String content</To>
  </OutgoingMessageResponse>
  <OutgoingMessageResponse>
    <Attachments>String content</Attachments>
    <From>String content</From>
    <MessageID>1627aea5-8e0a-4371-9022-9b504344e724</MessageID>
    <MessageStatus>Hold</MessageStatus>
    <SentTime>1999-05-31T11:20:00</SentTime>
    <To>String content</To>
  </OutgoingMessageResponse>
</ArrayOfOutgoingMessageResponse>

Let’s get your business buzzing

Spark customer connections in minutes. Discover the full power of our mobile messaging platform—no hidden fees, just real results.