Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Accessing AAM Rest API via Python

Avatar

Avatar
Level 1
sabineg26801730
Level 1

Likes

0 likes

Total Posts

1 post

Correct Reply

0 solutions
View profile

Avatar
Level 1
sabineg26801730
Level 1

Likes

0 likes

Total Posts

1 post

Correct Reply

0 solutions
View profile
sabineg26801730
Level 1

25-03-2019

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

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Affirm 1
Employee
Dylan_Kario
Employee

Likes

0 likes

Total Posts

3 posts

Correct Reply

1 solution
Top badges earned
Affirm 1
View profile

Avatar
Affirm 1
Employee
Dylan_Kario
Employee

Likes

0 likes

Total Posts

3 posts

Correct Reply

1 solution
Top badges earned
Affirm 1
View profile
Dylan_Kario
Employee

12-04-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 · GitHu...

Answers (2)

Answers (2)

Avatar

Avatar
Validate 1
Level 2
trevor1992
Level 2

Likes

14 likes

Total Posts

8 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Contributor
Shape 1
Boost 5
Boost 3
View profile

Avatar
Validate 1
Level 2
trevor1992
Level 2

Likes

14 likes

Total Posts

8 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Contributor
Shape 1
Boost 5
Boost 3
View profile
trevor1992
Level 2

18-07-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.

Avatar

Avatar
Affirm 1
Employee
Dylan_Kario
Employee

Likes

0 likes

Total Posts

3 posts

Correct Reply

1 solution
Top badges earned
Affirm 1
View profile

Avatar
Affirm 1
Employee
Dylan_Kario
Employee

Likes

0 likes

Total Posts

3 posts

Correct Reply

1 solution
Top badges earned
Affirm 1
View profile
Dylan_Kario
Employee

12-04-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