Reports API v2020-09-04 Use Case Guide
How to enable sellers to get reports from Amazon that help them manage their selling business.
API Version: 2020-09-04
What is the Reports API?
Effective June 27, 2023, the Selling Partner API for Reports v2020-09-04 will no longer be available and all calls to it will fail. Integrations that rely on the Reports API must migrate to Reports v2021-06-30 to avoid service disruption.
Terminology
-
Cipher block chaining. Cipher block chaining is an algorithm that uses a block cipher to provide information security such as confidentiality or authenticity. This algorithm uses an initialization vector and a key to encrypt the data.
-
Amazon S3 presigned URL. A URL for an S3 bucket from which you can download an object without AWS security credentials or permissions. In some cases the object may be compressed, in which case
compressionAlgorithm
is returned in addition to the URL. The URL expires after 5 minutes.
Tutorial: Request and retrieve a report
Here are the high-level steps for requesting a report:
-
Call the
createReport
operation, specifying the type of report and the marketplaces that you are requesting, and any optional parameters that you want.Amazon receives the report request. If the operation is successful, the response includes a
reportId
value. -
Periodically call the
getReport
operation, passing thereportId
value from the previous step, until theprocessingStatus
value in the response indicates that processing has ended. Processing will have ended when theprocessingStatus
equalsCANCELLED
,DONE
orFATAL
. At this point the response includes areportDocumentId
value if there is report data available. -
Call the getReportDocument operation, passing the
reportDocumentId
value from the previous step.Amazon returns a presigned URL for the location of the report document along with the encryption details. In some cases the object may be compressed, in which case
compressionAlgorithm
is returned in addition to the URL. The URL expires after 5 minutes. -
Download and decrypt the report.
Prerequisites
To complete this tutorial, you will need:
-
A report type to request. See reportType values for a list of the available report types.
-
Authorization from the seller for whom you are making calls. See the Selling Partner API Developer Guide for more information.
-
An understanding of client-side encryption using the cipher block chaining (CBC). For definitions, see Terminology.
-
To use the sample code in this guide, a working Java Development Kit (JDK) installation, including the javax.crypto library.
Steps
Step 1. Request a report
Request a report by specifying the report type and marketplaces that you are requesting, and any optional parameters.
- Call the
createReport
operation, passing the following parameters:
Request body:
Name | Description | Required |
---|---|---|
reportOptions | Additional information passed to reports. This varies by report type. Type: | No |
reportType | The report type. For more information, see reportType values. Type: string | Yes |
dataStartTime | The start of a date and time range, in ISO 8601 date time format, used for selecting the data to report. The default is now. The value must be prior to or equal to the current date and time. Not all report types make use of this. Type: string (date-time) | No |
dataEndTime | The end of a date and time range, in ISO 8601 date time format, used for selecting the data to report. The default is now. The value must be prior to or equal to the current date and time. Not all report types make use of this. Type: string (date-time) | No |
marketplaceIds | A list of marketplace identifiers. The report document's contents will contain data for all of the specified marketplaces, unless the report type indicates otherwise. Type: < string > array | Yes |
Request example:
POST https://sellingpartnerapi-na.amazon.com/reports/2020-09-04/reports
{
"reportType": "GET_MERCHANT_LISTINGS_ALL_DATA",
"dataStartTime": "2019-12-10T20:11:24.000Z",
"marketplaceIds": [
"A1PA6795UKMFR9",
"ATVPDKIKX0DER"
]
}
Response
A successful response includes the following property:
Name | Description |
---|---|
reportId | The identifier for the report. This identifier is unique only in combination with a seller ID. Type: string |
Response example:
{
"payload":
{
"reportId": "ID323"
}
}
Step 2. Confirm that report processing has completed
After you call the createReport
operation, Amazon receives the request and begins processing the report. You must then confirm that processing has completed before you continue.
Periodically call the getReport
operation, passing the reportId
value from the previous step, until the processingStatus
value in the response indicates that processing has ended. Processing will have ended when the processingStatus
equals CANCELLED
, DONE
or FATAL
. At this point the response includes a reportDocumentId
value if there is report data available.
Here are the processingStatus
values that confirm that processing has ended:
-
CANCELLED
- The report was cancelled. There are two ways a report can be cancelled: an explicit cancellation request before the report starts processing, or an automatic cancellation if there is no data to return. -
DONE
- The report has completed processing and areportDocumentId
is available. -
FATAL
- The report was stopped due to a fatal error and areportDocumentId
may be present. If present, the report represented by thereportDocumentId
may explain why the report processing ended.
The following processingStatus
values indicate that processing has not ended, and you should continue to call the getReport operation until the operation returns a processingStatus
of CANCELLED
, DONE
or FATAL
.
-
IN_PROGRESS
- The report is being processed. -
IN_QUEUE
- The report has not yet started processing. It may be waiting for anotherIN_PROGRESS
report.
Note: The getReport operation only serves information for on-demand or scheduled report requests that were created within the last 90 days.
Path parameter:
Name | Description | Required |
---|---|---|
reportId | The identifier for the report. This identifier is unique only in combination with a seller ID. Type: string | Yes |
Request example:
GET https://sellingpartnerapi-na.amazon.com/reports/2020-09-04/reports/ID323
Response
A successful response includes the following:
Name | Description | Schema |
---|---|---|
payload | The payload for the getReport operation. | Report |
Response example
{
"payload": {
"reportId": "ID323",
"reportType": "GET_MERCHANT_LISTINGS_ALL_DATA",
"dataStartTime": "2019-12-11T13:47:20.677Z",
"dataEndTime": "2019-12-12T13:47:20.677Z",
"createdTime": "2019-12-10T13:47:20.677Z",
"processingStatus": "DONE",
"processingStartTime": "2019-12-10T13:47:20.677Z",
"processingEndTime": "2019-12-12T13:47:20.677Z",
"reportDocumentId": "DOC-b8b0-4226-b4b9-0ee058ea5760"
}
}
Step 3. Retrieve the report
To retrieve the report, see How to Retrieve a Report.
Tutorial: Schedule and retrieve reports
You can schedule requests for reports so that they are submitted periodically, using the createReportSchedule
operation. Use the period enumeration to specify the time period. To identify which reports can be scheduled, review the reportType values in the Selling Partner API documentation.
Here are the high-level steps for scheduling and retrieving reports:
-
Call the
createReportSchedule
operation to create a schedule for periodically submitting report requests. SpecifyreportType
,marketplaceIds
andperiod
values and any optional parameters. ForreportType
values, see reportType values. Forperiod
values, see period enumeration.Note: If a report schedule with the same report type and marketplace IDs already exists, it will be cancelled and replaced with this one. Otherwise a new report schedule will be created.
-
Periodically call the
getReports
operation using an interval that is similar to the schedule that you configured in the previous step.If a call to the getReports operation succeeds, the response contains an array of report information, including
reportDocumentId
values if report data is available.Note: The getReports operation only serves information for on-demand or scheduled report requests that were created within the last 90 days.
-
For each
reportDocumentId
:-
Call the
getReportDocument
operation, passing thereportDocumentId
value.Amazon returns a presigned URL for the location of the report document along with the encryption details. In some cases the object may be compressed, in which case
compressionAlgorithm
is returned in addition to the URL. The URL expires after 5 minutes. -
Download and decrypt the report.
-
Prerequisites
To complete this tutorial, you will need:
-
A report type to schedule. See reportType values for a list of the available report types.
-
Authorization from the seller for whom you are making calls. See the Selling Partner API Developer Guide for more information.
-
An understanding of client-side encryption using the cipher block chaining (CBC). For definitions, see Terminology.
-
To use the sample code in this guide, a working Java Development Kit (JDK) installation, including the javax.crypto library.
Steps
Step 1: Create a schedule for report requests
Call the createReportSchedule
operation to create a schedule for submitting report requests, specifying the reportType
, markeplaceIds
, and period
values and any optional parameters. See reportType values for a list of the available report types.
- Call the
createReportSchedule
operation and pass the following parameters:
Body parameter:
Name | Description | Required |
---|---|---|
reportType | The report type. Type: string | Yes |
marketplaceIds | A list of marketplace identifiers for the report schedule. Type: < string > array | Yes |
reportOptions | Additional information passed to reports. This varies by report type. Type: | No |
period | One of a set of predefined ISO 8601 periods that specifies how often a report should be created. Type: enum ( | Yes |
nextReportCreationTime | The date and time when the schedule will create its next report, in ISO 8601 date time format. Type: string (date-time) | No |
Request example:
POST https://sellingpartnerapi-na.amazon.com/reports/2020-09-04/schedules
{
"reportType": "GET_XML_BROWSE_TREE_DATA",
"period": "P2D",
"marketplaceIds":["ATVPDKIKX0DER"]
}
Response
A successful response includes the following:
Name | Description | Schema |
---|---|---|
payload | The payload for the createReportSchedule operation. | CreateReportScheduleResult |
Response example:
{
"payload":
{
"reportScheduleId": "ID323"
}
}
Step 2: Periodically retrieve information about the scheduled reports
Periodically call the getReports
operation using an interval that is similar to the schedule that you configured. You'll want to try to time these calls so that they occur after scheduled reports are likely to have been completed.
- Call the
getReports
operation periodically to retrieve information about scheduled reports, passing the following parameters:
Query parameters:
Name | Description | Required |
---|---|---|
reportTypes | A list of report types used to filter reports. When Either Type: < string > array | No |
processingStatuses | A list of processing statuses used to filter reports. Type: < enum ( | No |
marketplaceIds | A list of marketplace identifiers used to filter reports. The reports returned will match at least one of the marketplaces that you specify. Type: < string > array | No |
pageSize | The maximum number of reports to return in a single call. Type: Integer | No |
createdSince | The earliest report creation date and time for reports to include in the response, in ISO 8601 date time format. The default is 90 days ago. Reports are retained for a maximum of 90 days. Type: string (date-time) | No |
createdUntil | The latest report creation date and time for reports to include in the response, in ISO 8601 date time format. The default is now. Type: string (date-time) | No |
nextToken | A string token returned in the response to your previous request. nextToken is returned when the number of results exceeds the specified pageSize value. To get the next page of results, call the getReports operation and include this token as the only parameter. Specifying nextToken with any other parameters will cause the request to fail. Type: string | No |
Request example:
GET https://sellingpartnerapi-na.amazon.com/reports/2020-09-04/reports?reportTypes=GET_XML_BROWSE_TREE_DATA
Response
A successful response includes the following:
Name | Description | Schema |
---|---|---|
payload |
The payload for the getReports operation. |
ReportList |
nextToken |
Returned when the number of results exceeds pageSize. To get the next page of results, call getReports with this token as the only parameter. |
string |
The payload array in the response contains one Report
object (see Report
for each processed report, and each Report object contains the reportDocumentId
.
Note: Information about both on-demand and scheduled reports is returned. To identify scheduled reports, look for the presence of a reportScheduleId
in the Report
object in the response. The reportScheduleId
indicates which schedule submitted this report request.
- For each
reportDocumentId
, save thereportDocumentId
and go to Step 3 to retrieve the report.
Response example:
{
"nextToken": "VGhpcyB0b2tlbiBpcyBvcGFxdWUgYW5kIGludGVudGlvbmFsbHkgb2JmdXNjYXRlZA==",
"payload": [
{
"reportType": "GET_XML_BROWSE_TREE_DATA",
"processingEndTime": "2020-09-23T22:52:59+00:00",
"processingStatus": "DONE",
"marketplaceIds": ["ATVPDKIKX0DER"],
"reportDocumentId": "FOO_eae0a7b7-6c33-4191-ad1a-f31ac1ae0ce3",
"reportId": "ID222",
"dataEndTime": "2020-09-23T22:52:24+00:00",
"createdTime": "2020-09-23T22:52:43+00:00",
"processingStartTime": "2020-09-23T22:52:49+00:00",
"reportScheduleId": "ID323",
"dataStartTime": "2020-09-23T22:37:24+00:00"
}
]
}
Step 3: Retrieve the report
To retrieve a report, see How to Retrieve a Report.
How to Retrieve a Report
Get your report by first getting the information required to retrieve a report document and then downloading and decrypting the report.
Steps
Step 1. Get information required to retrieve the report
Call the getReportDocument operation to get the information required for retrieving a report document's contents. This includes a presigned URL for the report document as well as the information required to decrypt the document's contents. In some cases the object may be compressed, in which case compressionAlgorithm
is returned in addition to the URL. The URL expires after 5 minutes.
- Call the
getReportDocument
operation, passing the following parameter:
Path parameter:
Name | Description | Required |
---|---|---|
reportDocumentId | The identifier for the report document. Type: string | Yes |
Request example:
GET https://sellingpartnerapi-na.amazon.com/reports/2020-09-04/documents/DOC-b8b0-4226-b4b9-0ee058ea5760
Response
A successful response includes the following elements:
Name | Description |
---|---|
reportDocumentId | The identifier for the report document. This identifier is unique only in combination with a seller ID. |
url | A presigned URL for the report document. If Type: string |
encryptionDetails | Encryption details required for decryption of a report document's contents. |
compressionAlgorithm | If the report document contents have been compressed, the compression algorithm used is returned in this property and you must decompress the report when you download. Otherwise, you can download the report directly. Refer to Step 2. Download and decrypt the report in the use case guide, where sample code is provided. Type: enum (CompressionAlgorithm) |
Response example:
{
"payload": {
"reportDocumentId": "DOC-b8b0-4226-b4b9-0ee058ea5760",
"url": "https://d34o8swod1owfl.cloudfront.net/SampleResult%2BKey%3DSample%2BINITVEC%3D58+fa+bf+a7+08+11+95+0f+c1+a8+c6+e0+d5+6f+ae+c8",
"encryptionDetails": {
"standard": "AES",
"initializationVector": "58 fa bf a7 08 11 95 0f c1 a8 c6 e0 d5 6f ae c8",
"key": "Sample"
}
}
}
- Save the
key
,initializationVector
,url
, andcompressionAlgorithm
(optional property) for use in Step 2.
Step 2. Download and decrypt the report
You will need to download and decrypt the report using the information returned in the previous step. The following sample code along with the classes provided in the Selling Partner API Documents Helper can help. You can also use the principles demonstrated in the sample code and in the SP-API Documents Helper code to guide you in building applications in other programming languages.
-
Use the following as inputs for the sample code:
- The
key
,initializationVector
,url
, and optionalcompressionAlgorithm
values from the previous step are arguments for thekey
,initializationVector
,url
, andcompressionAlgorithm
parameters of thedownloadAndDecrypt
method of theDownloadExample
class.
- The
Note: It's the developer's responsibility to always maintain encryption at rest. Unencrypted report content should never be stored on disk, even temporarily, because reports can contain sensitive information. The sample code that we provide demonstrates this principle.
Sample Code (Java)
// DownloadExample.java
import java.io.BufferedReader;
import java.io.IOException;
import com.amazon.spapi.documents.CompressionAlgorithm;
import com.amazon.spapi.documents.DownloadBundle;
import com.amazon.spapi.documents.DownloadHelper;
import com.amazon.spapi.documents.DownloadSpecification;
import com.amazon.spapi.documents.exception.CryptoException;
import com.amazon.spapi.documents.exception.HttpResponseException;
import com.amazon.spapi.documents.exception.MissingCharsetException;
import com.amazon.spapi.documents.impl.AESCryptoStreamFactory;
public class DownloadExample {
final DownloadHelper downloadHelper = new DownloadHelper.Builder().build();
// The key, initializationVector, url, and compressionAlgorithm are obtained from the response to
// the getReportDocument operation.
public void downloadAndDecrypt(String key, String initializationVector, String url, String compressionAlgorithm) {
AESCryptoStreamFactory aesCryptoStreamFactory =
new AESCryptoStreamFactory.Builder(key, initializationVector).build();
DownloadSpecification downloadSpec = new DownloadSpecification.Builder(aesCryptoStreamFactory, url)
.withCompressionAlgorithm(CompressionAlgorithm.fromEquivalent(compressionAlgorithm))
.build();
try (DownloadBundle downloadBundle = downloadHelper.download(downloadSpec)) {
// This example assumes that the downloaded file has a charset in the content type, e.g.
// text/plain; charset=UTF-8
try (BufferedReader reader = downloadBundle.newBufferedReader()) {
String line;
do {
line = reader.readLine();
// Process the decrypted line.
} while (line != null);
}
}
catch (CryptoException | HttpResponseException | IOException | MissingCharsetException e) {
// Handle exception here.
}
}
}
Best practices
Expect changes to reports
Amazon periodically adds new fields and field values to reports. Be sure that any report parsers that you build into your applications can gracefully handle these types of report updates.
Don't rely on document ID structure
You should not rely on the format and structure of document identifiers. The format and structure is subject to change.
Updated about 1 month ago