NextRoll API for AdRoll

Get Started with AdRoll API – NextRoll API for AdRoll

How to use NextRoll API to retrieve data from AdRoll?

Welcome visitor! Thanks so much for stopping by. Today we are going to set up an AdRoll developer account and eventually make our first AdRoll API call using python.

It might be possible you have no idea What is AdRoll? What do they do? Don’t worry. Will get the above question answered briefly below.

AdRoll is a performance marketing platform that has evolved over the last 10 years using the largest advertiser data co-op in the market. What that means for marketers is that they can reach their audience anywhere on the web and, using AdRoll’s products, help get those customers to make a purchase.

What you are going to get from this article?

  1. You will register as a developer for AdRoll (NextRoll).
    1. You will learn to create Apps under NextRoll (AdRoll API).
  2. You will learn the types of authentication available and ways to generate tokens and credentials.
  3. You will have python code to authenticate and make the first API call.

HEADSup: You will come across NextRoll in this article pretty much along with AdRoll. Wondering why? NextRoll is the parent company of AdRoll. All below processes will be happening under NextRoll. In this article we will use AdRoll to avoid confusion since eventually will be using AdRoll API to retrieve AdRoll data. Now your brain is kind of prepared and it will be easy to grab the knowledge and process we will be learning in this article.

So let’s get started.

1. Register as a Developer:

To make API calls, you’ll need to register as a developer and create an application. To create a developer account go to Create a Developer Account.

Fill out the form which will look like the below screengrab. You also need to verify your newly created account.

If you have already created an account then Sign in. Stay logged in since you need it in the coming steps.

 2. Register an APP:

It is recommended that you create an application for production and one for testing. This allows you to have a separate OAuth 2.0 redirect URI for each of your development environments. It’s easy to maintain and trust me this will avoid future confusion in the first place.

Things to remember is AdRoll API services allow 100 API requests per service per day.

In order to create an application, Go to Create an application, which is your developer account dashboard listing all applications you own or you have access to.

The image attached below is a screengrab of the AdRoll (NextRoll) developer dashboard and this is how it looks when you are just getting started.

Click on “New APP”. You will be asked to give the app name, some description, APIs and call back the URL. Below Screengrab should be similar to what you see on your screen.

Note: The callback URL you should give is “ http://localhost:8000/ “. If you are currently developing an application from your local system and going to complete the process of OAuth authorization through a local machine.

Okay, so let’s move forward and complete the process by clicking on the “Create” button.

Once you’ve registered your application, the AdRoll (NextRoll) screen will be updated with App ID and API keys details. Keep note of this credential as if you are handling your social media password. Very Important: API key is equivalent to client_id and API secret is equivalent to client secret.

We will use the consumer key when making API calls using HTTP Basic Access Authentication and in case of authenticating with OAuth 2.0 will need both key and secret.

3. Authentication:

Now it’s time to generate credentials for your app so that you can use it from the application you are building to authenticate yourself.

Below are two ways of authentication.

A. OAuth 2.0

All API calls are authenticated using OAuth 2.0. For information on how to use OAuth 2.0 see Get Started with OAuth 2.0.

OAuth is a popular standard that allows users to give account access to third-party developers without having to share their passwords.

ENDPOINTS:

Authorization -> https://services.adroll.com/auth/authorize

Token -> https://services.adroll.com/auth/token

Token Lifetime:

Access Token -> Expire 24 hours after they are issued for all supported grant types.

Refresh tokens -> Expire a year after they are issued and after they are used. You’ll receive a new refresh token along with your new access token. Above are the information and knowledge better to have. I have built a python code to help you out with generating tokens you will need for OAuth authentication.

Python code to generate Tokens:

#!/usr/local/bin/python3
 
import requests, json
import subprocess
import sys
import time
 
def get_token(authorize_url,client_id,callback_uri):
    try: 
        authorization_redirect_url = authorize_url + '?response_type=code&client_id=' + client_id + '&redirect_uri=' + callback_uri + '&scope=all'
 
        print("go to the following url on the browser and enter the code from the returned url: ")
        print("---  " + authorization_redirect_url + "  ---")
        authorization_code = input("\ncode: ")
 
        # step I, J - turn the authorization code into a access token, etc
        data = {'grant_type': 'authorization_code', 'code': authorization_code, 'redirect_uri': callback_uri}
        print("\nrequesting access token")
        access_token_response = requests.post(token_url, data=data, verify=False, allow_redirects=False, auth=(client_id, client_secret))
 
        #print("# response # \n ",access_token_response.headers)
        #print("body: ", access_token_response.text)
 
        # we can now use the access_token as much as we want to access protected resources.
        tokens = json.loads(access_token_response.text)
 
        return tokens
    except:
        print("\nProblem in get token function ",sys.exc_info())
 
