SMS API
SetPostbackUrlForPhoneNumber
This method assigns a postback URL to a given number.
Endpoint
GET:https://messaging.esendex.us/Messaging.svc/SetPostbackUrlForPhoneNumber?LicenseKey={LICENSEKEY}&PhoneNumber={PHONENUMBER}&Country={COUNTRY}&PostBackType={POSTBACKTYPE}&Url={URL}
Syntax
SetPostbackUrlForPhoneNumber(LicenseKey, PhoneNumber, Country, PostbackType, Url)
Request Parameters
Parameter Name | Description | Data Type | Required | Sample Value |
---|---|---|---|---|
LicenseKey | Your license key. | GUID | True | 00000000-0000-0000-0000-000000000000 |
PhoneNumber | Number for which to enable a postback URL. | String | True | 7575550000 |
Country | Origin country of the number. | String | True | US |
PostbackType | Indicates whether the postback URL is used for incoming messages, outgoing messages, or delivery receipts.ValueDescription0 – AllUse the postback URL for all messages. 1 – DeliveryReceiptUse the postback URL for delivery receipts. 2 – IncomingMessageUse the postback URL for incoming messages. 3 – OutgoingMessageUse the postback URL for outgoing messages. | Enum | True | 0 – All |
Url | The URL that information will be posted to. | String | True | http://www.example.com/postback.aspx |
Response
Returns: Enum
Sample:
0 – NoError
Value | Description |
---|---|
0 – NoError | The update was successful. |
1 – InvalidLicenseKey | The requested license key is invalid. |
2 – InvalidUrl | The requested URL is invalid. |
3 – InvalidPhoneNumber | The requested phone number is invalid. |
4 – InvalidPostbackType | The requested postback type is invalid. |
5 – NotFound | The requested resource was not found. |
6 – InvalidCountry | The requested country is invalid. |
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 country = "USA";
var postbackType = SMSPostbackType.All;
var url = YOUR_POSTBACK_URL;
var response = await client.SetPostbackUrlForPhoneNumberAsync(
YOUR_LICENSE_KEY, YOUR_NUMBER, country, postbackType, url);
Console.WriteLine(response);
Java
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
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 SetPostbackUrlForPhoneNumber {
public static void main(String[] args) {
try {
URL url = new URL("https://messaging.esendex.us/Messaging.svc/SetPostbackUrlForPhoneNumber?"
+ "LicenseKey=00000000-0000-0000-0000-000000000000"
+ "&PhoneNumber=15553369037"
+ "&Country=US"
+ "&PostBackType=All"
+ "&Url=http://esendex.us/postbackpage.aspx");
try {
InputStream in = url.openStream();
StreamSource source = new StreamSource(in);
printResult(source);
} catch (java.io.IOException e) {
}
} catch (MalformedURLException e) {
}
}
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 params = new URLSearchParams({
'LicenseKey': '00000000-0000-0000-0000-000000000000',
'PhoneNumber': '7575550000',
'Country': 'USA',
'PostbackType': 0,
'Url': 'https://example.com/postback.aspx'
});
const url = 'https://messaging.esendex.us/Messaging.svc/SetPostbackUrlForPhoneNumber?' + params.toString();
const response = await fetch(url, {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
});
const keywords = await response.json();
console.log(keywords);
JSON Response
0
PHP with cURL
<?php
$url = 'https://messaging.esendex.us/Messaging.svc/SetPostbackUrlForPhoneNumber?LicenseKey=00000000-0000-0000-0000-000000000000&PhoneNumber=17575550000&Country=US&PostBackType=All&URL=http://esendex.us/postbackpage.aspx';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json'));
$response = curl_exec($ch);
curl_close($ch);
print_r($response);
?>
Python
import httpx
headers = {"Accept": "application/json"}
url = "https://messaging.esendex.us/Messaging.svc/SetPostbackUrlForPhoneNumber"
request = {
"LicenseKey": "00000000-0000-0000-0000-000000000000",
"PhoneNumber": "7575550000",
"Country": "USA",
"PostbackType": 0,
"Url": "https://example.com/postback.aspx",
}
with httpx.Client(headers=headers) as client:
response = client.get(url=url, params=request)
response.raise_for_status()
print(response.json())
Ruby
require 'json'
require 'net/http'
headers = { Accept: 'application/json', 'Content-Type': 'application/json' }
uri = URI('https://messaging.esendex.us/Messaging.svc/SetPostbackUrlForPhoneNumber')
params = {
'LicenseKey': '00000000-0000-0000-0000-000000000000',
'PhoneNumber': '7575550000',
'Country': 'USA',
'PostbackType': 0,
'Url': 'https://example.com/postback.aspx'
}
uri.query = URI.encode_www_form(params)
response = Net::HTTP.get(uri, headers)
raise response.message if response.is_a?(Net::HTTPClientError) || response.is_a?(Net::HTTPServerError)
puts JSON.parse(response)
XML Response
<SMSPostbackReturnCode xmlns="http://sms2.cdyne.com">NoError</SMSPostbackReturnCode>
Let’s start sending, together.