Add Content To An SMS Message With API Message Tags

API message tags are user defined tags that allow you to insert text into the body an SMS message using the API. The content you add via API message tags will be added to the SMS message at send time. These tags are useful if you want to sync content from your system (database, CRM, etc.) with SMS messages you send in the application.

Tip: You will need to call addSMSDeliveries in order to use API message tags.

Creating A Message With API Message Tags

The syntax for creating an API message tag is %%#userdefined%%, where userdefined can be anything you want it to be.

Warning: The userdefined portion of API message tags cannot contain underscores followed by a number (tag_9), or number/hash symbols (#). Underscores followed by text are permitted (tag_name).

Example content passed in from the API

Example addSMSDeliveries Call

 * API Verision 4
 * This example will create an SMS delivery and send it to an entire keyword. This example
 * also demonstrates how to use the fields attribute to pass in data that will replace
 * API message tags contained in the body of the SMS message.
 * Be sure to replace the placeholder text below with real values.

$client = new SoapClient('', array('trace' => 1,
                                                                 'features' => SOAP_SINGLE_ELEMENT_ARRAYS));
setlocale(LC_ALL, 'en_US');

try {
    $token = "ADD YOUR API TOKEN HERE";

    print "logging in\n";
    $sessionId = $client->login(array('apiToken' => $token))->return;

    $session_header = new SoapHeader("",
                                     array('sessionId' => $sessionId));

    // Make delivery start timestamp
    $now = date('c');
    // Used to replace API message tags in your SMS message with the
    // value you pass in for 'content'.
    $smsMessageFieldObject = array('name' => 'SOME API MESSAGE TAG NAME',
                                   'content' => 'SOME EXAMPLE CONTENT' );

    $delivery = array('start' => $now,
                      'messageId' => 'ADD SMS MESSAGE ID HERE',
                      'deliveryType' => 'triggered',
                      'keywords' => 'ADD KEYWORD ID HERE',
                      'fields' => $smsMessageFieldObject

    $write_result = $client->addSMSDeliveries(array($delivery))->return;
    if ($write_result->errors) {
        print "There was a problem adding the SMS delivery:\n";
      } else {
        print "The SMS delivery has been successfully created.\n";

} catch (Exception $e) {
    print "uncaught exception\n";