Accessing AAM Rest API via Python | Community
Skip to main content
New Participant
March 25, 2019
Solved

Accessing AAM Rest API via Python

  • March 25, 2019
  • 3 replies
  • 6026 views

Hi everyone,

Sabine from the Daily Telegraph here

Has anybody ever succeed in accessing the REST API with the python request library?

I have managed to get a token but I get a 403 error (logged out) with any request I attempt - however the token generated works fine with Postman/AAM Rest tool, so I'm a bit clueless as to why it doesn't work...

Looking forward to hearing about your experiences with the API!

Thanks,

Sabine

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Dylan_Kario

Also, here's an example repo that accesses AAM APIs with python's requests library. Hope this helps point you in the right direction!

audiencemanager-api-lab/aam.py at exercise-7 · Adobe-Marketing-Cloud/audiencemanager-api-lab · GitHub

3 replies

New Participant
July 18, 2019

Hi sabineg26801730,

I wrote this and have used it successfully in Python 3:

# Import packages

import os

import base64 as base64

import requests as requests

# Load your aam credentials (must be aam credentials, not marketing cloud credentials)

# credentials include clientID, clientSecret, username, password

aam_credentials = json.load(open('aam_credentials.json', 'r'))

# Get AAM API Token.

def getToken(clientID,clientSecret,username,password):

    oauth_request = "https://api.demdex.com/oauth/token"

    combi =  clientID+':'+clientSecret

    b64combi = base64.b64encode(combi.encode())

    base64IDSecret = b64combi.decode()

    header = {'Authorization' : 'Basic '+base64IDSecret,'Content-Type': 'application/x-www-form-urlencoded'}

    body = {'grant_type':'password','username':username,'password':password}

    audience_request = requests.post(oauth_request,headers=header,data=body)

    token = audience_request.json()['access_token']

    return token

token = getToken(clientID = aam_credentials['clientID'],

                             clientSecret = aam_credentials['clientSecret'],

                             username = aam_credentials['username'],

                             password = aam_credentials['password'])

You'll want to use that token in your other API requests until it expires, then generate a new one when your session expires.

Dylan_KarioAccepted solution
Employee
April 12, 2019

Also, here's an example repo that accesses AAM APIs with python's requests library. Hope this helps point you in the right direction!

audiencemanager-api-lab/aam.py at exercise-7 · Adobe-Marketing-Cloud/audiencemanager-api-lab · GitHub

Employee
April 12, 2019

Hi sabineg26801730,

Thanks for your question! Dylan from Audience Manager's engineering team here. Sorry to hear you've been having trouble accessing the AAM APIs with python & the requests library. Could you please share the exact API call you're making from python along with all headers?

Thanks,

Dylan