try:
    authorize_url = "https://services.adroll.com/auth/authorize"
    token_url = "https://services.adroll.com/auth/token"
    callback_uri = "http://localhost:8000/"
    
    client_id = "Replace With client Id you got from above step"
    client_secret = "Replace with Client Secret you got from above step"
 
    tokens = get_token(authorize_url,client_id,callback_uri)
    print("\n Token : ",tokens)
    
    access_token = tokens['access_token']
    print("\n Access token: " + access_token)
    refresh_token = tokens['refresh_token']
    print("Refresh token: " + refresh_token)
 
except:
    print("ERROR -> ",sys.exc_info())
 

Save the above code as “generate_token.py”. When you run this file using the command (python generate_token.py), it’s going to ask you to follow some steps.

1.  Copy the link and paste it into your browser. Give in your AdRoll account credentials.

2.  Authorize the App to access AdRoll:

3.  Get the code and enter it in command line:

All the tokens should be printed in the command line. Especially the Access Token and Refresh Token. The output you see should look similar to the below screengrab.

Worth Giving a Thought: It’s better to create a JSON file to store above cred. Since the access toke is valid only for 24 hours you need to generate the access token again and again. If your are thinking of building python code to generate the access token on expiry using refresh_token then I recommend to store all the above credentials.

B. HTTP Basic Access Authentication

Historically developers have been able to use HTTP Basic Access Authentication to make API calls. This method is deprecated and we recommend using OAuth 2.0.

When using HTTP Basic Access Authentication, use the same email address and password you use to sign in to the dashboard. Please note, don’t use your Developer Site login in API calls as it is separate from a user account.

For all requests, you’ll need to pass your application’s Client ID in the API key query parameter. The API key parameter is always sent in the URL’s query string, regardless of the HTTP method used. The API key parameter should not be included in the body of the request for POST, PUT, or PATCH calls.

4. First API Call:

4.1: Using API Key (Basic Access Authentication):

The Advertisable is a commonly used object in user accounts. Since the Advertisable EID will be used for most API calls, it is recommended to retrieve the Advertisable EID as your first API call.

#!/usr/local/bin/python3
import requests
import json
 
api_key = 'replace with API key'
user_name = 'replace with AdRoll user name'
password = 'replace with AdRoll Password'
 
adroll_auth = (user_name, password)
r = requests.get(
    'https://services.adroll.com/api/v1/organization/get_advertisables?apikey='+api_key,
    auth=adroll_auth
)
print(r.json())

Save the above code as “adroll_api_call_using_api_key.py” and use the command (python adroll_api_call_using_api_key.py). The output will be Advertisable information in JSON format.

4.2 Using Access Token (OAuth2.0 Authentication):

It is always preferred to have a JSON file to store authentication-related credentials like – access token, client id, etc. This way it’s very easy to maintain and update.

#!/usr/local/bin/python3
import requests
import json
import sys
 
def first_api_call(access_token,api_url):
    try:
        api_call_headers = {'Authorization': 'Bearer ' + access_token}
        api_call_response = requests.get(api_url, headers=api_call_headers, verify=False)
        result = api_call_response.text
        return result
    except:
        print("\nProblem in first_api_call function ",sys.exc_info())
 
try:
    access_token = "replace with access token"
    #api_url = "https://services.adroll.com/api/v1/organization/get_advertisables"
    api_url = "https://services.adroll.com/api/v1/organization/get"
    info = first_api_call(access_token,api_url)
    print("\n Info : ",info)
except:
    print("ERROR -> ",sys.exc_info())
    

Save the above code as “adroll_api_call_using_access_token.py” and use the command (python adroll_api_call_using_access_token.py). The output will be Advertisable information in JSON format.

The output should be ->

Congratulation! you have successfully set up an AdRoll developer account and got all the credentials needed to authenticate your application on behalf of the user so that you can make API calls to retrieve data from AdRoll. Hope I was able to make the entire process of Getting Started with AdRoll API simpler.

Here’s the Python logic to AdRoll API in retrieving the AdRoll marketing insight guide. This to help you develop a complete Python code for OAuth Authentication and extracting data from AdRoll. Check out other API Set-Up Guide.

If you have any questions or comments feel free to reach me at.

Checkout out my other API Integration and Coding Solution Guide