php
My Emma Web Service
Example - myemma.com
webservices my emma
api
Having trouble with the lack of myEmma webservice api examples? Look here for myemma webservices example!
MyEmma is a great place to setup your mass email contacts and then mass email them (if you must do such a thing in your marketing). Their API is great, and pretty straightforward (if you are a SOAP aficionado and happen to breath envelope objects).
The biggest hurdle I found was myemma's lack of information on the auth object.
I finally pulled it together as I read the information on how the KeyValue objects are to be created. I wrote a mini-class to help me do this more quickly:
class eo {
function __construct($k,$v) {
$this->key = $k;
$this->value = $v;
}
};
Every KeyValue object must be its own object. Place those objects in an array, and pass them appropriately.
Check out this snippet of documentation for the addMember() call.
string addMember(object[] auth, string member_id, object[] member_info, object[] flags)
Once our soap client is created, we call the web service function,
$client->addMember()
, passing in the appropriate arguments:- object[] auth: create an array of
mini-class, key-value pairs that coincide with the myemma auth objecteo
- string member_id: i believe this is primarily for editing an existing member. it doesn't matter in this example; we are adding a new user, period
- object[] member_info: the member_info object is an array of
mini-class, key-value pairs that match up with fields in the myemma account (these include fields like "email, first_name, and last_name"eo
- object[] flags: shrug. i didn't go far enough to need any flags. maybe i'll update this at some point. email me and complain if the absence bothers you.
Enough! Show me the example!
Okay, okay, keep your shirts on.
// jjohnston 2011-07-20
// requirements php5 with SoapClass!
// example usage:
// http://jayjohnston.com/this_file.php?first_name=jay&last_name=johnston&email=jj@icglink.com
// FILL THESE IN FOR ***YOUR*** CLIENT
$myemma_emma_account_id = '12345';
$myemma_login = 'loginWS';
$myemma_password = 'pAsswerd9';
// emma fields (set these up in your myemma account)
// these fields may be passed via GET like this ?first_name=my&last_name=emma&email=emma@myemma.com
$fields = explode(',','first_name,last_name,email,city,state,address');
// mini-keyvalue class builder
class eo {
function __construct($k,$v) {
$this->key = $k;
$this->value = $v;
}
};
$login[] = new eo('emma_account_id',$myemma_emma_account_id);
$login[] = new eo('login','mscliWS',$myemma_login);
$login[] = new eo('password',$myemma_password);
$wsdl = 'https://rsvc1.e2ma.net/emmaWebServices.wsdl';
$client = new SoapClient($wsdl,array('trace'=>true));
// auto add and email based on the get params called
foreach($fields as &$f) {
if (!empty($_GET[$f])) {
$member[] = new eo($f,urldecode($_GET[$f]);
}
}
/*
// it would look kind of like this:
$member[] = new eo('first_name','my');
$member[] = new eo('last_name','emma');
$member[] = new eo('email','emma@myemma.com');
*/
try {
$client->addMember($login,'1',$member);
//echo $output.'<hr/>';
} catch (Exception $e) {
// if you are having trouble, uncomment these lines and check out the fault message:
/*
$debuginfo = "Request :<textarea style='width:800px;height:200px;'>".str_replace(array('<',"n</"),array("n<",'</'),$client->__getLastRequest()) ."</textarea><br/>";
$debuginfo = "Response:<textarea style='width:800px;height:200px;'>".htmlspecialchars($client->__getLastResponse())."</textarea>";
echo $debuginfo;
*/
}
Last Updated: 2011-07-20 14:21:52