GuidesAPI ReferenceChangelog
GuidesAPI ReferenceChangelogLog In

PHP API Client Library



The PHP Criteo API Library provides a set of classes and methods that allow for quick programmatic access to your Criteo data and campaign controls.



$ composer require criteo/criteo-php-marketing-transition-sdk

Manual Installation
Download the files and include autoload.php in your project:



The suggested method of authenticating with the PHP library is to use the TokenAutoRefreshClient to manage the expiration and refresh of the authentication token, which expires five minutes after issue.

This removes the need to make any manual requests to the OAuthApi endpoint or write any code to update the authorization header.

require_once(__DIR__ . '/vendor/autoload.php');

use Criteo\Marketing\TokenAutoRefreshClient;

$auth = new TokenAutoRefreshClient('client_id', 'client_secret');

Alternatively, you can manually retrieve an authorization token using the OAuthApi:

require_once(__DIR__ . '/vendor/autoload.php');

$apiInstance = new Criteo\Marketing\Api\OAuthApi();

$client_id = 'client_id';
$client_secret = 'client_secret';

$response = $apiInstance->createToken($client_id, $client_secret, 'client_credentials');
$token = $response['access_token'];

You can then manually specify the <token value> string when making each call, as detailed below.


A Basic Request (Token Auto Refresh)

Once authenticated, you should instantiate a class that corresponds with the API endpoint you will be accessing.

For instance, to make a call to the Advertisers service, you should use Criteo\Marketing\Api\AdvertisersApi class and pass it the TokenAutoRefreshClient instance on initialization.

The full list of classes and their corresponding methods can be found on the Github readme.

require_once(__DIR__ . '/vendor/autoload.php');

use Criteo\Marketing\TokenAutoRefreshClient;
use Criteo\Marketing\Api\AdvertisersApi;

$auth = new TokenAutoRefreshClient('client_id', 'client_secret');

$advAPI = new AdvertisersApi($auth);

$response = $advAPI->apiPortfolioGet();

You can then make a call using any of the available methods for that client, such as the apiPortfolioGet method above.


A Basic Request (Manual Auth)

Here is a full, manual example of how to retrieve an auth token and use it to specify the header when making a apiPortfolioGet request.

require_once(__DIR__ . '/vendor/autoload.php');

use Criteo\Marketing\Api\OAuthApi;
use Criteo\Marketing\Api\AdvertiserApi;

$apiInstance = new OAuthApi();

$client_id = 'client_id'; 
$client_secret = 'client_secret'; 

$authResponse = $apiInstance->createToken($client_id, $client_secret, 'client_credentials');
$token = $authResponse['access_token'];

$config = Criteo\Marketing\Configuration::getDefaultConfiguration()->setAccessToken($token);

$advAPI = new AdvertiserApi(new GuzzleHttp\Client(),$config);
$portfolioResponse = $advAPI->apiPortfolioGet();