This may be a novice concern, but I hope you can help me.
I always get FATAL processing status every time I run the script. I follow the same manner as how the python-amazon-sp-api test case code create_report() request in their test file: https://github.com/saleweaver/python-amazon-sp-api/blob/master/tests/api/reports/test_reports.py image
And I also followed this: https://www.youtube.com/watch?v=tT22lCVguCE&t=276s
I am stuck on the same issue. Please help me.
Here is my code
import csv
import json
import time
import pandas as pd
import requests
import seaborn as sns
from sp_api.api import Reports, Sales
from sp_api.base.marketplaces import Marketplaces
from sp_api.base.reportTypes import ReportType
from sp_api.base.processing_status import ProcessingStatus
from keys import CLIENT_CONFIG
DAYS_PAST = 7
import datetime as dt
if __name__ == '__main__':
report_type = ReportType.GET_VENDOR_SALES_REPORT #GET_VENDOR_INVENTORY_REPORT #
res = Reports(credentials=CLIENT_CONFIG, marketplace=Marketplaces.US)
date_start_time = (dt.datetime.utcnow() - dt.timedelta(days=DAYS_PAST)).isoformat()
date_end_time = (dt.datetime.utcnow() - dt.timedelta(days=DAYS_PAST)).isoformat()
print(f"date start time: {date_start_time}")
print(f"date end time: {date_end_time}")
data = res.create_report(reportType=report_type, reportPeriod='DAY', distributorView='Manufacturing', sellingProgram='RETAIL', dataStartTime=date_start_time, dataEndTime=date_end_time)
print(f"created report data: {data}")
report = data.payload
print(f"report: {report}")
report_id = report['reportId']
print(f"report id: {report_id}")
time.sleep(60)
try:
res = Reports(credentials=CLIENT_CONFIG, marketplace=Marketplaces.CA)
data = res.get_report(report_id)
except Exception as e:
print(f"Err: {e}")
# print(f"Actual response: {res.Reports}")
print(f"Got report data: {data}")
# print(res.status)
time.sleep(60)
while data.payload.get('processingStatus') not in [ProcessingStatus.DONE, ProcessingStatus.FATAL, ProcessingStatus.CANCELLED]:
print(f"DATA PAYLOAD: {data.payload}")
print('Sleeping...')
data = res.get_report(report_id)
time.sleep(60)
print(f"data: {data}")
print(f"processing status: {data.payload.get('processingStatus')}")
if data.payload.get('processingStatus') in [ProcessingStatus.FATAL, ProcessingStatus.CANCELLED]:
print("Report failed!")
report_data = data.payload
else:
print("Success:")
print(data.payload)
report_data = res.get_report_document(data.payload['reportDocumentId'])
print(f"Document: {report_data}")
print(report_data.payload)
keys.py
CLIENT_CONFIG = {
"refresh_token": "Atzr|Iw*****",
"lwa_app_id": "amzn1.application-******",
"lwa_client_secret": "4******",
"aws_access_key": "AK******",
"aws_secret_key": "h2*****",
"role_arn": "arn:aws:iam::******:role/******",
}
Here is the result when running the script:
date start time: 2022-11-07T12:57:40.403596
date end time: 2022-11-07T12:57:40.403596
created report data: {'errors': None,
'headers': {'Date': 'Mon, 14 Nov 2022 12:57:44 GMT', 'Content-Type': 'application/json', 'Content-Length': '26', 'Connection': 'keep-alive', 'x-amzn-RequestId': '34ac6f48-47dc-4a94-b848-a53a1c2886f3', 'x-amz-apigw-id': 'bl4zQHMkIAMFYbA=', 'X-Amzn-Trace-Id': 'Root=1-63723b47-749629b0664ad0c36447ebe1'},
'next_token': None,
'pagination': None,
'payload': {'reportId': '60454019310'},
'rate_limit': None}
report: {'reportId': '60454019310'}
report id: 60454019310
Got report data: {'errors': None,
'headers': {'Date': 'Mon, 14 Nov 2022 12:58:45 GMT', 'Content-Type': 'application/json', 'Content-Length': '451', 'Connection': 'keep-alive', 'x-amzn-RequestId': '7082b7da-3e8e-44f3-a5fe-f52a85874a42', 'x-amzn-RateLimit-Limit': '2.0', 'x-amz-apigw-id': 'bl484EFZIAMFwcg=', 'X-Amzn-Trace-Id': 'Root=1-63723b85-0e2c014c5a8134910c211d13'},
'next_token': None,
'pagination': None,
'payload': {'createdTime': '2022-11-14T12:57:43+00:00',
'dataEndTime': '2022-11-07T12:57:40+00:00',
'dataStartTime': '2022-11-07T12:57:40+00:00',
'marketplaceIds': ['ATVPDKIKX0DER'],
'processingEndTime': '2022-11-14T12:58:05+00:00',
'processingStartTime': '2022-11-14T12:57:51+00:00',
'processingStatus': 'FATAL',
'reportDocumentId': 'amzn1.spdoc.1.4.na.4c6fb960-497b-469d-8890-65dce9be0d68.T2JOIFWFNF5EAZ.43400',
'reportId': '60454019310',
'reportType': 'GET_VENDOR_SALES_REPORT'},
'rate_limit': '2.0'}