2

I am working on a sandbox environment and I am trying to download the report based on the https://advertising.amazon.com/API/docs/v2/reference/reports The issue is that the report which is downloaded is empty. Doesn't contain any data inside. How do we download the report from amazon advertising api?

I follow this steps as described: https://gist.github.com/dbrent-amazon/ca396a63c1670ee0ec83aad26b0ce55b

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
cc89
  • 21
  • 1
  • 4

1 Answers1

5

here's a script that works for me using python and requests, make sure to:

  1. create a campaign, adGroupd and keywords
  2. create reports with the right metrics
  3. make sure you have actual data to view in the report
  4. make sure reportDate is correct
import requests

version = 'v2'
advertise = 'sp'

headers = {
    "Authorization": f"Bearer {token.access}",
    "Amazon-Advertising-API-ClientId": AmazonSecurityProfile.ClientID,
    "Content-Type": "application/json",
}

class urls:
    class api:
        test = 'https://advertising-api-test.amazon.com'

# create report
recordType = "keywords"
r = requests.post(
    f'{urls.api.test}/{version}/{advertise}/{recordType}/report',
    json={
      # "campaignType": "sponsoredProducts",
      "segment": "query",
      "reportDate": '20201025',  #YYYYMMDD
      "metrics": ",".join([
          "campaignName",
          "campaignId",
          "campaignStatus",
          "campaignBudget",
          "clicks",
          "cost",
          "attributedConversions1d",
          "attributedConversions7d",
          "attributedConversions1dSameSKU",
          "attributedConversions7dSameSKU",
          "attributedUnitsOrdered1d",
          "attributedUnitsOrdered7d",
          "attributedSales1d",
          "attributedSales7d",
          "attributedSales1dSameSKU",
          "attributedSales7dSameSKU",
          "attributedUnitsOrdered1dSameSKU",
          "attributedUnitsOrdered7dSameSKU",
          "adGroupName",
          "adGroupId",
          "keywordText",
          "keywordId",
          "matchType",
          "impressions",
      ]),
    },
    headers=headers,
)
r.raise_for_status()
r = r.json()
print(r)
reportId = r["reportId"]

while r['status'] == 'IN_PROGRESS':
    r = requests.get(
        f'{urls.api.test}/{version}/reports/{reportId}',
        headers=headers,
    )
    r = r.json()
    print(r)

assert r['status'] == 'SUCCESS'

r = requests.get(
    r["location"],
    headers=headers,
)
print(r)
yonadav bar ilan
  • 550
  • 6
  • 10