Reports

class ad_api.api.sb.Reports(account='default', marketplace: Marketplaces = Marketplaces.EU, credentials=None, proxies=None, verify=True, timeout=None, debug=False, access_token=None)

Sponsored Brand Reports

Documentation: https://advertising.amazon.com/API/docs/en-us/reference/sponsored-brands/2/reports

post_report(self, recordType, **kwargs) ApiResponse:

Requests a Sponsored Brands report.

Request the creation of a performance report for all entities of a single type which have performance data to report. Record types can be: campaigns, adGroups, and keywords.

Keyword Args
path recordType (string): The type of entity for which the report should be generated. Supported record types: campaigns, adGroups, and keywords
Request body
segment (string): [required] Dimension on which to segment the report. Available values : placement, query
reportDate (string): [required] The date for which to retrieve the performance report in YYYYMMDD format. The time zone is specified by the profile used to request the report. If this date is today, then the performance report may contain partial information. Reports are not available for data older than 60 days.
metrics (string) [optional] A comma-separated list of the metrics to be included in the report.
creativeType (string) [optional] Set to video to request a Sponsored Brands video report.
Returns:

ApiResponse

### Example python

from ad_api.api.sb.reports import Reports

with open("campaigns.json", "r", encoding="utf-8") as f:
    data = f.read()

# Available values : campaigns, adGroups, targets and keywords
record_type = 'campaigns'

result = Reports().post_report(
    recordType=record_type,
    body=data
)

payload = result.payload
report_id = payload.get('reportId')

### Example json

Open this json file to see the result:

{
  "segment": "placement",
  "reportDate": "20211101",
  "metrics": "campaignName,campaignId,campaignStatus,campaignBudget,campaignBudgetType,campaignRuleBasedBudget"
}
get_report(self, reportId, **kwargs) ApiResponse:

Gets a previously requested report specified by identifier.

Keyword Args
path reportId (string): [required] The report identifier.
Request body
creativeType (string): [optional] Set to video to retrieve a Sponsored Brands video report.
Returns:

ApiResponse

### Example python

from ad_api.api.sb.reports import Reports

# this report_id is obtained from post_report method
report_id = 'amzn1.clicksAPI.v1.p44551.61549C5E.e4599469-7392-4624-a858-fc1fecdb165c'

result = Reports().get_report(
    reportId=report_id
)

### Result json

{'expiration': 1640736000000,
 'fileSize': 6546,
 'location': 'https://advertising-api-eu.amazon.com/v1/reports/amzn1.clicksAPI.v1.p44551.61549C5E.e4599469-7392-4624-a858-fc1fecdb165c/download',
 'reportId': 'amzn1.clicksAPI.v1.p44551.61549C5E.e4599469-7392-4624-a858-fc1fecdb165c',
 'status': 'SUCCESS',
 'statusDetails': 'Report has been successfully generated.'}}
download_report(self, **kwargs) ApiResponse:

Downloads the report previously get report specified by location (this is not part of the official Amazon Advertising API, is a helper method to download the report). Take in mind that a direct download of location returned in get_report will return 401 - Unauthorized.

kwarg parameter file if not provided will take the default amazon name from path download (add a path with slash / if you want a specific folder, do not add extension as the return will provide the right extension based on format choosed if needed)

kwarg parameter format if not provided a format will return a url to download the report (this url has a expiration time)

Keyword Args
url (string): [required] The location obatined from get_report.
file (string): [optional] The path to save the file if mode is download json, zip or gzip.
format (string): [optional] The mode to download the report: data (list), raw, url, json, zip, gzip. Default (url)
Returns:

ApiResponse

### Example python

from ad_api.api.sb.reports import Reports

# the url=location is obtained from get_report method need to in stay 'status': 'SUCCESS' if is 'IN_PROGRESS' the report cannot be downloaded
location = 'https://advertising-api-eu.amazon.com/v1/reports/amzn1.clicksAPI.v1.p44551.61549C5E.e4599469-7392-4624-a858-fc1fecdb165c/download'

# path = '/Users/your-profile/Downloads/report_name'
# mode = "data"  # "data (list), raw, url, json, zip, gzip default is url"

result = Reports().download_report(
    url=location,
    # file=path,
    # format=mode
)