Retrieve Email Messages (get)
<?php
//example PHP code to get email messages by criteria
//set values of messages to get
$url_params['apiKey']="APIKEY_HERE";
$url_params['templateFlag']="0"; //Template flag. 0=Not a template, 1=Is a template. Defaults to 0.
//Optional fields commented out below:
//$url_params['sortBy']="SORTBY_HERE"; //Column to sort results by. Values: subject,emailname,updatedate
//$url_params['sortDirection']="SORTDIRECTION_HERE"; //Direction to sort results by. Values: asc or desc
//$url_params['searchFields']="SEARCHFIELDS_HERE"; //Field or comma-delimited list of fields to search on. Values: subject,emailname
//$url_params['searchValue']="SEARCHVALUE_HERE"; //Value to search for.
//$url_params['start']="START_HERE"; //Control paging of email messages, defaults to 1st page of data (page 0)
//$url_params['limit']="LIMIT_HERE"; //Control paging of email messages, number of messages to return with each call, defaults to 100 (max=100000)
$url = 'http://apidomain.com/api8/messages';
$url = sprintf("%s?%s", $url, http_build_query($url_params));
//Uses CURL, GET Request
$curl = curl_init($url);
curl_setopt ($curl, CURLOPT_CONNECTTIMEOUT, 100);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec ($curl);
curl_close ($curl);
echo $result;
//Parse the json to get return values.
$parsed_result = json_decode($result,false);
echo "<br><br>Status: $parsed_result->status";
echo "<br>Message: $parsed_result->message";
echo "<br>Error Code: $parsed_result->errorcode";
echo "<br>Error Message: $parsed_result->errormessage";
echo "<br># of Lists that match criteria: ";
echo $parsed_result->data->totalrowcount;
echo "<br>Email Message ID: ";
echo $parsed_result->data->data[0]->id;
echo "<br>Subject: ";
echo $parsed_result->data->data[0]->subject;
echo "<br>Email Message ID: ";
echo $parsed_result->data->data[1]->id;
echo "<br>Subject: ";
echo $parsed_result->data->data[1]->subject;
?>
Comments
0 comments
Article is closed for comments.