Beruflich Dokumente
Kultur Dokumente
API Overview
Table of Contents
1. API Overview
2. Versions
3. API Interface
4. HTTP Verbs
5. HTTP Headers
6. Returned Data - Standard Types
7. Errors
8. Pagination
9. Rate Limiting
10. PHP Code Examples
i. Login
ii. Authentication
iii. Collections
iv. Statistics
11. Changelog
2
EXADS API Overview
API Overview
This document presents a general overview of how to interact and use the EXADS Public API Version 1.
An interactive interface to the API, along with detailed request descriptions and responses, is available here.
A PHP Client is also available to expediate integration of the EXADS API into your application. The package can be
downloaded from GitHub.
API Overview 3
EXADS API Overview
Versions
The API version required should be specified in the URL of the request.
To specify the version required, place a 'v' followed by the version number itself e.g. v1. This should then be placed directly
proceeding the TLD, before the endpoint required.
A valid request to the API including the version number therefore would be:
https://api.exoclick.com/v1/login
Versions 4
EXADS API Overview
API Interface
The API Interface is a representation of the EXADS API designed to detail available requests, their associated parameters
and their expected responses.
In order to access restricted API requests, there must be an API Token set. To set a token, you must have a valid account
with the required username and password. Click on the Set API Token button on the top right of the screen and enter your
username and password. After you click the Login button, a login request will be made to the API to retrieve a valid token.
This token will then be used to validate all API requests you wish to make in that session.
To make a request to the API, click on a group. The group will expand to list the requests available. Click again on the
desired request. A panel will expand detailing the request details.
The Response body, if any, will be displayed first alongside the response Content-type.
The Request parameters, required and/or optional, are detailed next, along with the request Content-type, if required.
To make the request, fill in the required parameters. If the request body is detailed, clicking on the body in the Model
window will pre-populate the parameter window with the body.
Once all required parameters have been set, clicking on the Try it Out button will execute the request.
Four panels will appear below the button. The first displays the full Request URL.
API Interface 5
EXADS API Overview
HTTP Verbs
The following subset of HTTP verbs are supported. Please note that not all URLs will support all verbs. For information
what verbs to use for a particular resource see that resource's documentation.
Verb Uses
HTTP Verbs 6
EXADS API Overview
HTTP Headers
This section describes the HTTP headers the API will accept from any request.
Content-Type
All requests must contain a content-type HTTP Header.
Accepted Content-Types
Content-Type Errors
Response
Notes
Code
The content type was understood but could not be decoded. More information will appear in the
400
response body
In cases where the content-type header has a problem then the response content-type will be the default format for the
API, currently application/json
The API currently does not adhere to the Accept-type HTTP Header, all responses are sent in the same content-type as the
received request provided the request's content-type was valid
Authorization
This header is optional and is used to provide authentication details to the API for the current user which will enable the
current user to access restricted API resources. Tokens can be obtained via the Login API. An example header is:
The Authorization header accepts a string that is built from two parts, seperated by a single space. The first part is the
token type, the second is the access token itself.
Authorization Errors
401 The authorization header is missing or the token was invalid or expired
Choosing an authorisation token type On any failure the response headers will contain a WWW-Authenticate header
which will indicate the token type that is required for access.
HTTP Headers 7
EXADS API Overview
For the date format and time format we will use ISO 8601 standard. For dates only we will use the short variant ISO 8601:
YYYY-MM-DD
Errors
All errors will return the most specific, appropriate HTTP response code from the following table:
Return Codes
A malformed request was received from the client. This is the most generic
400 Bad Request
response given by the API
401 Unauthorized You are not authorized and cannot access the requested resource
403 Forbidden You do not have permission to access the requested resource
404 Not Found The requested resource cannot be found. It may become available later
Method Not
405 An unsupported HTTP method was used for the requested resource
Allowed
406 Not Acceptable The Accept or Accept-Encoding type requested by the client is not available
The request cannot be completed because there is a conflict with the existing
409 Conflict
resource
410 Gone The requested resource is no longer available and never will be in future
411 Length Required The requested resource expects a Content-Length to be supplied by the client
Request Entity The request body supplied by the client was too large, the resource refuses to
413
Too Large process it
Unsupported
415 An incorrect (or no) Content-Type has been supplied by the client
Media Type
Unprocessable The request is not malformed and the media type is acceptable but the resource
422
Entity cannot process the request
Too many The rate limit has been reached. Please see Rate Limiting section for more
429
requests information
Internal Server The server could not process your request due to an unexpected internal server
500
Error error
501 Not Implemented The requested resource has not been implemented
Service
503 The requested service is temporarily not available
Unavailable
Examples
This is the simplest form of an error's return body, clients can rely on these fields being present in every error.
Errors 9
EXADS API Overview
{
"code": 429,
"message": "You have exceeded your number of requests. Please try again later"
}
The following example has, in addition to the standard fields, for errors associated with this specific request.
{
"code": 422,
"message": "Unprocessable entity",
"cause": "Validation failed",
"errors": [
{
"resource": "Issue",
"field": "title",
"code": "missing_field"
},
...
]
}
Errors 10
EXADS API Overview
Pagination
Requests that return multiple items can be paginated. The standard way of performing pagination is with GET parameters -
limit and offset. Page numbering is 1-based.
limit The number of records to return in this request Default is 50. Minimum value is 1
offset The position to retrieve the records from. Default is 0. Minumum value is 0
Examples
Pagination - Example 1
$ curl -i https://api.exoclick.com/v1/statistics/advertiser/sites?limit=5&offset=40
Pagination 11
EXADS API Overview
Rate Limiting
The API is rate-limited to 150000 requests every 900 seconds. All requests count towards the total. Every request
processed by the API returns rate limiting information in the HTTP headers.
Examples
$ curl -i https://api.exoclick.com/v1/statistics/advertiser/date
{
"HTTP/1.1": "200 OK",
"Date": "Fri, 24 Oct 2014 14:57:32 GMT",
"Content-Type": "application/json",
"Transfer-Encoding": "chunked",
"X-Rate-Limit-Limit": 150000,
"X-Rate-Limit-Remaining": 149994,
"X-Rate-Limit-Reset": 27
}
When the rate limit is exceeded a 429 Too Many Requests HTTP error will be thrown by any subsequent requests until the
rate limit is reset. As with a normal request the rate limiting information will be available in the HTTP headers.
$ curl -i https://api.exoclick.com/v1/statistics/advertiser/date
{
"HTTP/1.1": "429 Too Many Requests",
"Date": "Fri, 24 Oct 2014 15:04:35 GMT",
"Content-Type": "application/json",
"Transfer-Encoding": "chunked",
"X-Rate-Limit-Limit": 150000,
"X-Rate-Limit-Remaining": 0,
"X-Rate-Limit-Reset": 12
}
Rate Limiting 12
EXADS API Overview
The Request class uses cURL to make the requests to the API.
The Response class contains the API response and returned status code info.
class Request {
/**
* @var resource
*/
protected $_request;
/**
* @var integer
*/
protected $_method;
/**
* @var string
*/
protected $_url;
/**
* @var array
*/
protected $_headers = array(
'Content-type: application/json'
);
/**
* @var string|array
*/
protected $_params;
/**
* @var object Response
*/
protected $_reponse;
/**
* Constructor
*
* @param string $url
* @param string $method
* @param array $params
*/
public function __construct($url, $method, $params = array()) {
$this->_url = $url;
/**
* Determine the Request method
*
* @param string $method
*/
private function setMethod() {
switch($this->_method) {
case 'GET':
break;
case 'POST':
curl_setopt($this->_request, CURLOPT_POST, 1);
break;
case 'PUT':
curl_setopt($this->_request, CURLOPT_CUSTOMREQUEST, 'PUT');
break;
case 'DELETE':
curl_setopt($this->_request, CURLOPT_CUSTOMREQUEST, 'DELETE');
break;
}
}
/**
* Add authorization header
*
* @param string $type
* @param string $token
*/
public function setAuthorizationHeader($type, $token) {
/**
* Add body to request
*/
private function addBody() {
if(is_array($this->_params)) {
// JSON Encode the array
$this->_params = json_encode($this->_params);
}
/**
* Add a query string to the request
*/
private function addQueryString() {
$query_string = '?';
trim($query_string, '&');
/**
* Send the request
*/
public function send() {
// Add a body
$this->addBody();
if(empty($this->_headers) == false) {
// Set the headers
curl_setopt($this->_request, CURLOPT_HTTPHEADER, $this->_headers);
}
/**
* Get the response
*
* @return object
*/
public function getResponse() {
return $this->_response;
}
}
class Response {
/**
* @var array
*/
protected $_reason_phrases = array(
//Informational 1xx
100 => "Continue",
101 => "Switching Protocols",
// Successful 2xx
200 => "OK",
201 => "Created",
202 => "Accepted",
203 => "Non-Authoritative Information",
204 => "No Content",
205 => "Reset Content",
206 => "Partial Content",
// Redirection 3xx
300 => "Multiple Choices",
301 => "Moved Permanently",
302 => "Found",
303 => "See Other",
304 => "Not Modified",
305 => "Use Proxy",
306 => "(Unused)",
307 => "Temporary Redirect",
/**
* @var integer
*/
protected $_status_code;
/**
* @var string
*/
protected $_body;
/**
* Constructor
*
* @param string $body
*/
public function __construct($body) {
$this->_body = $body;
}
/**
* Constructor
*
* @param string $status_code
*/
public function setStatusCode($status_code) {
$this->_status_code = $status_code;
}
/**
* Get status code
*
* @return integer
*/
public function getStatusCode() {
return $this->_status_code;
}
/**
* Get body
*
* @return string
*/
public function getBody() {
return $this->_body;
}
/**
* Get body JSON Decoded
*
* @return object|null
*/
public function getBodyDecoded() {
return json_decode($this->_body);
}
/**
* Get reason phrase
*
* @return string|boolean
*/
public function getReasonPhrase() {
if(array_key_exists($this->_status_code, $this->_reason_phrases)) {
return $this->_reason_phrases[$this->_status_code];
}
else {
return false;
}
}
}
Login
The following is an example of a request to the login route of the API.
<?php
$url = 'https://api.exoclick.com/v1/login';
$params = array(
'username' => 'sample_username',
'password' => 'sample_password'
);
if($response->getStatusCode() == 200) {
print_r($response->getBodyDecoded());
}
else {
Login 18
EXADS API Overview
Authentication
Each request to user related content requires an Authorization header to be set, with the value containing the token type
and token received from the API Login request.
A valid /login request to the API will return the following json payload.
{
"token": "",
"type": "",
"expires_in": 0
}
The token should be included in all subsequent user related content requests to the API.
Bearer 4e63518d383d8fcaefb516fe708b893727463031
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.
<?php
// Login
$url = 'https://api.exoclick.com/v1/login';
$params = array(
'username' => 'sample_username',
'password' => 'sample_password'
);
if($response->getStatusCode() == 200) {
// Get Campaigns
$url = 'https://api.exoclick.com/v1/campaigns';
Authentication 19
EXADS API Overview
if($response->getStatusCode() == 200) {
foreach($campaigns->result as $campaign) {
// Display the campaign names
echo $campaign->name . PHP_EOL;
}
}
else {
// Campaigns request error
echo $response->getStatusCode() . PHP_EOL;
echo $response->getReasonPhrase() . PHP_EOL;
echo $response->getBody();
}
}
else {
// Invalid Login
echo $response->getStatusCode() . PHP_EOL;
echo $response->getReasonPhrase() . PHP_EOL;
echo $response->getBody();
}
?>
Authentication 20
EXADS API Overview
Collections Request
The following is an example of a request to get the Browsers collection.
<?php
$url = 'https://api.exoclick.com/v1/collections/browsers';
if($response->getStatusCode() == 200) {
$browsers = $response->getBodyDecoded();
foreach($browsers as $browser) {
Collections 21
EXADS API Overview
Statistics Request
The following is an example of a request to statistics/advertiser/date .
<?php
$url = 'https://api.exoclick.com/v1/statistics/advertiser/date';
if($response->getStatusCode() == 200) {
$statistics = $response->getBodyDecoded();
foreach($statistics->result as $statistic) {
Statistics 22
EXADS API Overview
Changelog
Version 1.0.1
Bug fix to campaigns:
active field removed
status field now
-1 = deleted
0 = paused
1 = running
Version 1.0
Endpoints available in API V1
campaigns
GET - /campaigns
GET - /campaigns/{campaignid}
PUT - /campaigns/{campaignid}/copy
PUT - /campaigns/{campaignid}/delete
PUT - /campaigns/{campaignid}/pause
PUT - /campaigns/{campaignid}/play
PUT - /campaigns/{campaignid}/restore
collections
GET - /collections
GET - /collections/browsers
GET - /collections/carriers
GET - /collections/categories
GET - /collections/countries
GET - /collections/devices
GET - /collections/languages
GET - /collections/operating-systems
login
POST - /login
payments
GET - /payments/advertiser
GET - /payments/publisher
sites
GET - /sites
statistics
GET - /statistics/advertiser/browser
GET - /statistics/advertiser/carrier
GET - /statistics/advertiser/category
GET - /statistics/advertiser/country
GET - /statistics/advertiser/date
GET - /statistics/advertiser/device
GET - /statistics/advertiser/hour
GET - /statistics/advertiser/language
GET - /statistics/advertiser/os
GET - /statistics/advertiser/site
Changelog 23
EXADS API Overview
GET - /statistics/advertiser/variation
GET - /statistics/publisher/browser
GET - /statistics/publisher/carrier
GET - /statistics/publisher/category
GET - /statistics/publisher/country
GET - /statistics/publisher/date
GET - /statistics/publisher/device
GET - /statistics/publisher/hour
GET - /statistics/publisher/os
GET - /statistics/publisher/site
GET - /statistics/publisher/sub
GET - /statistics/publisher/zone
user
GET - /user
PUT - /user
POST - /user/changepassword
zones
GET - /zones
Changelog 24