チュートリアル: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 で電話をかけるには、まず認証情報を設定する必要があります。ワークスペースには次のグローバル変数が必要です。

ステップ・バイ・ステップ・ワークフロー

次の手順を使用して、販売パートナー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 時間) で有効期限が切れます。

2034

LWA アクセストークンのリクエストとレスポンス

ステップ 2:SP-API サンドボックスエンドポイントを呼び出します。

以下の手順では、Orders API Swagger モデルを使用して SP-API サンドボックスエンドポイントへの呼び出しを練習する方法について説明します。このプロセスを使用して API 呼び出しをテストし、模擬リクエストとレスポンスを調べることができます。

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

注文 API v0 スワッガーモデル

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

「Params」タブの静的リクエスト値

  1. Under the Headers tab, pass the access_token received in Step 1 for each API call, using the key value pair x-amz-access-token: Atc|********************. Skip this step for restricted operations and grantless operations.
2720

ヘッダータブのアクセストークン

  1. For restricted operations, pass the Restricted Data Token (RDT) received from the createRestrictedDataToken operations using the key value pair x-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 データを取得する操作。

2708

制限付きデータトークンの応答と有効期限

{ "restrictedDataToken": "Atz.sprdt|IQEBLjAsAhRmHjNgHpi0U-Dme37rR6CuUpSR", "expiresIn": 3600 }

  1. レスポンスで、Swaggerモデルと一致するペイロードが返されることを確認します。
2698

アクセストークンを使用して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 呼び出しの例を調べました。


このページは役に立ちましたか?