Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Note that this is sandbox. If you have not registered profiles in sandbox you
will need to do so prior to making these calls. You will also need at least
one campaign, ad group, and keyword before you see anything in the report.
While in sandbox, we will return “dummy” data so that you can see how an actual
report would look.
To make it look nicer, I always export my access token prior to making calls.
You could do the same for API-Scope (profile Id) if you wish. Make sure to use
quotes around the access token if it isn’t URL encoded. It has a | (pipe)
symbol and your shell won’t like it.
1) Request the report:
$ curl \
-H "Content-Type: application/json" \
-H "Authorization: bearer $AUTH" \
-H "Amazon-Advertising-API-Scope: ABC1234567890" \
-d '{"reportDate": "20161010", "campaignType": "sponsoredProducts", "metrics": "impressions,clicks,cost", "segment": "query"}' \
"statusDetails":"Report is being generated."
2) Get the report (actually getting the location for downloading):
$ curl \
-H "Authorization: bearer $AUTH" \
-H "Amazon-Advertising-API-Scope: ABC1234567890" \
"statusDetails":"Report has been generated successfully. Pending publish to S3.",
3) Get the download location to S3. This is returned in the header. The file
is also gzipped. Notice the use of the -v flag so CURL will show headers.
$ curl -v \
-H "Authorization: bearer $AUTH" \
-H "Amazon-Advertising-API-Scope: ABC1234567890" \
< HTTP/1.1 307 Temporary Redirect
< Date: Fri, 14 Oct 2016 21:17:49 GMT
< Server: Apache-Coyote/1.1
< Location:
< x-amz-request-id: 067KMA80XJHXHQ1P37SA
< Content-Length: 0
< Vary: Accept-Encoding,User-Agent
4) “Location” is the S3 location where the report can be downloaded. You
don’t have to send authorization headers to get this. You can get it just
by visiting the URL. It will expire very quickly so be sure you get it ASAP.
You will probably need to put quotes around it as the URL contains characters
such as & that the shell will interpret as you trying to background the process,
which we don’t want.
$ curl -o /tmp/report.json.gz ""
5) Profit:
$ less /tmp/report.json.gz

This comment has been minimized.

Copy link

garybunofsky commented Jun 13, 2018

Hey @dbrent-amazon. Thanks you for this gist. It's helped me quite a bit already. You seem to be pretty familiar with the Amazon Advertising API. I was hoping that you could help me, as I've searched high and low for clarification on my current issue but haven't had any luck.

My goal is to get current campaigns through the Amazon Advertising API so that I can generate reports. I've implemented LWA, and I'm having trouble getting profile data. I need to get profile data so I can pass the Amazon-Advertising-API-Scope in the header of subsequent requests.

When I make a GET request to I receive a response, which leads me to believe that my Authorization header is passed properly. However the response is an empty array. I would expect some type of profile to be in the array, as there are currently campaigns running under this account.

Do I have to create a profile for this account in order to view current campaigns? Is it possible to get the data of current campaigns with the Advertising API? Any help would be much appreciated


This comment has been minimized.

Copy link

Keita-N commented Jan 16, 2019

I'm also dealing with the same trouble as @garybunofsky, Did you find the solution?


This comment has been minimized.

Copy link
Owner Author

dbrent-amazon commented May 1, 2019

@garybunofsky and @Keita-N, empty profile list is a completely separate issue from reporting. You should open a Jira Service Desk ticket for that issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.