Expand my Community achievements bar.

Join us January 15th for an AMA with Champion Achaia Walton, who will be talking about her article on Event-Based Reporting and Measuring Content Groups!
SOLVED

Adobe Analytics API access for multiple integrations

Avatar

Level 1
Hi,
We have a SaaS based system that has a number of data connectors to enable our customers to connect their systems to the platform to gain insights from their Website analytics, digital marketing and ecomm data.
 
We recently had a customer approach us that wants a connection to Adobe Analytics.
 
After reviewing documentation on the site and setting up the needed accounts we are struggling to understand how we can make a reusable data connector for the Adobe Analytics platform.
 
The documentation seems to indicate it would be tightly coupled with a customers Adobe Analytics account.
 
Does anyone have any experience or clarity on this please?
 
Thanks
1 Accepted Solution

Avatar

Correct answer by
Adobe Champion

Yes, Adobe Analytics can support a flow similar to what you're describing through its OAuth 2.0 Server-to-Server authentication and JWT-based integration although JWT is getting deprecated starting next year.

 

Upon successful onboarding and token exchange, Adobe issues Access Tokens that allow access to specific APIs. These tokens can be scoped to ensure that only necessary resources are accessed. Adobe Analytics allows you to dynamically specify report suites (analogous to “properties”) when querying data. This can be done using an API request where the desired report suite is specified as part of the request. Sharing sample Python code in which you can see that an access code is first generated and then shared to retrieve data from Adobe Admin.

 

import logging
import requests
from datetime import datetime, timedelta, time

logging.basicConfig(level="INFO")
logger = logging.getLogger()

# OAuth and API configuration details (replace with your org specific data)
config = {
    "client_id": "your_client_id",
    "client_secret": "your_client_secret",
    "scopes": "openid,AdobeID,additional_info.projectedProductContext",
    "token_url": "https://ims-na1.adobelogin.com/ims/token/v3",
    "company_id": "your_company_id",
    "api_base_url": "https://analytics.adobe.io/api/"
}

# Get timestamps for yesterday
yesterday = datetime.now() - timedelta(days=1)
start_date_str = datetime.combine(yesterday, time.min).strftime("%Y-%m-%dT%H:%M:%S-07")
end_date_str = datetime.combine(yesterday, time.max).strftime("%Y-%m-%dT%H:%M:%S-07")

def get_access_token_oauth(config):
    """Fetches an OAuth access token using the client credentials method."""
    post_body = {
        "grant_type": "client_credentials",
        "client_id": config["client_id"],
        "client_secret": config["client_secret"],
        "scope": config["scopes"]
    }

    response = requests.post(config["token_url"], data=post_body)
    response.raise_for_status()
    return response.json()["access_token"]

def get_admin_logs(config, access_token, start_date, end_date):
    """Fetches admin usage logs for the specified date range."""
    url = f"{config['api_base_url']}{config['company_id']}/auditlogs/usage"
    querystring = {
        "startDate": start_date,
        "endDate": end_date,
        "limit": "1000"
    }

    headers = {
        "x-api-key": config["client_id"],
        "Authorization": f"Bearer {access_token}",
        "Accept": "application/json"
    }

    response = requests.get(url, headers=headers, params=querystring)
    response.raise_for_status()
    return response.json()

# Fetch the access token
access_token = get_access_token_oauth(config)
logger.info(f"Access token retrieved successfully.")

# Retrieve admin logs
logs = get_admin_logs(config, access_token, start_date_str, end_date_str)
logger.info(f"Retrieved {len(logs)} logs.")

 

Hope this helps! 

View solution in original post

3 Replies

Avatar

Adobe Champion

Hey @CamdenDe ,

I am assuming your system in question does not have a built-in Adobe Analytics connector in place? Does it allow custom API integrations? If so, you can create a project in Adobe Developer console and link the system using OAuth Server to Server authentication. Is this what you are trying to explore?

 

Best,

Isha

Avatar

Level 1

Hi Isha,

 

We have created system that integrates with the like of GA, LinkedIn, Facebook etc. 

 

The approach we have with these is that a customer signs up and then connects to the systems they want. They follow an oauth onboarding flow for how the system in questions needs it supported, then at the end of us receiving the needed access tokens a customer would then select the property they want us to extract data for. 

 

Does Adobe Analytics support this type of flow as well? I cannot tell via the docs.


Cheers

Mark

Avatar

Correct answer by
Adobe Champion

Yes, Adobe Analytics can support a flow similar to what you're describing through its OAuth 2.0 Server-to-Server authentication and JWT-based integration although JWT is getting deprecated starting next year.

 

Upon successful onboarding and token exchange, Adobe issues Access Tokens that allow access to specific APIs. These tokens can be scoped to ensure that only necessary resources are accessed. Adobe Analytics allows you to dynamically specify report suites (analogous to “properties”) when querying data. This can be done using an API request where the desired report suite is specified as part of the request. Sharing sample Python code in which you can see that an access code is first generated and then shared to retrieve data from Adobe Admin.

 

import logging
import requests
from datetime import datetime, timedelta, time

logging.basicConfig(level="INFO")
logger = logging.getLogger()

# OAuth and API configuration details (replace with your org specific data)
config = {
    "client_id": "your_client_id",
    "client_secret": "your_client_secret",
    "scopes": "openid,AdobeID,additional_info.projectedProductContext",
    "token_url": "https://ims-na1.adobelogin.com/ims/token/v3",
    "company_id": "your_company_id",
    "api_base_url": "https://analytics.adobe.io/api/"
}

# Get timestamps for yesterday
yesterday = datetime.now() - timedelta(days=1)
start_date_str = datetime.combine(yesterday, time.min).strftime("%Y-%m-%dT%H:%M:%S-07")
end_date_str = datetime.combine(yesterday, time.max).strftime("%Y-%m-%dT%H:%M:%S-07")

def get_access_token_oauth(config):
    """Fetches an OAuth access token using the client credentials method."""
    post_body = {
        "grant_type": "client_credentials",
        "client_id": config["client_id"],
        "client_secret": config["client_secret"],
        "scope": config["scopes"]
    }

    response = requests.post(config["token_url"], data=post_body)
    response.raise_for_status()
    return response.json()["access_token"]

def get_admin_logs(config, access_token, start_date, end_date):
    """Fetches admin usage logs for the specified date range."""
    url = f"{config['api_base_url']}{config['company_id']}/auditlogs/usage"
    querystring = {
        "startDate": start_date,
        "endDate": end_date,
        "limit": "1000"
    }

    headers = {
        "x-api-key": config["client_id"],
        "Authorization": f"Bearer {access_token}",
        "Accept": "application/json"
    }

    response = requests.get(url, headers=headers, params=querystring)
    response.raise_for_status()
    return response.json()

# Fetch the access token
access_token = get_access_token_oauth(config)
logger.info(f"Access token retrieved successfully.")

# Retrieve admin logs
logs = get_admin_logs(config, access_token, start_date_str, end_date_str)
logger.info(f"Retrieved {len(logs)} logs.")

 

Hope this helps!