Selling Partner APIへの接続
SP-APIに接続する方法
Before your application can connect to the Selling Partner API, you must register it and it must be authorized by a selling partner. Refer to Registering your application and Authorizing Selling Partner API applications.
These instructions show you the steps for making a call to the Selling Partner API. For help with constructing a Selling Partner API URI and adding headers to it, refer to Generating a Java client library. For a more complete solution that includes code for exchanging LWA tokens, refer to Generating a Java SDK with LWA token exchange.
ステップ1:Amazonアカウントでログインのアクセストークンをリクエストする
Amazonアカウントでログイン(LWA)のアクセストークンは、アプリケーションが出品パートナーに代わって特定のアクションを実行することを認可します。LWAアクセストークンは発行後1時間で期限が切れます。
Note about restricted operations. An LWA access token must be included in calls to all operations except restricted operations, which return Personally Identifiable Information (PII). When calling restricted operations, instead of including an LWA access token, you include a Restricted Data Token (RDT). For information about getting RDTs and calling restricted operations, refer to the Tokens API Use Case Guide.
LWAアクセストークンをリクエストするには、次のパラメーターを使用して、LWA認証サーバー(https://api.amazon.com/auth/o2/token
)に安全なHTTP POSTを実行します。
名前 | 説明 | 必須 |
---|---|---|
grant_type | リクエストされたアクセス許可のタイプ。値:
| はい |
refresh_token | The LWA refresh token. Get this value when the selling partner authorizes your application. For more information, refer to Authorizing Selling Partner API applications. | 必須ではありません。出品パートナーからの認可が必要なオペレーションを呼び出す場合はrefresh_tokenを含めてください。refresh_tokenを含める場合は、scopeを含めないでください。 |
scope | LWA認可グラントのスコープ。値:
| No. Include scope for calling a grantless operation. If you include scope, do not include refresh_token. |
client_id | Get this value when you register your application. Refer to Viewing your developer information. | はい |
client_secret | Get this value when you register your application. Refer to Viewing your developer information. | はい |
出品パートナーの認可が必要なオペレーションの呼び出し例:
POST /auth/o2/token HTTP/l.l
Host: api.amazon.com
Content-Type: application/x-www-form-urlencoded;charset=UTF-8
grant_type=refresh_token
&refresh_token=Aztr|...
&client_id=foodev
&client_secret=Y76SDl2F
グラントレスオペレーションの呼び出し例:
POST /auth/o2/token HTTP/l.l
Host: api.amazon.com
Content-Type: application/x-www-form-urlencoded;charset=UTF-8
grant_type=client_credentials
&scope=sellingpartnerapi::notifications
&client_id=foodev
&client_secret=Y76SDl2F
ヒント:LWA認可サーバーを呼び出すときに信頼できない認証局(CA)エラーが発生しないようにするには、トラストストアを更新して、アプリケーションがLWA認証サーバーを信頼するようにしてください。
レスポンス
成功レスポンスには、次の値が含まれます。
名前 | 説明 |
---|---|
access_token | LWAアクセストークン。最大サイズ:2048バイト。 |
token_type | 返されたトークンのタイプ。ベアラーなければなりません。 |
expires_in | LWAアクセストークンが無効になるまでの秒数。 |
refresh_token | リクエストで送信したLWAリフレッシュトークン。最大サイズ:2048バイト。 |
HTTP/l.l 200 OK
Content-Type: application/json;charset UTF-8
Cache-Control: no-store
Pragma:no-cache
{
"access_token":"Atza|IQEBLjAsAhRmHjNgHpi0U-Dme37rR6CuUpSREXAMPLE",
"token_type":"bearer",
"expires_in":3600,
"refresh_token":"Atzr|IQEBLzAtAhRPpMJxdwVz2Nn6f2y-tpJX2DeXEXAMPLE"
}
For more information, visit the Authorization Code Grant page in the Login with Amazon documentation.
ステップ2:Selling Partner API URIを構築する
Selling Partner API URIのコンポーネントは次のとおりです。
名前 | 説明 | 例 |
---|---|---|
HTTPメソッド | HTTPメソッド。 | GET |
エンドポイント | A Selling Partner API endpoint. | https://sellingpartnerapi-na.amazon.com |
Path | Selling Partner APIのセクション/バージョン。セクション/リソースの番号。 | /fba/inbound/v0/shipments/{shipmentId}/preorder/confirm |
クエリー文字列 | クエリーパラメーター。 | ?marketplace=ATVPDKIKX0DER |
パスパラメーター | パスパラメーター。 | shipmentId1 |
例:
PUT https://sellingpartnerapi-na.amazon.com/fba/inbound/v0/shipments/shipmentId1/preorder/confirm?MarketplaceId=ATVPDKIKX0DER&NeedByDate=2020-10-10
ステップ2:URIにヘッダーを追加する
Add headers to the URI that you constructed in Step 2. Construct a Selling Partner API URI. Here are the HTTP headers to include in requests to the Selling Partner API:
リクエストヘッダー
名前 | 説明 |
---|---|
host | The marketplace endpoint. Refer to Selling Partner API endpoints. |
x-amz-access-token | The LWA access token. Refer to Step 1. Request a Login with Amazon access token. Note about restricted operations. If you are calling a restricted operation, pass in a Restricted Data Token (RDT) here instead of an LWA access token. For information about getting RDTs and calling restricted operations, refer to the Tokens API Use Case Guide in the Tokens API Use Case Guide. |
x-amz-date | リクエストの日付と時刻。 |
user-agent | Your application name and version number, platform, and programming language. These help Amazon diagnose and fix problems you might encounter with the service. Refer to Include a User-Agent header in all requests. |
以下は、URIとヘッダーはあるが署名情報はないSelling Partner APIへのリクエストの例です。
PUT /fba/inbound/v0/shipments/shipmentId1/preorder/confirm?MarketplaceId=ATVPDKIKX0DER&NeedByDate=2020-10-10 HTTP/1.1
host: sellingpartnerapi-na.amazon.com
user-agent: My Selling Tool/2.0 (Language=Java/1.8.0.221;
Platform=Windows/10)
x-amz-access-token=Atza|IQEBLjAsAhRmHjNgHpi0U-Dme37rR6CuUpSREXAMPLE
x-amz-date: 20190430T123600Z
8日前に更新されました