All Projects → amazon-php → sp-api-sdk

amazon-php / sp-api-sdk

Licence: other
Amazon Selling Partner SPI - PHP SDKs

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to sp-api-sdk

amz sp api
AmzSpApi - Unofficial Ruby gem for the Selling Partner APIs (SP-API)
Stars: ✭ 22 (-35.29%)
Mutual labels:  amazon, mws, mws-sdk, selling-partner-api
selling-partner-api-sdk
Golang toolkit for working with Amazon's Selling Partner API (SP-API)
Stars: ✭ 48 (+41.18%)
Mutual labels:  amazon, mws, mws-sdk, selling-partner-api
selling-partner-sdk
Amazon Selling Partner JAVA SDK SP API
Stars: ✭ 15 (-55.88%)
Mutual labels:  amazon, mws, selling-partner-api
Amazon-SP-API-CSharp
.Net C# library for the new Amazon Selling Partner API
Stars: ✭ 95 (+179.41%)
Mutual labels:  amazon, selling-partner-api
mws-product
A module for retrieving product information via Amazon MWS API
Stars: ✭ 40 (+17.65%)
Mutual labels:  amazon, mws
mws-sdk
JavaScript SDK for Amazon Marketplace Web Services (MWS)
Stars: ✭ 23 (-32.35%)
Mutual labels:  amazon, mws
amazon-mws-api-sdk
Amazon MWS API TypeScript and Node.js Unofficial SDK
Stars: ✭ 19 (-44.12%)
Mutual labels:  mws, mws-sdk
line-pay-sdk-php
LINE Pay SDK for PHP
Stars: ✭ 68 (+100%)
Mutual labels:  sdk-php
investigation-amazon-brands
Materials to reproduce our findings in our stories, "Amazon Puts Its Own 'Brands' First Above Better-Rated Products" and "When Amazon Takes the Buy Box, it Doesn’t Give it up"
Stars: ✭ 56 (+64.71%)
Mutual labels:  amazon
sesdashboard
Analytics and activity tracking dashboard for AWS Simple Email Service
Stars: ✭ 36 (+5.88%)
Mutual labels:  amazon
map-kit-android
An extensive framework for map development in Android.
Stars: ✭ 44 (+29.41%)
Mutual labels:  amazon
cdek-sdk
SDK для СДЭК
Stars: ✭ 38 (+11.76%)
Mutual labels:  sdk-php
mws-orders
A Ruby interface to the Amazon MWS Orders API
Stars: ✭ 14 (-58.82%)
Mutual labels:  amazon
magento2-extension
eBay / Amazon / Walmart Integration for Magento v2.x.x
Stars: ✭ 57 (+67.65%)
Mutual labels:  amazon
installtomcataws
Install tomcat 8.x in AWS (Amazon Linux AMI)
Stars: ✭ 13 (-61.76%)
Mutual labels:  amazon
storage-abstraction
Provides an abstraction layer for interacting with a storage; the storage can be local or in the cloud.
Stars: ✭ 36 (+5.88%)
Mutual labels:  amazon
aws-ses-template-manager
A simple application offering an interface for CRUD management of AWS SES templates across all compatible regions and with your own choice of credentials profile. A great GUI productivity tool that can be setup and run locally in seconds (see readme).
Stars: ✭ 23 (-32.35%)
Mutual labels:  amazon
punic
Punic is a remote cache CLI built for Carthage and Apple .xcframework
Stars: ✭ 25 (-26.47%)
Mutual labels:  amazon
tudien
Từ điển tiếng Việt dành cho Kindle
Stars: ✭ 38 (+11.76%)
Mutual labels:  amazon
ioBroker.cloud
Enable access to ioBroker from internet
Stars: ✭ 36 (+5.88%)
Mutual labels:  amazon

Amazon Selling Partner API - PHP SDK

This repository is not an official Amazon PHP library for their SP API.

social-preview

Why next library?

The main goal of this SDK is to provide SDK's for the Amazon SP API in a way that would let the application to pass Amazon audit.

Amazon audit might happen to systems that must access API endpoints with PII.

There are already few php sp api SDKs available for PHP however most of them comes with many issues of auto generated code.

  • hardcoded dependencies like guzzlehttp/guzzle or aws/aws-sdk-php
  • legacy code base (7.2)
  • no logger
  • SDK's are oriented around single seller which is not suitable for bigger systems
  • missing or lacking support for client_credentials grant type
  • not all API covered
  • no extensions

This library goal is to resolve all above mentioned issues.

Installations

composer install amazon-php/sp-api-sdk^3.0

This library is not in a stable stage yet, please use with caution.

Releases

branch maintained
1.x 🚫
2.x
3.x

Version 1.x is deprecated becuase of the attempt to make a little more sense of what Amazon is doing with using "tags" in their Open API specification. This attempt failed and in order to keep Backward Compatibility promise, changes in the class names had to be introduced in 2.x. Version 1.0 is not going to be updated anymore, please migrate to version 2.0 that will stay consistent with Amazon Models Branch 3.x comes with BC breaks introduced by Amazon in Catalog Item models. Until old model won't go away, branches 2.x and 3.x should be maintained in parallel.

Available SDKs

SellingPartnerSDK - Facade for all SDK's

Authorization

In order to start using SP API you need to first register as a Developer and create application. Whole process is described in Amazon Official Guides.

