-
-
Save dbrent-amazon/ca396a63c1670ee0ec83aad26b0ce55b to your computer and use it in GitHub Desktop.
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. | |
$ export AUTH="MY_ACCESS_TOKEN" | |
1) Request the report: | |
$ curl \ | |
-X POST \ | |
-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"}' \ | |
https://advertising-api-test.amazon.com/v1/keywords/report | |
Response: | |
{ | |
"reportId":"amzn1.clicksAPI.v1.m1.580149D6.c7aa92c1-ca5b-435d-bb8b-51cb26ad5731", | |
"recordType":"keyword", | |
"status":"IN_PROGRESS", | |
"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" \ | |
https://advertising-api-test.amazon.com/v1/reports/amzn1.clicksAPI.v1.m1.580149D6.c7aa92c1-ca5b-435d-bb8b-51cb26ad5731 | |
Response: | |
{ | |
"reportId":"amzn1.clicksAPI.v1.m1.580149D6.c7aa92c1-ca5b-435d-bb8b-51cb26ad5731", | |
"status":"SUCCESS", | |
"statusDetails":"Report has been generated successfully. Pending publish to S3.", | |
"location":"https://advertising-api-test.amazon.com/v1/reports/amzn1.clicksAPI.v1.m1.580149D6.c7aa92c1-ca5b-435d-bb8b-51cb26ad5731/download", | |
"fileSize":236 | |
} | |
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" \ | |
https://advertising-api-test.amazon.com/v1/reports/amzn1.clicksAPI.v1.m1.580149D6.c7aa92c1-ca5b-435d-bb8b-51cb26ad5731/download | |
Response: | |
< HTTP/1.1 307 Temporary Redirect | |
< Date: Fri, 14 Oct 2016 21:17:49 GMT | |
< Server: Apache-Coyote/1.1 | |
< Location: https://sandboxreports.s3.amazonaws.com/amzn1.clicksAPI.v1.m1.580149D6.c7aa92c1-ca5b-435d-bb8b-51cb26ad5731?AWSAccessKeyId=AKIAIKLHNT32USZOWVRA&Expires=1476479900&Signature=I%2F2Gd%2B8TbcPbXbBUM6ix%2BSVP3qA%3D | |
< 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 "https://sandboxreports.s3.amazonaws.com/amzn1.clicksAPI.v1.m1.580149D6.c7aa92c1-ca5b-435d-bb8b-51cb26ad5731?AWSAccessKeyId=AKIAIKLHNT32USZOWVRA&Expires=1476479900&Signature=I%2F2Gd%2B8TbcPbXbBUM6ix%2BSVP3qA%3D" | |
5) Profit: | |
$ less /tmp/report.json.gz |
@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.
Hi @dbrent-amazon,
Have you experienced having different response between linux and windows?
I have a script that works perfectly ok but when I run it in a google cloud vm, it does not return the file location.
Hi!
After
curl -v
-H "Authorization: bearer $AUTH"
-H "Amazon-Advertising-API-Scope: ABC1234567890"
https://advertising-api-test.amazon.com/v1/reports/amzn1.clicksAPI.v1.m1.580149D6.c7aa92c1-ca5b-435d-bb8b-51cb26ad5731/download
I don't get a 307 redirect..I get a 401 HTTP 401 Unauthorized even though the actual token worked for previous requests i.e. to get
"reportId","status","statusDetails", "location","fileSize": 22
If I do the same request form postman, I get a 200 with junk data in body and not a 307 redirect
Does Amazon Advertising provide web-hooks for report downloading? Actually, it takes time for some reports to be created so I have to request multiple times to get the download URL. Is there any way around for it? Kindly share your thoughts. Thanks
Hi, I'm having a problem at this point:
$ curl -v
-H "Authorization: bearer $AUTH"
-H "Amazon-Advertising-API-Scope: ABC1234567890"
https://advertising-api-test.amazon.com/v1/reports/amzn1.clicksAPI.v1.m1.580149D6.c7aa92c1-ca5b-435d-bb8b-51cb26ad5731/download
When I make my request I get a response body that looks like this: "only one auth mechanism allowed; only the X-Amz-Algorithm query parameter…”
Does anyone know what is going on? Looks like the request is getting 2 authorization, but I'm only using the bearer Auth and the amazon-advertisign-API-scope
Hi Everyone,
I would like to download report like this
curl -o /tmp/report.json.gz "https://-------------------b26ad5731/download"
How to setup curl -o in php. I am newbie
Please help me
thanks
@lucarigo did you manage to resolve your issue with "only one auth mechanism allowed; only the X-Amz-Algorithm query parameter…” as I seem to be getting the same issue when trying to download the report.
Hi Everyone,
Is there any way to get the total spending and total sales of the campaign without generating a report? Reports usually take a lot of time to generate and process.
Thanks
I'm also dealing with the same trouble as @garybunofsky, Did you find the solution?