Amazon Selling Partner API integration and documentation for laravel8 and php

Amazon Selling Partner API integration and documentation for laravel8 and php

The Selling Partner API (SP-API) is a REST-based API that helps Amazon selling partners programmatically access their data on orders, shipments, payments, and much more. Applications using the SP-API can increase selling efficiency, reduce labor requirements, and improve response time to customers, helping selling partners grow their businesses.

 

Key Features

With the Selling Partner API, you can:

Set up an OAuth authorization workflow that selling partners initiate from the Amazon Partner Network detail page or from your own website.

Generate an SDK that can help you with LWA token exchange and authentication.

Test your applications by making calls to a sandbox environment.

 

Global Applications

You only need to register as a developer once, in the region and marketplace of your choice, to be able to create a SP-API application that can be authorized by a selling partner from any region or marketplace. You need only one set of developer credentials (your AWS access key ID and AWS secret access key) to make calls to any SP-API endpoint, as long as the endpoint is for the same region as the selling partner who authorized your application.

Selling Partner API for PHP

  • Supports all Selling Partner API operations (for Sellers and Vendors) as of 5/30/2022 (see here for links to documentation for all calls)
  • Supports applications made with both IAM user and IAM role ARNs (docs)
  • Automatically generates Restricted Data Tokens for all calls that require them -- no extra calls to the Tokens API needed
  • Includes a Document helper class for uploading and downloading feed/report documents

 

Installation

composer require jlevers/selling-partner-api

Table of Contents

Check out the Getting Started section below for a quick overview.

This README is divided into several sections:

 

Getting Started

Prerequisites

You need a few things to get started:

  • A Selling Partner API developer account
  • An AWS IAM user or role configured for use with the Selling Partner API
  • A Selling Partner API application

If you're looking for more information on how to set those things up, check out this blog post. It provides a detailed walkthrough of the whole setup process.

 

Setup

The Configuration constructor takes a single argument: an associative array with all the configuration information that's needed to connect to the Selling Partner API:

