![ショコラ](https://answorz.com/wp-content/uploads/2022/06/animal_hamster-1.png)
ショコラ
Amazon SP-API 在庫数を更新するには?
ListingsItems を PATCH で呼び出します。
関連ドキュメントは
【出品アイテムAPI v2021-08-01ユースケースガイド】
https://developer-docs.amazon.com/sp-api/lang-ja_JP/docs/listings-items-api-v2021-08-01-use-case-guide
![もっさん先輩](https://answorz.com/wp-content/uploads/2022/06/mosss.png)
もっさん先輩
SKU の在庫数を更新するプログラムです。
「”productType”:”LUGGAGE”」が必要です。
#!/usr/local/bin/php
<?php
// 在庫数を更新する
$access_token = file_get_contents('access_token');
$Host = 'sellingpartnerapi-fe.amazon.com';
$sellerId = '[出品者トークン]';
$sku = '[SKU]';
$marketplaceIds = 'A1VC38T7YXB528';
$url = "https://{$Host}/listings/2021-08-01/items/{$sellerId}/{$sku}?marketplaceIds={$marketplaceIds}";
$json =<<< JSON
{
"productType":"LUGGAGE",
"patches":[
{
"op":"replace",
"path":"/attributes/fulfillment_availability",
"value":[
{
"quantity":"[在庫数]",
"fulfillment_channel_code":"DEFAULT"
}
]
}
]
}
JSON;
$options = array(
CURLOPT_CUSTOMREQUEST => 'PATCH',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_URL => $url,
CURLOPT_HTTPHEADER => array(
"Host: {$Host}",
"x-amz-access-token: {$access_token}",
'Content-Type: application/json; charset=utf-8',
),
CURLOPT_POSTFIELDS => $json,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
);
$curl = curl_init();
curl_setopt_array($curl,$options);
$resp = curl_exec($curl);
curl_close($curl);
$json = json_decode($resp,true);
mb_convert_variables('EUC-JP','UTF-8',$json);
var_dump($json);
以上