Howdy,
I'm trying to connect to Adobe to run some prebaked queries on a schedule to return for my relational database.
When I code up my python script though, I keep getting a combination of errors depending on the time I run my script. One time it can return this...
Error retrieving report data:
{"error_code":"500701", "message":"GRM internal server error"}
Other times it will return this; I am not making changes to my script between runs...
Error retrieving report data:
{"error_code":"403025", "message":"Profile is not valid"}
import sys
import csv
import json
import time
import requests
import jwt
# Set up your API credentials and report suite ID
client_id = 'helloWorld!'
client_secret = 'shhhhhhhhhhh'
technical_account_id = 'stuffandthings@techacct.adobe.com'
org_id = 'thingsandstuff@AdobeOrg'
private_key = 'private.key'
report_suite_id = 'honeybadger'
json_query = 'marketing_channels.json'
# Set up the API endpoint and authentication URL
auth_url = 'https://ims-na1.adobelogin.com/ims/exchange/jwt/'
aud_url = f'https://ims-na1.adobelogin.com/c/{client_id}'
api_url = f'https://analytics.adobe.io/api/{report_suite_id}/reports'
# Load your private key
with open(private_key, 'r') as f:
private_key_data = f.read()
# Set up the JWT payload
jwt_payload = {
'iss': org_id,
'sub': technical_account_id,
'aud': 'https://ims-na1.adobelogin.com/c/' + client_id,
'exp': int(time.time()) + 300,
'iat': int(time.time()),
'https://ims-na1.adobelogin.com/s/ent_analytics_bulk_ingest_sdk': True,
'meta_scopes': ['ent_analytics_bulk_ingest_sdk','read','write','https://analytics.adobe.io/api/honeybadger/write','https://analytics.adobe.io/api/honeybadger/read']
}
# Generate the JWT token
jwt_token = jwt.encode(jwt_payload, private_key_data, algorithm='RS256')
# Exchange the JWT token for an access token
auth_headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Cache-Control': 'no-cache'
}
auth_payload = {
'client_id': client_id,
'client_secret': client_secret,
'jwt_token': jwt_token
}
auth_response = requests.post(auth_url, headers=auth_headers, data=auth_payload)
if auth_response.status_code == 200:
access_token = auth_response.json()['access_token']
print("Access Token is: " + access_token)
else:
print('Error exchanging JWT token for access token:')
print(auth_response.text)
sys.exit()
# Load your query JSON
with open(json_query, 'r') as f:
query = json.load(f)
# Make the API call
headers = {
'Authorization': f'Bearer {access_token}',
'Content-Type': 'application/json',
'Accept': 'application/json',
'x-api-key': client_id,
'x-proxy-global-company-id': org_id
}
response = requests.post(api_url, headers=headers, json=query)
# Process the response data
if response.status_code == 200:
data = response.json()
# Write data to CSV file
with open('report_data.csv', 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
# Write headers
headers = [col['id'] for col in data['columns']]
writer.writerow(headers)
# Write rows
for row in data['rows']:
writer.writerow(row)
print('Data successfully written to report_data.csv')
else:
print('Error retrieving report data:')
print(response.text)
sys.exit()