This method cancels a message scheduled for a future time or date. It has no effect on messages that have already been sent or queued.
Endpoint
POST:https://messaging.esendex.us/messaging.svc/CancelMessage
GET:https://messaging.esendex.us/messaging.svc/CancelMessage?MessageID={MESSAGEID}
Syntax
CancelMessage(MessageID)
Request Parameters
Parameter Name | Description | Data Type | Required | Sample Value |
---|---|---|---|---|
MessageID | Unique ID of the message to cancel. | GUID | True | 1627aea5-8e0a-4371-9022-9b504344e724 |
Response
Returns: Boolean
Description: Whether the cancellation was successful or not.
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#
- Java
- JavaScript
- JSON POST Request
- JSON Response
- PHP with cURL
- Python
- Ruby
- XML POST Request
- XML Response
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);
// Let's schedule a message.
var messageResponses = await client.SendMessageAsync(new OutgoingMessageRequest
{
Body = "Hi, this is a test.",
LicenseKey = YOUR_LICENSE_KEY,
From = YOUR_FROM_NUMBER,
To = new[] { YOUR_TO_NUMBER },
ScheduledDateTime = DateTime.UtcNow.AddDays(1)
});
// We can use this ID to cancel the message later on.
var messageId = messageResponses[0].MessageID;
// We can cancel the message at any time before it's sent. Let's cancel it now.
var success = await client.CancelMessageAsync(messageId);
Console.WriteLine("Message cancelled: " + success);
Java
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.URL;
import java.net.MalformedURLException;
import java.util.Properties;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
public final class CancelMessage {
public static void main(String[] args) {
try {
URL url = new URL("https://messaging.esendex.us/Messaging.svc/CancelMessage?"
+ "MessageID=MESSAGEID OF MESSAGE YOU WANT TO CANCEL");
try {
InputStream in = url.openStream();
StreamSource source = new StreamSource(in);
printResult(source);
} catch (java.io.IOException e) {
e.printStackTrace();
}
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
private static void printResult(Source source) {
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
StreamResult sr = new StreamResult(bos);
Transformer trans = TransformerFactory.newInstance().newTransformer();
Properties oprops = new Properties();
oprops.put(OutputKeys.OMIT_XML_DECLARATION, "yes");
trans.setOutputProperties(oprops);
trans.transform(source, sr);
System.out.println("**** Response ******");
System.out.println(bos.toString());
bos.close();
System.out.println();
} catch (Exception e) {
}
}
}
JavaScript
const headers = {
'Accept': 'application/json',
'Content-Type': 'application/json'
};
// Let's schedule a message.
const url = 'https://messaging.esendex.us/Messaging.svc/SendMessage';
const response = await fetch(url, {
headers,
body: JSON.stringify({
'Body': 'Hi, this message was sent using JavaScript.',
'LicenseKey': '00000000-0000-0000-0000-000000000000',
'To': ['7575559999'],
'UseMMS': false,
"ScheduledDateTime": "/Date(9999999999999)/"
}),
method: 'POST'
});
// We can use this ID to cancel the message later on.
const messages = await response.json();
const messageId = messages[0]['MessageID'];
// We can cancel the message at any time before it's sent. Let's cancel it now.
const url2 = 'https://messaging.esendex.us/Messaging.svc/CancelMessage';
const response2 = await fetch(url2, {
headers,
body: messageId,
method: 'POST'
});
const success = await response2.json();
console.log(success);
JSON POST Request
"1627aea5-8e0a-4371-9022-9b504344e724"
JSON Response
true
PHP with cURL
<?php
$url = 'https://messaging.esendex.us/Messaging.svc/CancelMessage?MessageID=(Message ID)';
$cURL = curl_init();
curl_setopt($cURL, CURLOPT_URL, $url);
curl_setopt($cURL, CURLOPT_HTTPGET, true);
curl_setopt($cURL, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json'));
$result = curl_exec($cURL);
curl_close($cURL);
print_r($result);
?>
Python
import httpx
headers = {"Accept": "application/json"}
with httpx.Client(headers=headers) as client:
# Let's schedule a message.
response = client.post(
url="https://messaging.esendex.us/Messaging.svc/SendMessage",
json={
"Body": "Hi, this message was sent using Python.",
"LicenseKey": "00000000-0000-0000-0000-000000000000",
"To": ["7575559999"],
"UseMMS": False,
"ScheduledDateTime": "/Date(9999999999999)/",
},
)
response.raise_for_status()
# We can use this ID to cancel the message later on.
message_id = response.json()[0]["MessageID"]
if message_id == "00000000-0000-0000-0000-000000000000":
raise RuntimeError("The message could not be sent.")
# We can cancel the message at any time before it's sent. Let's cancel it now.
request = message_id
response = client.post(
url="https://messaging.esendex.us/Messaging.svc/CancelMessage",
json=request,
)
response.raise_for_status()
print(response.json())
Ruby
require 'json'
require 'net/http'
headers = { Accept: 'application/json', 'Content-Type': 'application/json' }
# Let's schedule a message.
uri = URI('https://messaging.esendex.us/Messaging.svc/SendMessage')
data = {
'Body': 'Hi, this message was sent using Ruby.',
'LicenseKey': '00000000-0000-0000-0000-000000000000',
'To': ['7575559999'],
'UseMMS': false,
'ScheduledDateTime': '/Date(9999999999999)/'
}.to_json
response = Net::HTTP.post(uri, data, headers)
raise response.message if response.is_a?(Net::HTTPClientError) || response.is_a?(Net::HTTPServerError)
# We can use this ID to cancel the message later on.
message_id = JSON.parse(response.body)[0]['MessageID']
raise 'The message could not be sent.' if message_id == '00000000-0000-0000-0000-000000000000'
# We can cancel the message at any time before it's sent. Let's cancel it now.
uri = URI('https://messaging.esendex.us/Messaging.svc/CancelMessage')
data = message_id
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
<guid xmlns="http://schemas.microsoft.com/2003/10/Serialization/">1627aea5-8e0a-4371-9022-9b504344e724</guid>
XML Response
<boolean xmlns="http://schemas.microsoft.com/2003/10/Serialization/">true</boolean>