PHP Examples
Overview
The code samples in this section all use the following classes.
The Request class uses cURL to make the requests to the API.
The Response class contains the API response and returned status code info.
Login
There are two options to request the login route:
with username and password
with api token (access token)
Example of login with username and password parameters.
<?php
// Include Request and Response classes
$url = 'https://api.example.com/v2/login';
$params = array(
'username' => 'sample_username',
'password' => 'sample_password'
);
// Create a new Request object
$request = new Request($url, 'POST', $params);
// Send the request
$request->send();
// Get the Response object
$response = $request->getResponse();
if($response->getStatusCode() == 200) {
// Retrieve the session token details
$token = $response->getBodyDecoded();
print_r($token);
}
else {
echo $response->getStatusCode() . PHP_EOL;
echo $response->getReasonPhrase() . PHP_EOL;
echo $response->getBody() . PHP_EOL;
}
?>Example of login with API token (access token)
Authentication
Each request to user related content requires an Authorization header to be set, with the value containing the token type and Session token received from the API Login request.
A valid /login request to the API will return the following json payload.
The Session token should be included in all subsequent user related content requests to the API.
The type is to be prepended to the the token, separated by a single space.
The expires_in is the time in seconds that the token will be valid for. When this time expires, a new token will need to be attained via the /login request.
Example of Getting and Setting Authorization Header with username and password
Example of Getting and Setting Authorization Header with API token
Collections
The following is an example of a request to get the Browsers collection.
Statistics
The following is an example of an advertiser request to statistics/a/date.
In case additional_group_by value is defined, the request will be grouped by the main route field and the extra one(s).
Example of statistics per date filtered by campaign ID 1234.
Example of statistics per date with additional group by campaign.
post /statistics/a/global
Get global advertiser statistics
Example 1 of global statistics
Example for global statistics request.
Only the group_by parameter is mandatory. The default values for the other parameters can be found Here.
Please note that the global statistic routes (statistics/a/global, statistics/p/global) have different parameters format.
Example 2 of global statistics
Get statistics per date including sum totals.
Example 3 of global statistics
Get statistics per campaign and country filtered by specific date ordered by impressions.
Example 4 of global statistics
Get publisher statistics per zone and country filtered by specific operating system.
Last updated
Was this helpful?

