Send Email
Next: Log In

You can use the API to schedule message delivieries. This example will create a delivery to send a message to a single contact. It assumes you have already created a message containing the following API messages tags: %%#purchasetable%% and %%#cardlast4%%.

Start Tutorial

Authenticate With Bronto

Before you can login using the API, you need to log into Bronto and set up your authentication and API access tokens. To do this:

  1. Go to Home->Data Exchange.
  2. Click Add Access Token.
  3. Make sure the token has Read, Write and Send permissions.
  4. Create API Session

    Use the access token you created to log in. The session ID created when you log into the API will expire if there is no transaction for a 20 minute period.

    Get the Message ID

    Get the ID for the message you want to send. You will need to use this ID in a later step.

    Get the Contact ID

    Get the ID for the contact you want to send to. You will need to use this ID in a later step.

    Make the Delivery Timestamp

    Indicate the start time for the message delivery.

    Provide Delivery Parameters

    Create an array that contains all of the delivery parameters. This should include:

    • the start time
    • the message ID
    • your sender information (from name, from email address)
    • the contact ID
    • Any data that tags or loops in the message need in order to display properly. For example, if the message has a cart loop you need to provide the relevant cart mapping data.
    • Results

      After you send the message you will receive a confirmation or error message. In the event of an error, we suggest you retry connecting to the API a few times before exiting your script, and saving in an error log when the failure happened.

      In order to retrieve all objects in a result set, you must iterate over all the available pages. This is done by incrementing the pageNumber parameter on subsequent read calls. When the API returns an empty result set, you know that you have retrieved all objects available. The initial page number is 1. The behavior of making multiple read calls to the same page is not defined and should not be relied upon to perform successfully.

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      49
      50
      51
      52
      53
      54
      <?php
      /**
      * API VERSION 4
      * This example will create a delivery to send a message to a single
      * contact. It assumes you have already created a message containing
      * the following API messages tags: %%#purchasetable%% and
      * %%#cardlast4%%.
      **/
      $client = new SoapClient('https://api.bronto.com/v4?wsdl', array('trace' => 1,
      'features' => SOAP_SINGLE_ELEMENT_ARRAYS));
      try {
      // Replace with a valid API token
      $token = "INSERT A VALID API TOKEN";
      print "logging in\n";
      $sessionId = $client->login(array('apiToken' => $token))->return;
      $session_header = new SoapHeader("http://api.bronto.com/v4",
      'sessionHeader',
      array('sessionId' => $sessionId));
      $client->__setSoapHeaders(array($session_header));
      // Get the id of the message you wish to send. It may be more
      // efficient to hardcode the ID here, depending on your own
      // usage scenario(s).
      // Replace the placeholder text with the name of a message
      // in you account.
      $messageFilter = array('name' => array('operator' => 'EqualTo',
      'value' => 'SOME MESSAGE NAME',
      ),
      );
      $message = $client->readMessages(array('pageNumber' => 1,
      'includeContent' => false,
      'filter' => $messageFilter)
      )->return[0];
      if (!$message) {
      print "There was an error retrieving your message.\n";
      exit;
      }
      // Get the id of the contact you will be sending to. It may be
      // more efficient to hardcode the ID here, depending on your
      // own usage scenario(s).
      // Replace the placeholder text with the email address
      // of the contact you want to send to.
      $contactFilter = array('email' => array('operator' => 'EqualTo',
      'value' => 'SOME EMAIL ADDRESS'
      ),
      );
      $contact = $client->readContacts(array('pageNumber' => 1,
      XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX