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
Solved! Go to Solution.
Views
Replies
Total Likes
Also, here's an example repo that accesses AAM APIs with python's requests library. Hope this helps point you in the right direction!
Views
Replies
Total Likes
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
Views
Replies
Total Likes
Also, here's an example repo that accesses AAM APIs with python's requests library. Hope this helps point you in the right direction!
Views
Replies
Total Likes
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.
Views
Likes
Replies