Data Kioskユースケースガイド
How to use the Data Kiosk API.
APIバージョン:2023-11-15
Data Kiosk APIとは
Data Kiosk用のSelling Partner APIを使用すると、さまざまなスキーマからGraphQLクエリーを送信して、出品パートナーによるビジネスの管理を支援できます。
重要なポイント
- Data Kioskは、
getQuery
オペレーションへのレスポンスでデータドキュメントまたはエラードキュメントを返します。また、クエリーは成功してもデータが返されなかった場合は、ドキュメントを返さないこともあります。- リクエストが処理ステータス
DONE
で正常に処理されると、データドキュメントにはJSONL形式の出力が含まれます。 - 処理ステータスが
FATAL
の失敗したリクエストについては、エラードキュメントにJSON形式のエラーメッセージが含まれます。
- リクエストが処理ステータス
getQuery
オペレーションのレスポンスで、processingStatus
がDONE
で、errorDocumentId
もdataDocumentId
もない場合は、リクエストがデータなしで完了したか、指定された日付範囲にデータがないことを意味します。別のパラメーターを指定してリクエストを再試行してください。- Data Kiosk APIはクエリーのスケジュール設定をサポートしていません。
- Data Kiosk APIは、クエリーのバックロギングをサポートしていません。Data Kioskは、出品パートナーごと、 GraphQLクエリーごとに同時に実行できる非ターミナルクエリーの数を制限しています。
チュートリアル:GraphQLクエリーによるデータのリクエストとフィルタリング
このチュートリアルでは、GraphQLクエリーを使用してデータをリクエストおよびフィルタリングする方法について説明します。
前提条件:
このチュートリアルを完了するには、次のものが必要です。
- リクエストするデータに適したロール。このチュートリアルの例では販売とトラフィックのデータを使用していますが、この場合はブランド分析ロールが必要です。
ステップ1:クエリーリクエストを作成する
クエリーを指定して非同期クエリーリクエストを作成します。クエリーは、スキーマに従った有効な GraphQLクエリーでなければなりません。クエリーの入力パラメーターは必要に応じて変更できます。また、レスポンスフィールドは任意の順序で追加または除外できます。
ボディにクエリーを指定して、createQuery
オペレーションを呼び出します。
ボディのパラメーター
名前 | Type | 説明 | 必須 |
---|---|---|---|
query |
string | The GraphQL query that is compliant with the schema. A query can be at most 8,000 characters after unnecessary whitespace is removed. Refer to the schema to build your query. | はい |
リクエストの例
例1:salesAndTrafficByDate
のクエリーリクエストを作成して、レスポンスでフィールドのサブセットを取得します。
POST https://sellingpartnerapi-na.amazon.com/dataKiosk/2023-11-15/queries
{
"query": "{analytics_salesAndTraffic_2023_11_15{salesAndTrafficByDate(startDate:\"2023-01-01\" endDate:\"2023-10-31\" aggregateBy:DAY marketplaceIds:[\"ATVPDKIKX0DER\"]){endDate marketplaceId startDate traffic{averageOfferCount browserPageViews averageParentItems browserPageViewsB2B browserSessions}sales{averageSalesPerOrderItem{amount currencyCode}averageSalesPerOrderItemB2B{amount currencyCode}averageSellingPrice{amount currencyCode}claimsGranted refundRate unitsOrderedB2B unitsRefunded unitsShipped}}}}"
}
例2:salesAndTrafficByAsin
のクエリーリクエストを作成して、レスポンスでフィールドのサブセットを取得します。
POST https://sellingpartnerapi-na.amazon.com/dataKiosk/2023-11-15/queries
{
"query": "{analytics_salesAndTraffic_2023_11_15{salesAndTrafficByAsin(startDate:\"2023-01-01\" endDate:\"2023-10-31\" aggregateBy:PARENT marketplaceIds:[\"ATVPDKIKX0DER\"]){childAsin endDate marketplaceId parentAsin sales{orderedProductSales{amount currencyCode}totalOrderItems totalOrderItemsB2B}sku startDate traffic{browserPageViews browserPageViewsB2B browserPageViewsPercentage browserPageViewsPercentageB2B browserSessionPercentage unitSessionPercentageB2B unitSessionPercentage}}}}"
}
レスポンス
成功した場合のレスポンスには、以下のプロパティが含まれます。
名前 | Type | 説明 |
---|---|---|
queryId |
string | クエリーの識別子。この識別子は出品者IDと組み合わせた場合にのみ一意となります。 |
レスポンスの例
{
"queryId": "012345678901"
}
ステップ2:クエリー処理が完了したことを確認する
createQuery
オペレーションを呼び出すと、Amazonはそのリクエストを受け取り、クエリーの処理を開始します。続行する前に、処理が完了したことを確認してください。クエリーの処理が完了したことを確認するには、「クエリー処理が完了したことを確認する」を参照してください。
ステップ3:クエリー結果を取得するために必要な情報を取得する
getDocument
オペレーションを呼び出して、クエリー結果のドキュメントの内容を取得するために必要な情報を取得します。これには、ドキュメントの署名付きURLが含まれています。ドキュメントが圧縮されている場合は、Content-Encoding
のヘッダーに圧縮アルゴリズムが示されます。これは、レポートAPIが圧縮に関する情報を提供する方法とは異なるので注意してください。
パスパラメーター
名前 | Type | 説明 | 必須 |
---|---|---|---|
documentId |
string | クエリー結果ドキュメントの識別子。この識別子は出品者IDと組み合わせた場合にのみ一意となります。 | はい |
リクエストの例
GET https://sellingpartnerapi-na.amazon.com/dataKiosk/2023-11-15/documents/DOC-b8b0-4226-b4b9-0ee058ea5760
レスポンス
成功レスポンスには、以下が含まれます。
名前 | Type | 説明 |
---|---|---|
documentId |
string | クエリードキュメントの識別子。この識別子は出品者IDと組み合わせた場合にのみ一意となります。 |
documentUrl |
string | Data Kioskドキュメントを取得するために使用する署名付きURL。このURLは5分後に期限切れになります。Data Kioskドキュメントが圧縮されている場合、Content-Encoding のヘッダーが圧縮アルゴリズムを示します。 |
レスポンスの例
{
"documentId": "DOC-b8b0-4226-b4b9-0ee058ea5760",
"documentUrl": "https://d34o8swod1owfl.cloudfront.net/SampleResult%2BKey%3DSample%2BINITVEC%3D58+fa+bf+a7+08+11+95+0f+c1+a8+c6+e0+d5+6f+ae+c8"
}
次のステップで使用するため、documentUrl
を保存します。
ステップ4:ドキュメントをダウンロードする
ステップ3で返された情報を使用して、クエリードキュメントをダウンロードする必要があります。
以下のサンプルコードは、Data Kioskドキュメントをダウンロードする方法を示しています。前のステップのdocumentUrl
の値を、DownloadExample
クラスのdownload
メソッドのurl
パラメーターの引数として使用します。
注:保管中は必ず暗号化を維持する必要があります。クエリー結果のドキュメントには機密情報が含まれている可能性があるため、暗号化されていないクエリー結果のドキュメントコンテンツは、一時的であってもディスクに保存しないでください。以下のサンプルコードは、この原則を示しています。
// DownloadExample.java
// This example is for use with the Selling Partner API for Data Kiosk, Version: 2023-11-15
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import com.squareup.okhttp.ResponseBody;
/**
* Example that downloads a Data Kiosk document.
*/
public class DownloadExample {
public static void main(String[] args) {
String url = "<URL from the getDocument response>";
DownloadExample obj = new DownloadExample();
try {
obj.download(url);
} catch (IOException e) {
// Handle exceptions here.
e.printStackTrace();
}
}
/**
* Download the document from the given Amazon Simple Storage Service (Amazon S3) URL.
*
* @param url the signed Amazon S3 URL to retrieve the document from.
* @throws IOException when there is an error reading the response.
*/
public void download(String url) throws IOException {
OkHttpClient httpclient = new OkHttpClient();
Request request = new Request.Builder()
.url(url)
.get()
.build();
Response response = httpclient.newCall(request).execute();
if (!response.isSuccessful()) {
System.out.printf("Call to download content was unsuccessful with response code: %d and message: %s%n",
response.code(), response.message());
return;
}
try (ResponseBody responseBody = response.body();
InputStream inputStream = responseBody.byteStream();
// Note: If the Data Kiosk document is compressed, the 'Content-Encoding' header will indicate the
// compression algorithm. Most HTTP clients are capable of automatically decompressing downloaded files
// based on the 'Content-Encoding' header.
// More Information: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding
//
// The OkHttp client will automatically set the "Accept-Encoding" header and respect the
// "Content-Encoding" header, so it is not required to unzip the stream.
// For clients which do not automatically decompress, wrapping the stream in a GZIP stream may be
// required, for example:
// InputStream unzippedInputStream = new GZIPInputStream(inputStream);
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
BufferedReader reader = new BufferedReader(inputStreamReader)) {
String line;
while ((line = reader.readLine()) != null) {
// Process line by line.
System.out.println(line);
}
}
}
}
Updated 23 days ago