REST API v4: GET document statistics (HTML mailing)
You can retrieve the statistics of an HTML emailing document by sending an HTTP GET request to the following URL:
https://api.copernica.com/v4/html/document/$id/statistics
Where the $id
should be replaced with the ID of the emailing document.
Available parameters
- begintime: Start date (and time) for the statistics (YYYY-MM-DD HH:MM:SS format).
- endtime: End date (and time) for the statistics (YYYY-MM-DD HH:MM:SS format).
- type: Includes the type of mailings to include ('mass', 'individual' or 'both').
- followups: Indicates whether we should retrieve only mailings from follow-ups ('yes'), only mailings not from follow-ups ('no') or all mailings ('both').
- test: Indicates whether we should retrieve only test mailings ('yes'), only mailings that were not tests ('no') or all mailings ('both').
- mindestinations: Only retrieve mailings at least this many destinations.
- maxdestinations: Only retrieve mailings with at most this many destinations.
Return value
Fields
The following fields are available in the JSON object:
- abuses: An array with fields 'total' and 'unique' for the total number of clicks and number of unique clicks respectively.
- clicks: An array with fields 'total' and 'unique' for the total number of clicks and number of unique clicks respectively.
- errors: An array with fields 'total' and 'unique' for the total number of clicks and number of unique clicks respectively.
- impressions: An array with fields 'total' and 'unique' for the total number of clicks and number of unique clicks respectively.
- unsubscribes: An array with fields 'total' and 'unique' for the total number of clicks and number of unique clicks respectively.
- unknown: An array with the field 'total' for all of the statistics not fitting the categories above.
Example
The JSON output will look something like this:
{
"clicks":{
"total":"53",
"unique":"14"
},
"impressions":{
"total":"80",
"unique":"49"
},
"errors":{
"total":"2412",
"unique":"2289"
},
"unsubscribes":{
"total":"0",
"unique":"0"
},
"abuses":{
"total":"0",
"unique":"0"
},
"unknown":{
"total":"22"
}
}
PHP example
This script demonstrates how to use this API method:
// dependencies
require_once('CopernicaRestAPI.php');
// change this into your access token
$api = new CopernicaRestAPI("your-access-token", 4);
// set the period
$data = array(
'begintime' => "2019-01-01 00:00:00",
'endtime' => "2019-02-01 00:00:00"
);
// execute the call
print_r($api->get("html/document/{$documentID}/statistics/", $data));
This example requires the REST API class.