mData lets you create dynamic, data-driven applications on our platform. Either upload your database as a CSV or, to make rich applications using SMS, just point us to your web service and we’ll handle all the messaging for you.

Using a Web Service
Request Parameters
Sample PHP Code


Using a Web Service

When you set up your mData, specify a URL instead of “Upload CSV”. We will ping that URL whenever we get a message and append ?args= to the end of the request. You can then parse the args parameter, generate a dynamic response, and return us XML as follows:

 

1
2
3
4
5
6
7
8
<?xml version="1.0" encoding="UTF-8"?>
<response>
 <reply>
  <text>
   <![CDATA[This is the response message]]>
  </text>
 </reply>
</response>

Pastie #342403 linked directly from Pastie.

We will parse your XML and send the dynamic message back to the user.

 

Request Parameters

We will pass the following url parameters to your web service

Request Parameters
args The args parameter will contain the body of the message sent by the user, with the keywords removed. For example, with a mData campaign that has a keyword CELSIUS,
if a user sends CELSIUS 100, we’ll pass args=100 to your web service.
phone The phone parameter will contain the phone number of the user who sent the message. For example, we’ll passphone=2125551234 to your webservice.
keyword The keyword parameter will contain the keyword that the user actually texted to query your service. You can set up multiple keywords for a single mData program and customize your service to behave differently for each. Using the example above, we would sendkeyword=celsius to your web service.
profile_first_name The first name of the user who texted in, if it’s in their Mobile Commons profile
profile_last_name The last name of the user who texted in, if it’s in their Mobile Commons profile
profile_email The email of the user who texted in, if it’s in their Mobile Commons profile
profile_street1 The first line of the address of the user who texted in, if it’s in their Mobile Commons profile
profile_street2 The second line of the address of the user who texted in, if it’s in their Mobile Commons profile
profile_city The city of the user who texted in, if it’s in their Mobile Commons profile
profile_state The state of the user who texted in, if it’s in their Mobile Commons profile
profile_postal_code The 5- or 9-digit postal code of the user who texted in, if it’s in their Mobile Commons profile
profile_CUSTOM_FIELD If you have custom fields setup for your profiles, they will be prefixed with profile_, such asprofile_favorite_color=red
longitude If your mData uses location-based queries, we will geocode the user’s query and send you the longitude, if available
latitude If your mData uses location-based queries, we will geocode the user’s query and send you the latitude, if available

Sample PHP Code

The following PHP code sample will take a value in Fahrenheit and convert it to Celsius.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
$msg = "";
$fahrenheit = $_GET['args'];
$phone = $_GET['phone'];
$celsius = convert_to_celsius($fahrenheit);
$msg = "$fahrenheit degrees Fahrenheit is $celsius degrees Celsius";

echo generate_xml($msg);

function convert_to_celsius($f) {
	return ($f-32)*(5.0/9.0);
}

function generate_xml($msg) {
   $resp  = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response><reply>";
   $resp .= "<text><![CDATA[$msg]]></text>";
   $resp .= "</reply></response>";
   return $resp;
}
?>

Pastie #342398 linked directly from Pastie.