チュートリアル:Selling Partner APIエンドポイントをテストする
サンドボックスを使用すると、本番データに影響を与えずにテスト呼び出しをすることができます。
Selling Partner API (SP-API) provides sandbox environments where you can test the SP-API endpoints without affecting production data. You can direct calls to the SP-API sandbox endpoints to make static requests that return mock responses. By using the sandbox, you can practice the steps required to make a call, gain an understanding of the request and response formats, practice validating application credentials, and play with API endpoints without impacting production data.
チュートリアル
次のチュートリアルでは、必要なアクセストークンを生成し、SP-API サンドボックスエンドポイントを呼び出す方法を示します。
前提条件
このチュートリアルを完了するには、次の前提条件が必要です。
- A Postman account and workspace. For more information on how to use Postman, refer to Using Postman for Selling Partner API models.
- If you have your own selling partner account, you can self authorize your application to access your account information.
- If you don’t have your own selling partner account, then you must set up a third-party OAuth workflow. With this workflow, third-party sellers and vendors can authorize your application to access their Amazon Selling Partner data.
このプロセス中に、後でアクセストークンと交換できる更新トークンを受け取ります。SP API エンドポイントを呼び出すにはアクセストークンが必要です。
Postman でテストを実行するために必要な変数
Postman で電話をかけるには、まず認証情報を設定する必要があります。ワークスペースには次のグローバル変数が必要です。
client_id
: You must have the client_id to request an LWA access token. The client_id appears after you register your app. To get this value, refer to Viewing your developer information.client_secret
: You must have the client_secret to request an LWA access token. The client_secret appears after you register your app. To get this value, refer to Viewing your developer information.refresh_token
: The LWA refresh token, get this value when the selling partner authorizes your application. If you have your own Selling Partner account, you can self authorize your application to get the refresh token. For more information, refer to Authorizing Selling Partner API applications.base_url_sandbox
: To get Selling Partner API sandbox endpoints for each regions, refer to SP-API sandbox endpoints.
ステップ・バイ・ステップ・ワークフロー
次の手順を使用して、販売パートナーAPIエンドポイントをテストできます。
ステップ 1:Amazon (LWA) アクセストークンを使用してログインする
まず、販売パートナーに代わって販売データにアクセスするためのアプリケーションを承認する必要があります。Login with Amazon (LWA) アクセストークンを生成すると、有効期限が切れるまで複数の SP-API 呼び出しに使用できます。
For detailed steps, refer to Generate an LWA Access Token using Postman or Step 1. Request a Login with Amazon access token.
The response returns an LWA access token that you can use to authenticate your SP-API call. An LWA access token must be included in calls to all operations (except restricted operations) that return Personally Identifiable Information (PII). When calling restricted operations, you include a Restricted Access Token (RDT) instead of an LWA access token
次の画像は、アクセストークンが開始される例を示しています Atza|****************************
そして、(LWA アクセストークンが無効になるまでの秒数) で 3600 秒 (1 時間) で有効期限が切れます。

LWA アクセストークンのリクエストとレスポンス
ステップ 2:SP-API サンドボックスエンドポイントを呼び出します。
以下の手順では、Orders API Swagger モデルを使用して SP-API サンドボックスエンドポイントへの呼び出しを練習する方法について説明します。このプロセスを使用して API 呼び出しをテストし、模擬リクエストとレスポンスを調べることができます。
- Import the Orders API Swagger model to your Postman workspace.
- コードで以下を検索する
x-amzn-api-sandbox
それらが表示される API オペレーションへの静的サンドボックス呼び出しのリクエストとレスポンスの例の静的配列を含むオブジェクト。 - リクエストパラメータには、Orders API Swagger モデルで定義されているのと同じ値を設定します。
- リクエストに、対応する Swagger モデルで定義されている必須パラメーターがすべて含まれていることを確認してください。次の例は オーダー API v0 スワッガーモデル、どこ
Get Order
API 呼び出しが成功したことを示すレスポンスが強調表示されます。

注文 API v0 スワッガーモデル
- 作る
GET
に電話して/orders/v0/orders
。 - Set the
baseUrl
as Selling Partner API sandbox. - の下に パラメーター タブをクリックし、Orders API モデルから静的リクエスト値を渡します。

「Params」タブの静的リクエスト値
- Under the Headers tab, pass the
access_token
received in Step 1 for each API call, using the key value pairx-amz-access-token
:Atc|********************
. Skip this step for restricted operations and grantless operations.

ヘッダータブのアクセストークン
- For restricted operations, pass the Restricted Data Token (RDT) received from the
createRestrictedDataToken
operations using the key value pairx-amz-access-token
:Atz.sprdt|********************
.
重要
If you are calling a restricted operation to access a customer's Personally Identifiable Information (PII), such as buyer information or a shipping address, pass a Restricted Data Token (RDT) in the request headers instead of an LWA access token. You can call the createRestrictedDataToken operation in Tokens API to get a Restricted Data Token (RDT) for one or more restricted resources that you specify.
次のレスポンス例では、RDT とその有効期限が返されます。RDT トークンは以下で使用できます。 Get Orders
PII データを取得する操作。

制限付きデータトークンの応答と有効期限
{ "restrictedDataToken": "Atz.sprdt|IQEBLjAsAhRmHjNgHpi0U-Dme37rR6CuUpSR", "expiresIn": 3600 }
- レスポンスで、Swaggerモデルと一致するペイロードが返されることを確認します。

アクセストークンを使用してOrders v0 APIの静的レスポンスを取得
販売パートナーAPIの動的サンドボックスを使用してステートフルリクエストを行う
The SP-API also provides a dynamic sandbox where you can make requests and receive varied responses that are potentially stateful and that react to input.
呼び出すAPIのSwaggerモデルJSONを確認することで、どのオペレーションが動的サンドボックス呼び出しをサポートしているかを判断できます。オペレーションに次のオブジェクトが含まれている場合、そのオペレーションは動的サンドボックスへの呼び出しをサポートします。
"x-amzn-api-sandbox": { "dynamic": {} }
オブジェクトは、オペレーションレベルまたはパスレベルのいずれかで見つけることができます。パスレベルの場合、パス内のすべてのオペレーションが動的サンドボックスを呼び出すことができます。
For more details on how to make calls to the dynamic sandbox, refer to How to make a dynamic sandbox call to the Selling Partner API.
結論
このチュートリアルでは、SP-API サンドボックスエンドポイントをテストする方法を学びました。このチュートリアルでは、LWA アクセストークンを生成し、サンドボックスエンドポイントへの SP-API 呼び出しの例を調べました。
Updated 8 months ago