Amazon SP-API カタログ情報を取得するには?

ショコラ
ショコラ

Amazon SP-API カタログ情報を取得するには?

CatalogItems を GET で呼び出します。
関連ドキュメントはこちら
https://developer-docs.amazon.com/sp-api/docs/catalog-items-api-v2022-04-01-use-case-guide

もっさん先輩
もっさん先輩

ASIN のカタログ情報を取得するプログラムです。

#!/usr/local/bin/php
<?php
// ASIN から商品情報を取得する

$access_token   = file_get_contents('access_token');
$Host           = 'sellingpartnerapi-fe.amazon.com';
#$asin          = 'B004Y9IZDC'; // コカ・コーラ
 $asin          = 'B06VVGDCF8'; // nVidia
$marketplaceIds = 'A1VC38T7YXB528';
$includedData   = 'attributes,productTypes';
$url = "https://{$Host}/catalog/2022-04-01/items/{$asin}?marketplaceIds={$marketplaceIds}&includedData={$includedData}";

$options = array(
  CURLOPT_HTTPGET        => true,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_URL            => $url,
  CURLOPT_HTTPHEADER     => array(
    "Host: {$Host}",
    "x-amz-access-token: {$access_token}",
  ),
  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);

サンドボックス版
https://github.com/amzn/selling-partner-api-models/blob/main/models/catalog-items-api-model/catalogItemsV0.json

#!/usr/local/bin/php
<?php
// ASIN から商品情報を取得する

$access_token   = file_get_contents('access_token');
$Host           = 'sandbox.sellingpartnerapi-fe.amazon.com';
$asin           = 'ASIN_200';
$MarketplaceIds = 'TEST_CASE_200';
$url = "https://{$Host}/catalog/v0/items/{$asin}?MarketplaceId={$MarketplaceIds}";

$options = array(
  CURLOPT_HTTPGET        => true,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_URL            => $url,
  CURLOPT_HTTPHEADER     => array(
    "Host: {$Host}",
    "x-amz-access-token: {$access_token}",
  ),
  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);

サンドボックスの他のバージョンを使うとエラー

#!/usr/local/bin/php
<?php
// ASIN から商品情報を取得する

$access_token   = file_get_contents('access_token');
$Host           = 'sandbox.sellingpartnerapi-fe.amazon.com';
$asin           = 'B07N4M94X4';
$marketplaceIds = 'ATVPDKIKX0DER';
$url = "https://{$Host}/catalog/2022-04-01/items/{$asin}?marketplaceIds={$marketplaceIds}";

$options = array(
  CURLOPT_HTTPGET        => true,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_URL            => $url,
  CURLOPT_HTTPHEADER     => array(
    "Host: {$Host}",
    "x-amz-access-token: {$access_token}",
  ),
  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);
array(1) {
  ["errors"]=>
  array(1) {
    [0]=>
    array(3) {
      ["code"]=>
      string(12) "Unauthorized"
      ["message"]=>
      string(39) "Access to requested resource is denied."
      ["details"]=>
      string(55) "The marketplaces you provided are not valid for region."
    }
  }
}

以上

Scroll to Top