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.

The type is to be prepended to the the token, separated by a single space.

    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.

Example of Getting and Setting Authorization Header

    <?php

        // Include Request and Response classes

        // Login
        $url = 'https://api.exoclick.com/v1/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 token details
            $token = $response->getBodyDecoded();

            // Get Campaigns
            $url = 'https://api.exoclick.com/v1/campaigns';

            // Create a new Request object
            $request = new Request($url, 'GET');

            // Set the Authorization Header
            $request->setAuthorizationHeader($token->type, $token->token);

            // Send the request
            $request->send();

            // Get the Response object
            $response = $request->getResponse();

            if($response->getStatusCode() == 200) {

                // Retrieve the campaigns
                $campaigns = $response->getBodyDecoded();

                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();
        }
    ?>