Amazon recommends to use Role IAM when creating application however this requires and additional API request in order to obtain access token. It's easier to use User IAM and just make sure that the user has following Inline Policy

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "execute-api:Invoke",
            "Resource": "arn:aws:execute-api:*:*:*"
        }
    ]
}

IAM User

Example of changing refresh token into access token.

<?php

use AmazonPHP\SellingPartner\OAuth;
use AmazonPHP\SellingPartner\Configuration;
use AmazonPHP\SellingPartner\HttpFactory;
use Buzz\Client\Curl;
use Nyholm\Psr7\Factory\Psr17Factory;

$factory = new Psr17Factory();
$client = new Curl($factory);

$oauth = new OAuth(
    $client,
    $httpFactory = new HttpFactory($factory, $factory),
    $config = Configuration::forIAMUser(
        'lwaClientId',
        'lwaClientIdSecret',
        'awsAccessKey',
        'awsSecretKey'
    )
);

$accessToken = $oauth->exchangeRefreshToken('seller_oauth_refresh_token');

IAM Role

<?php

use AmazonPHP\SellingPartner\OAuth;
use AmazonPHP\SellingPartner\Configuration;
use AmazonPHP\SellingPartner\HttpFactory;
use Buzz\Client\Curl;
use Nyholm\Psr7\Factory\Psr17Factory;

$factory = new Psr17Factory();
$client = new Curl($factory);

$sts = new STSClient(
    $client,
    $requestFactory = $factory,
    $streamFactory = $factory
);

$oauth = new OAuth(
    $client,
    $httpFactory = new HttpFactory($requestFactory, $streamFactory),
    $config = Configuration::forIAMRole(
        'lwaClientID',
        'lwaClientID',
        $sts->assumeRole(
            'awsAccessKey',
            'awsSecretKey',
            'arn:aws:iam::.........'
        )
    )
);

$accessToken = $oauth->exchangeRefreshToken('seller_oauth_refresh_token');

Development

99% of code in this library is auto generated from Amazon Selling Partner API Models using OpenAPI Generator tool. Output is later automatically upgraded by RectorPHP to PHP 7.4 version and finally coding standards are also automatically unified by PHP CS Fixer.

Requirements:

In oder to regenerate code (for example when API definitions change), execute following code:

composer generate

Examples

<?php

use AmazonPHP\SellingPartner\Marketplace;
use AmazonPHP\SellingPartner\Regions;
use AmazonPHP\SellingPartner\SellingPartnerSDK;
use Buzz\Client\Curl;
use AmazonPHP\SellingPartner\Exception\ApiException;
use AmazonPHP\SellingPartner\Configuration;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Nyholm\Psr7\Factory\Psr17Factory;

require_once __DIR__ . '/vendor/autoload.php';

$factory = new Psr17Factory();
$client = new Curl($factory);

$configuration = Configuration::forIAMUser(
    'lwaClientId',
    'lwaClientIdSecret',
    'awsAccessKey',
    'awsSecretKey'
);

$logger = new Logger('name');
$logger->pushHandler(new StreamHandler(__DIR__ . '/sp-api-php.log', Logger::DEBUG));

$sdk = SellingPartnerSDK::create($client, $factory, $factory, $configuration, $logger);

$accessToken = $sdk->oAuth()->exchangeRefreshToken('seller_oauth_refresh_token');

try {
    $item = $sdk->catalogItem()->getCatalogItem(
        $accessToken,
        Regions::NORTH_AMERICA,
        $marketplaceId = Marketplace::US()->id(),
        $asin = 'B07W13KJZC'
    );
    dump($item);
} catch (ApiException $exception) {
    dump($exception->getMessage());
}

Logging

Default log level is set up to DEBUG, but it can be changed in configuration to any other level for all operations in all APIs or only for given operation in given API.

$configuration->setDefaultLogLevel(\Psr\Log\LogLevel::INFO);

Specific API's or only given operations can be also excluded from logging (for example APIs with PII or sensitive data).

$configuration->setLogLevel(CatalogItemSDK::API_NAME, CatalogItemSDK::OPERATION_GETCATALOGITEM, LogLevel::INFO);
$configuration->setSkipLogging(TokensSDK::API_NAME);
$configuration->setSkipLogging(AuthorizationSDK::API_NAME, AuthorizationSDK::OPERATION_GETAUTHORIZATIONCODE);

Finally, you can also ignore specific headers when logging http request/response. By default, configuration is set to ignore following sensitive authorization headers:

'authorization',
'x-amz-access-token',
'x-amz-security-token',
'proxy-authorization',
'www-authenticate',
'proxy-authenticate',

you can also add your own ignored headers:

$configuration->loggingAddSkippedHeader('some-sensitive-key');

Extensions

Each SDK allows you to register custom extensions executed before and after sending API requests.

<?php 

$configuration->registerExtension(new class implements \AmazonPHP\SellingPartner\Extension {
    public function preRequest(string $api, string $operation, RequestInterface $request): void
    {
        echo "pre: " . $api . "::" . $operation . " " . $request->getUri() . "\n";
    }

    public function postRequest(string $api, string $operation, RequestInterface $request, ResponseInterface $response): void
    {
        echo "post: " . $api . "::" . $operation . " " . $request->getUri() . " " 
            . $response->getStatusCode() . " rate limit: " . implode(' ', $response->getHeader('x-amzn-RateLimit-Limit')) . "\n";
    }
});
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].