'Why does Amazon Advertising report API return a .bin instead of .json
I am requesting a Sponsered Product report from Amazon's Advertising API. When I send the POST i receive the reportID. I enter the reportID as part of the GET call's path to retrieve the document. I observe the response of type 20, however the content of the response is binary code(I think).
The documentation has indicated I should receive a JSON response but that is not what I am getting back. How do i return the document in the appropriate format?
I have included an image for reference of the response.
Solution 1:[1]
As @tector says, you need to unzip this file. Amazon's documentation is pretty poor and is often mixed with updated and outdated information.
GET /v2/reports/{reportId} does return a JSON response that contains a download URI when the status is 'SUCCESS'.
GET /v2/reports/{reportId}/download, when successful, responds with a 307 redirect to the file that is generated. You are seeing a binary response because it is a file.
In python you would handle the response like this:
import requests
import gzip
import io
headers = {
"Authorization": f"Bearer {access_code}",
"Amazon-Advertising-API-Scope": profile_id,
"Amazon-Advertising-API-ClientId": client_id
}
response = requests.get(location, headers=headers, allow_redirects=True)
if response.ok:
compressed_file = io.BytesIO(response.content)
decompressed_file = gzip.GzipFile(fileobj=compressed_file) # you can shorten the past 2 lines
final = pd.read_json(decompressed_file) # put contents into pandas dataframe
Solution 2:[2]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | tector |


