developers

contact form API

s/h overview

Automatically place incoming contact requests— like from a sign-up form—into your Shoutlet contact database.

This helps explain to your development team how to integrate your contact gathering forms with the Shoutlet contact API.

s/h getting started

To begin, you need:

  1. a Shoutlet account
  2. a Shoutlet Client API key
  3. shoutlet Group ID (optional)

If you don't have these last two items, contact your account representative.
(This will be automated in the future.)

s/h connecting to the API

s/h securing your API Key

s/h shoutlet contact fields

s/h example PHP application

Below is a sample PHP application which utilizes the Shoutlet API:

<?php
// The URL for the Shoutlet Contact API:
  $api_url = 'http://client.shoutlet.com/shoutlet/ »
api/contact_add';

// Your Client ID (provided by Shoutlet)
  $client_id  = 222;
  
// Your Client API Key (provided by Shoutlet)
  $client_api = 'a21e12345d7fedcdeaef8e3725eee1c2';
  
// An Optional Group ID for placing new contacts
// directly into a Shoutlet Group 
// (provided by Shoutlet)
  $group_id   = 276;
  $warning    = '';
  if (isset($_REQUEST['submit'])) {
  
// Validate the data against your needs:
  if (empty($_REQUEST['cn_first_name']))  »
  { $warning .= 'first name required<br />'; }

  if (empty($_REQUEST['cn_last_name']))  »
  { $warning .= 'last name required<br />'; }

  if (!preg_match('/^[^@\s]+@([-a-z0-9]+\.)+  »
  [a-z]{2,}$/i', $_REQUEST['cn_email'])) {  »
  $warning .= 'valid e-mail required<br />'; }

  if (!$warning) {
// Build a query string, the required 
// fields are: cid, capi. Optional fields 
// include gid and any of the Shoutlet 
// contact field IDs. This example uses 
// PHP CURL to make a post request with 
// these fields to Shoutlet
  $query = join('&', array("cid=$client_id",
   "capi=$client_api",
   "gid=$group_id",
   "cn_first_name={$_REQUEST['cn_first_name']}",
   "cn_last_name={$_REQUEST['cn_last_name']}",
   "cn_cell_phone={$_REQUEST['cn_cell_phone']}",
   "cn_email={$_REQUEST['cn_email']}"));
    $ch = curl_init($api_url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// On success Shoutlet will return the numerical 
// unique ID of your new Contact, or 0 on failure.
  $response = curl_exec($ch);
   curl_close($ch);
   if ($response > 0) {
    header('Location: http://www.shoutlet.com/');
    exit;
   }
   else { $warning = 'An error occurred »
    saving this contact.'; }
   }
}
?>

line breaks are marked with   »