$config = newSellingPartnerApi\Configuration([ "lwaClientId" => "<LWA client ID>", "lwaClientSecret" => "<LWA client secret>", "lwaRefreshToken" => "<LWA refresh token>", "awsAccessKeyId" => "<AWS access key ID>", "awsSecretAccessKey" => "<AWS secret access key>", // If you're not working in the North American marketplace, change// this to another endpoint from lib/Endpoint.php"endpoint" => SellingPartnerApi\Endpoint::NA,]);

If you created your Selling Partner API application using an IAM role ARN instead of a user ARN, pass that role ARN in the configuration array:

$config = newSellingPartnerApi\Configuration([ "lwaClientId" => "<LWA client ID>", "lwaClientSecret" => "<LWA client secret>", "lwaRefreshToken" => "<LWA refresh token>", "awsAccessKeyId" => "<AWS access key ID>", "awsSecretAccessKey" => "<AWS secret access key>", // If you're not working in the North American marketplace, change// this to another endpoint from lib/Endpoint.php"endpoint" => SellingPartnerApi\Endpoint::NA, "roleArn" => "<Role ARN>",]);

Getter and setter methods exist for the Configuration class's lwaClientId, lwaClientSecret, lwaRefreshToken, awsAccessKeyId, awsSecretAccessKey, and endpoint properties. The methods are named in accordance with the name of the property they interact with: getLwaClientId, setLwaClientId, getLwaClientSecret, etc.

$config can then be passed into the constructor of any SellingPartnerApi\Api\*Api class. See the Example section for a complete example.

 
Configuration options

The array passed to the Configuration constructor accepts the following keys:

  • lwaClientId (string): Required. The LWA client ID of the SP API application to use to execute API requests.
  • lwaClientSecret (string): Required. The LWA client secret of the SP API application to use to execute API requests.
  • lwaRefreshToken (string): The LWA refresh token of the SP API application to use to execute API requests. Required, unless you're only using the Configuration instance to call grantless operations.
  • awsAccessKeyId (string): Required. AWS IAM user Access Key ID with SP API ExecuteAPI permissions.
  • awsSecretAccessKey (string): Required. AWS IAM user Secret Access Key with SP API ExecuteAPI permissions.
  • endpoint (array): Required. An array containing a url key (the endpoint URL) and a region key (the AWS region). There are predefined constants for these arrays in lib/Endpoint.php: (NA, EU, FE, and NA_SANDBOX, EU_SANDBOX, and FE_SANDBOX. See here for more details.
  • accessToken (string): An access token generated from the refresh token.
  • accessTokenExpiration (int): A Unix timestamp corresponding to the time when the accessToken expires. If accessToken is given, accessTokenExpiration is required (and vice versa).
  • onUpdateCredentials (callable|Closure): A callback function to call when a new access token is generated. The function should accept a single argument of type SellingPartnerApi\Credentials.
  • roleArn (string): If you set up your SP API application with an AWS IAM role ARN instead of a user ARN, pass that ARN here.
  • authenticationClient (GuzzleHttp\ClientInterface): Optional GuzzleHttp\ClientInterface object that will be used to generate the access token from the refresh token
  • tokensApi (SellingPartnerApi\Api\TokensApi): Optional SellingPartnerApi\Api\TokensApi object that will be used to fetch Restricted Data Tokens (RDTs) when you call a restricted operation
  • authorizationSigner (SellingPartnerApi\Contract\AuthorizationSignerContract): Optional SellingPartnerApi\Contract\AuthorizationSignerContract implementation. See Custom Authorization Signer section
  • requestSigner (SellingPartnerApi\Contract\RequestSignerContract): Optional SellingPartnerApi\Contract\RequestSignerContract implementation. See Custom Request Signer section.

Examples

This example assumes you have access to the Seller Insights Selling Partner API role, but the general format applies to any Selling Partner API request.

<?phprequire_once(__DIR__ . '/vendor/autoload.php');useSellingPartnerApi\Api\SellersV1ApiasSellersApi;useSellingPartnerApi\Configuration;useSellingPartnerApi\Endpoint;$config = newConfiguration([ "lwaClientId" => "amzn1.application-oa2-client.....", "lwaClientSecret" => "abcd....", "lwaRefreshToken" => "Aztr|IwEBI....", "awsAccessKeyId" => "AKIA....", "awsSecretAccessKey" => "ABCD....", // If you're not working in the North American marketplace, change// this to another endpoint from lib/Endpoint.php"endpoint" => Endpoint::NA]);$api = newSellersApi($config);try { $result = $api->getMarketplaceParticipations(); print_r($result);} catch (Exception$e) { echo'Exception when calling SellersApi->getMarketplaceParticipations: ', $e->getMessage(), PHP_EOL;}?>

To get debugging output when you make an API request, you can call $config->setDebug(true). By default, debug output goes to stdout via php://output, but you can redirect it a file with $config->setDebugFile('<path>').

<?phprequire_once(__DIR__ . '/vendor/autoload.php');useSellingPartnerApi\Configuration;$config = newConfiguration([/* ... */]);$config->setDebug(true);// To redirect debug info to a file:$config->setDebugFile('./debug.log');

 

Supported API segments

Each API class name contains the API's version. This allows for multiple versions of the same API to be accessible in a single version of this package. It makes the class names a little uglier, but allows for simultaneously using new and old versions of the same API segment, which is often useful. The uglier names can be remedied by formatting use statements like so:

useSellingPartnerApi\Api\SellersV1ApiasSellersApi;useSellingPartnerApi\Model\SellersV1asSellers;

It also means that if a new version of an existing API is introduced, the library can be updated to include that new version without introducing breaking changes.

Seller APIs

Vendor APIs

Post Code : NTYtSnVuIDEzLCAyMDIy

photo

Sonjoy Bhadra

Python | Django | Laravel | 12Years Experience


962

Views

104

Following

42

Posts

Popular posts

The Latest