{"id":13748853,"url":"https://github.com/double-break/spapi-php","last_synced_at":"2025-12-26T22:50:08.501Z","repository":{"id":38680224,"uuid":"323671889","full_name":"double-break/spapi-php","owner":"double-break","description":"Amazon Selling Partner API PHP Client","archived":false,"fork":false,"pushed_at":"2022-06-30T11:26:56.000Z","size":101,"stargazers_count":56,"open_issues_count":2,"forks_count":48,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-11T12:51:59.706Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/double-break.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-12-22T16:02:44.000Z","updated_at":"2024-07-01T17:00:12.000Z","dependencies_parsed_at":"2022-07-11T02:18:04.092Z","dependency_job_id":null,"html_url":"https://github.com/double-break/spapi-php","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/double-break%2Fspapi-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/double-break%2Fspapi-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/double-break%2Fspapi-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/double-break%2Fspapi-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/double-break","download_url":"https://codeload.github.com/double-break/spapi-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253240350,"owners_count":21876593,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T07:00:50.903Z","updated_at":"2025-12-26T22:50:08.450Z","avatar_url":"https://github.com/double-break.png","language":"PHP","readme":"# SPAPI\n\nspapi-php is a http client for Amazon's Selling Partner API\n\nAuthor: Lyubomir Slavilov\n\n## Before you start\n\nSpapi is released as Composer package `double-break/spapi-php` with **no warranties or promises**.\n\nThere are couple classes (such as `Signer`, `Credentials`) which are essential for the API calls to work. Most of the issues will live here.\n\nAll of the actual API clients are autogenerated and given the disclaimer above - not heavily tested.\n\n### Requirements\n\n- php 7.3 (never tested on lower version)\n- composer\n- a lot of time reading Amazon SP API documentation\n\n## Install and update\n\nNow you are ready to do\n\n```bash\ncomposer require double-break/spapi-php\n```\n\n### Package updates\n\nOnce you have successfully installed the package, the updates are simple as normal Composer package updates. Just execute:\n\n```bash\ncomposer update double-break/spapi-php\n```\n\n## Configuration\n\n| Name                     | Description                                                                                                                  | Type                                                     |\n| ------------------------ | ---------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------- |\n| `http`                   | Contains all the `Guzzle` configuration                                                                                      | GuzzleConfiguration                                      |\n| **LWA configuration**    |                                                                                                                              |\n| `refresh_token`          | Value of the refresh token issued by the Seller authorizing the application                                                  | string                                                   |\n| `client_id`              | The client id which is generated in the Seller Apps console                                                                  | string                                                   |\n| `client_secret`          | The client secret with which the client will identify itself                                                                 | string                                                   |\n| `access_token_longevity` | The longevity in seconds of the token. It is basically the time period in which the token will be kept in the `TokenStorage` | integer\u003cbr/\u003eDefault: 3600                                |\n| **STS configuration**    |                                                                                                                              |\n| `access_key`             | The IAM role access key                                                                                                      | string                                                   |\n| `secret_key`             | The IAM role secret key                                                                                                      | string                                                   |\n| `role_arn`               | The ARN of the IAM role                                                                                                      | string                                                   |\n| `sts_session _longevity` | The longevity of the STS session which will be created                                                                       | integer \u003cbr /\u003eDefault: 3600                              |\n| **API configuration**    |                                                                                                                              |\n| `region`                 | The region identifier for the region you are going to execute your calls against                                             | string \u003cbr /\u003e Example: `eu-west-1`                       |\n| `host`                   | The region specific host of the Selling Partner API                                                                          | string \u003cbr /\u003e Example: `sellingpartnerapi-eu.amazon.com` |\n\n## Examples\n\n### Simple use\n\n```php\n\u003c?php\n  include __DIR__ . '/vendor/autoload.php';\n\n\n  /** The Setup **/\n\n  $config = [\n    //Guzzle configuration\n    'http' =\u003e [\n      'verify' =\u003e false,    //\u003c--- NOT SAFE FOR PRODUCTION\n      'debug' =\u003e true       //\u003c--- NOT SAFE FOR PRODUCTION\n    ],\n\n    //LWA: Keys needed to obtain access token from Login With Amazon Service\n    'refresh_token' =\u003e '\u003cYOUR-REFRESH-TOKEN\u003e',\n    'client_id' =\u003e '\u003cCLINET-ID-IN-SELLER-CONSOLE\u003e',\n    'client_secret' =\u003e '\u003cCLIENT_SECRET\u003e',\n\n    //STS: Keys of the IAM role which are needed to generate Secure Session\n    // (a.k.a Secure token) for accessing and assuming the IAM role\n    'access_key' =\u003e '\u003cSTS-ACCESS_KEY\u003e',\n    'secret_key' =\u003e '\u003cSTS-SECRET-KEY\u003e',\n    'role_arn' =\u003e '\u003cROLE-ARN\u003e' ,\n\n    //API: Actual configuration related to the SP API :)\n    'region' =\u003e 'eu-west-1',\n    'host' =\u003e 'sellingpartnerapi-eu.amazon.com'\n  ];\n\n  //Create token storage which will store the temporary tokens\n  $tokenStorage = new DoubleBreak\\Spapi\\SimpleTokenStorage('./aws-tokens');\n\n  //Create the request signer which will be automatically used to sign all of the\n  //requests to the API\n  $signer = new DoubleBreak\\Spapi\\Signer();\n\n  //Create Credentials service and call getCredentials() to obtain\n  //all the tokens needed under the hood\n\n  $credentials = new DoubleBreak\\Spapi\\Credentials($tokenStorage, $signer, $config);\n  $cred = $credentials-\u003egetCredentials();\n\n\n\n  /** The application logic implementation **/\n\n\n  //Create SP API Catalog client and execute one ot its REST methods.\n  $catalogClient = new DoubleBreak\\Spapi\\Api\\CatalogItems($cred, $config);\n\n  //Check the catalog info for B074Z9QH5F ASIN\n  $result = $catalogClient-\u003egetCatalogItem('B074Z9QH5F', [\n      'marketplaceIds' =\u003e 'A1PA6795UKMFR9',\n  ]);\n\n\n  print_r($result);\n```\n\n### Feed API usage\n\nFor Feed API, user can follow [Feeds API Use Case Guide](https://github.com/amzn/selling-partner-api-docs/blob/main/guides/use-case-guides/feeds-api-use-case-guide-2020-09-04.md).\n\nAnd in this guide for step 2. Encrypt and upload the feed data: user can use below example:\n\n```php\n\u003c?php\n\n// content type of the feed data to be uploaded.\n$contentType = 'text/xml; charset=UTF-8';\n\n// create feed document\n$feedClient = new \\DoubleBreak\\Spapi\\Api\\Feeds($cred, $config);\n$response = $feedClient-\u003ecreateFeedDocument([\"contentType\" =\u003e $contentType]);\n$payload = $response['payload'];\n\n$feedContentFilePath = './testFeedDoc.xml';\n\n$result = (new \\DoubleBreak\\Spapi\\Helper\\Feeder())-\u003euploadFeedDocument($payload,$contentType,$feedContentFilePath);\nprint_r($result);\n```\n\nAnd for Step 6. Download and decrypt the feed processing report: user can use below example:\n\n```php\n\u003c?php\n$feedClient = new \\DoubleBreak\\Spapi\\Api\\Feeds($cred, $config);\n\n// $resultFeedDocumentId: from response of getFeed() function.\n$resultFeedDocumentId = 'amzn1.tortuga.3.ed4cd0d8-447b-4c22-96b5-52da8ace1207.T3YUVYPGKE9BMY';\n$response = $feedClient-\u003egetFeedDocument($resultFeedDocumentId);\n$payload = $response['payload'];\n\n$result = (new \\DoubleBreak\\Spapi\\Helper\\Feeder())-\u003edownloadFeedProcessingReport($payload);\nprint_r($result);\n```\n\n### Debugging responses\n\n```php\n\u003c?php\n  //configuration and initialization here\n\n  $catalogClinet = new DoubleBreak\\Spapi\\Api\\Catalog($cred, $config);\n  try {\n    $result = $catalogClinet-\u003egetCatalogItem('B074Z9QH5F', [\n      'MarketplaceId' =\u003e 'A1PA6795UKMFR9',\n    ])['payload'];\n    //do your business here\n  } catch (\\GuzzleHttp\\Exception\\ClientException $e) {\n    $httpCode = $e-\u003egetResponse()-\u003egetStatusCode();\n    $errorBody =  $e-\u003egetResponse()-\u003egetBody();\n\n    echo \"Amazon SP API responded with HTTP {$httpCode}\\n {$errorBody}\";\n\n  } catch(\\Exception $e) {\n    echo \"Unexpected exception: \" . $e-\u003egetMessage();\n  }\n```\n\n### Accessing response headers\n\n📝Accessing headers by using client's `getLastHttpResponse()` is available since v1.0.5\n\n```php\n\u003c?php\n  //configuration and initialization here\n\n  //Create SP API Catalog client and execute one ot its REST methds.\n  $catalogClinet = new DoubleBreak\\Spapi\\Api\\Catalog($cred, $config);\n\n  //Check the catalog info for B074Z9QH5F ASIN\n  $result = $catalogClinet-\u003egetCatalogItem('B074Z9QH5F', [\n    'MarketplaceId' =\u003e 'A1PA6795UKMFR9',\n  ])['payload'];\n\n  $headers = $catalogClinet-\u003egetLastHttpResponse()-\u003egetHeaders();\n  foreach ($headers as $headerName =\u003e $values) {\n    echo \"{$headerName}: \" . implode(','. $values);\n  }\n```\n\n### Debugging 4xx and 5xx response headers\n\n📝Accessing headers by using client's `getLastHttpResponse()` is available since v1.0.5\n\n```php\n\u003c?php\n  //configuration and initialization here\n\n  $catalogClinet = new DoubleBreak\\Spapi\\Api\\Catalog($cred, $config);\n  try {\n    $result = $catalogClinet-\u003egetCatalogItem('B074Z9QH5F', [\n      'MarketplaceId' =\u003e 'A1PA6795UKMFR9',\n    ])['payload'];\n    //do your business here\n  } catch (\\GuzzleHttp\\Exception\\ClientException $e) {\n    $headers = $e-\u003egetResponse()-\u003egetHeaders();\n    print_r($headers);\n  }\n\n  // OR\n\n  try {\n    $result = $catalogClinet-\u003egetCatalogItem('B074Z9QH5F', [\n      'MarketplaceId' =\u003e 'A1PA6795UKMFR9',\n    ])['payload'];\n    //do your business here\n\n  } catch (\\GuzzleHttp\\Exception\\ClientException $e) {\n    $headers = $catalogClinet-\u003egetLastHttpResponse()-\u003egetHeaders();\n    print_r($headers);\n  }\n\n```\n\n### Migrating authorization from Amazon Marketplace Web Service to Selling Partner Api\n\n[Please, see more details in Selling Partner Api docs](https://github.com/amzn/selling-partner-api-docs/blob/main/guides/developer-guide/SellingPartnerApiDeveloperGuide.md#migrating-authorization-from-amazon-marketplace-web-service)\n\n```php\n\u003c?php\ninclude __DIR__ . '/vendor/autoload.php';\n\n  /** The Setup **/\n\n$config = [\n    //Guzzle configuration\n    'http' =\u003e [\n        'verify' =\u003e false,\n        'debug' =\u003e true\n    ],\n\n    //LWA: Keys needed to obtain access token from Login With Amazon Service\n    'refresh_token' =\u003e '\u003cYOUR-REFRESH-TOKEN\u003e',\n    'client_id' =\u003e '\u003cCLINET-ID-IN-SELLER-CONSOLE\u003e',\n    'client_secret' =\u003e '\u003cCLIENT_SECRET\u003e',\n\n    //STS: Keys of the IAM role which are needed to generate Secure Session\n    // (a.k.a Secure token) for accessing and assuming the IAM role\n    'access_key' =\u003e '\u003cSTS-ACCESS_KEY\u003e',\n    'secret_key' =\u003e '\u003cSTS-SECRET-KEY\u003e',\n    'role_arn' =\u003e '\u003cROLE-ARN\u003e' ,\n\n    //API: Actual configuration related to the SP API :)\n    'region' =\u003e 'eu-west-1',\n    'host' =\u003e 'sellingpartnerapi-eu.amazon.com'\n];\n\n//Create token storage which will store the temporary tokens\n$tokenStorage = new DoubleBreak\\Spapi\\SimpleTokenStorage('./aws-tokens');\n\n//Create the request signer which will be automatically used to sign all of the\n//requests to the API\n$signer = new DoubleBreak\\Spapi\\Signer();\n\n//Create Credentials service and call getCredentials() to obtain\n//all the tokens needed under the hood\n$credentials = new DoubleBreak\\Spapi\\Credentials($tokenStorage, $signer, $config);\n//get credentials with migration token, it's needed for /authorization/v1/authorizationCode request\n$cred = $credentials-\u003egetCredentials(true);\n\n/** The application logic implementation **/\n\n//Create SP API Catalog client and execute one ot its REST methods.\n$authorizationClient = new DoubleBreak\\Spapi\\Api\\Authorization($cred, $config);\n\n//Get Authorization code\n$result = $authorizationClient-\u003egetAuthorizationCode([\n    'developerId' =\u003e '\u003cDEVELOPER-ID-AUTHORIZED-BY-SELLING-PARTNER\u003e',\n    'mwsAuthToken' =\u003e '\u003cMWS-AUTH-TOKEN\u003e',\n    'sellingPartnerId' =\u003e '\u003cSELLING-PARTNER-ID\u003e'\n])['payload'];\n\n//Authorization code should be changed to Access and Refresh token\nprint_r($credentials-\u003eexchangesAuthorizationCodeForRefreshToken($result['authorizationCode']));\n```\n\n### Authorization for Grantless Operations in Selling Partner API\n\n[Please, see more details in Selling Partner Api docs](https://github.com/amzn/selling-partner-api-docs/blob/main/guides/developer-guide/SellingPartnerApiDeveloperGuide.md#grantless-operations-1)\n\n```php\n\u003c?php\ninclude __DIR__ . '/vendor/autoload.php';\n\n  /** The Setup **/\n\n$config = [\n    //Guzzle configuration\n    'http' =\u003e [\n        'verify' =\u003e false,\n        'debug' =\u003e true\n    ],\n\n    //LWA: Keys needed to obtain access token from Login With Amazon Service\n    'refresh_token' =\u003e '\u003cYOUR-REFRESH-TOKEN\u003e',\n    'client_id' =\u003e '\u003cCLINET-ID-IN-SELLER-CONSOLE\u003e',\n    'client_secret' =\u003e '\u003cCLIENT_SECRET\u003e',\n\n    //STS: Keys of the IAM role which are needed to generate Secure Session\n    // (a.k.a Secure token) for accessing and assuming the IAM role\n    'access_key' =\u003e '\u003cSTS-ACCESS_KEY\u003e',\n    'secret_key' =\u003e '\u003cSTS-SECRET-KEY\u003e',\n    'role_arn' =\u003e '\u003cROLE-ARN\u003e' ,\n\n    //API: Actual configuration related to the SP API :)\n    'region' =\u003e 'eu-west-1',\n    'host' =\u003e 'sellingpartnerapi-eu.amazon.com'\n];\n\n//Create token storage which will store the temporary tokens\n$tokenStorage = new DoubleBreak\\Spapi\\SimpleTokenStorage('./aws-tokens');\n\n//Create the request signer which will be automatically used to sign all of the\n//requests to the API\n$signer = new DoubleBreak\\Spapi\\Signer();\n\n//Create Credentials service and call getCredentials() to obtain\n//all the tokens needed under the hood\n$credentials = new DoubleBreak\\Spapi\\Credentials($tokenStorage, $signer, $config);\n//get credentials with Grantless auth token, it's needed for grantless operations request\n$cred = $credentials-\u003egetCredentials('grantless');\n\n/** The application logic implementation **/\n\n//Create SP API Notification client and execute one ot its REST methods.\n$notificationClient = new DoubleBreak\\Spapi\\Api\\Notifications($cred, $config);\n\n//Get notification destinations\n$result = $notificationClient-\u003egetDestinations();\nprint_r($result['payload']);\n```\n\n### Working with Restricted Data APIs\n\n```php\n\u003c?php\n  include __DIR__ . '/vendor/autoload.php';\n\n\n  /** The Setup **/\n\n  $config = [\n    // same as examples above...\n  ];\n\n  //Create token storage which will store the temporary tokens\n  $tokenStorage = new DoubleBreak\\Spapi\\SimpleTokenStorage('./aws-tokens');\n\n  //Create the request signer which will be automatically used to sign all of the\n  //requests to the API\n  $signer = new DoubleBreak\\Spapi\\Signer();\n\n  //Create Credentials service and call getCredentials() to obtain\n  //all the tokens needed under the hood\n\n  $credentials = new DoubleBreak\\Spapi\\Credentials($tokenStorage, $signer, $config);\n  $cred = $credentials-\u003egetRdtCredentials([\n    'restrictedResources' =\u003e [\n      [\n        'method' =\u003e 'GET',\n        'path' =\u003e '/orders/v0/orders/{orderId}/buyerInfo'\n      ],\n      [\n        'method' =\u003e 'GET',\n        'path' =\u003e '/mfn/v0/shipments/{shipmentId}'\n      ]\n    ]\n  ]);\n\n\n\n  /** The application logic implementation **/\n\n\n  //Create SP API Orders client and execute one ot its REST methods.\n  $orderClient = new DoubleBreak\\Spapi\\Api\\Orders($cred, $config);\n\n  //Get order's buyer info\n  $result = $catalogClient-\u003egetOrderBuyerInfo('902-3159896-1390916')['payload'];\n  print_r($result);\n\n  //...\n```\n\nFor more information see the Amazons's use case documentation about this topic: https://github.com/amzn/selling-partner-api-docs/blob/main/guides/en-US/use-case-guides/tokens-api-use-case-guide/tokens-API-use-case-guide-2021-03-01.md\n","funding_links":[],"categories":["Docs"],"sub_categories":["Library"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdouble-break%2Fspapi-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdouble-break%2Fspapi-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdouble-break%2Fspapi-php/lists"}