scottyrobinson/laravel-amazon-mws

Simple Amazon MWS API Package for Laravel

0.2.5 2021-04-29 09:23 UTC

This package is auto-updated.

Last update: 2024-04-29 04:53:24 UTC


README

Software License Latest Version on Packagist Build Status StyleCI Scrutinizer Code Quality

Simple Amazon Marketplace Web Service API Package for Laravel

This package is under development. Currently we have only implemented the endpoints we are using. Feel free to add the endpoints you need (contribute). A List of all available endpoints you can see under the endpoint road map.

Contents

Link to the Official Amazon MWS Documentation

Installation

This package requires PHP 7.3 and Laravel 8.0 or higher. For older laravel versions install the latest 0.1.x version.

Require the package using composer:

composer require looxis/laravel-amazon-mws

The package will automatically register itself.

Add your Environment Variables for MWS to your .env File. The variable names are listed in the amazon-mws.php config file.

Configuration

To successfully authenticate with the Amazon Marketplace Web Service you need to add the Environment variables to your .env File. The variable names are listed in the amazon-mws.php config file. Also you can set a default marketplace.

You can optionally publish the configuration with:

$ php artisan vendor:publish --provider="Looxis\LaravelAmazonMWS\AmazonMWSServiceProvider" --tag="config"

This will create an amazon-mws.php in your config directory.

Config file content with the env variables:

<?php

return [
    'access_key_id' => env('MWS_ACCESS_KEY_ID'),
    'secret_key' => env('MWS_SECRET_KEY'),
    'seller_id' => env('MWS_SELLER_ID'),
    'mws_auth_token' => env('MWS_AUTH_TOKEN'),
    'default_market_place' => env('MWS_DEFAULT_MARKET_PLACE', 'DE'),
];

Usage

Authentication

Amazon MWS authenticates you via the Canonicalized Query String. The Laravel Amazon MWS Package handles this for you and adds the string for each request. You just have to add your seller specific credentials to your .env file (configuration).

Marketplaces

If you need to change the marketplaces just set the country/countries in your code via the MWS Facade. For simplicity the package chooses the right endpoint and market place id via the given country. You do not have to set them by yourself. (Amazon MWS endpoints and Market Place IDS Overview) If something is missing do not hesitate to create an issue.

AmazonMWS::setMarketplaces('FR');

AmazonMWS::setMarketplaces('DE', 'FR');  //to append multiple marketplaces to your request query strings.

Orders

Retrieve order information that you need. Amazon MWS Orders Documentation Overview

List Orders

Returns orders created or updated during a time frame that you specify. MWS List Orders Documentation

$response = AmazonMWS::orders()->list([
    'CreatedAfter' => '2020-04-09T18:56:29+02:00'
]);

// List Order By Next Token
$response = AmazonMWS::orders()->list([
    'NextToken' => '27u07N+WSfaaJkJYLDm0ZAmQazDrhw3C...'
]);
Throttling
  • maximum request quota of six and a restore rate of one request every minute. MWS Throttling Algorithm
  • Throws a ServerException with Request is throttled

Get Order

Returns orders based on the AmazonOrderId values that you specify. MWS Get Order Documentation

$response = AmazonMWS::orders()->get("1234-1234-1234"); //get amazon order by id

$response = AmazonMWS::orders()->get("1234-1234-1234", "123-123-123"); //get multiple orders
Throttling
  • maximum request quota of six and a restore rate of one request every minute. MWS Throttling Algorithm
  • Throws a ServerException with Request is throttled

List Order Items

Returns order items based on the AmazonOrderId that you specify. MWS List Order Items Documentation

$response = AmazonMWS::orders()->getItems("1234-1234-1234");
Throttling
  • ListOrderItems and ListOrderItemsByNextToken share same throttling
  • maximum request quota of 30 and a restore rate of one request every two seconds. MWS Throttling Algorithm
  • Throws a ServerException with Request is throttled

Feeds

The Feeds API lets you upload inventory and order data to Amazon Amazon MWS Orders Documentation Overview

Submit Feed

Uploads a feed for processing by Amazon MWS.

You must set the feed type and content to successfully submit the feed. The content for the xml depends on the FeedType

$feedXmlContent = '<?xml version="1.0"?> ...';
$response = AmazonMWS::feeds()
                ->setType("_POST_ORDER_ACKNOWLEDGEMENT_DATA_")
                ->setContent($xml)
                ->submit();
Throttling
  • maximum request quota of 15 and a restore rate of one request every two minutes.
  • Hourly request quote: 30 MWS Throttling Algorithm
  • Throws a ServerException with Request is throttled
Responses

The Amazon MWS XML responses are parsed and will be casted into a convenient array structure. For checking if the Feed was successful you need to check the result via the GetSubmissionFeedResult endpoint.

SubmitFeedResponse Example:

[
    "request_id" => "e86f7299-9712-43e3-b290-b659da85b527"
    "data" => [
        "FeedSubmissionId" => "2291326430"
        "FeedType" => "_POST_ORDER_ACKNOWLEDGEMENT_DATA_"
        "SubmittedDate" => "2020-03-04T14:54:14+00:00"
        "FeedProcessingStatus" => "_SUBMITTED_"
    ]
]

Get Feed Submission Result

Returns the feed processing report and the Content-MD5 header.

Pass the Feed Submission Id as a parameter to retrieve the feed result Amazon MWS Description GetFeedSubmissionResult

$response = AmazonMWS::feeds()
                ->getFeedSubmissionResult($feedSubmissionId);
Throttling
  • maximum request quota of 15 and a restore rate of one request every minute.
  • Hourly request quote: 60 MWS Throttling Algorithm
  • Throws a ServerException with Request is throttled
Responses

The Feed Submission Result responses are parsed and will be casted into a convenient structure.

SubmitFeedResponse Example:

[
    "status_code" => "Complete",
    "processing_summary" => [
        "MessagesProcessed" => "2"
        "MessagesSuccessful" => "2"
        "MessagesWithError" => "0"
        "MessagesWithWarning" => "0"
    ],
    "result" => null
]

General Responses

Response Format Documentation The Amazon MWS XML responses are parsed and will be casted into a convenient array structure. GetOrder Response Example:

[
    "request_id" => "be781aff-3c63-485a-aec8-951ed3be2ba4",
    "data" => [
        "AmazonOrderId" => "902-3159896-1390916",
        ...
    ]
]

Exceptions

The Laravel Amazon MWS package does not catch the Exceptions returned by guzzle. For Example for throttling ServerExceptions or missing Parameter Client Exceptions.

Endpoint Road map

Laravel Amazon MWS is still under development. We have only added the endpoints we currently are using ourselfs. We decided to ship it in this early stage so you can help to add some endpoits or use the already existing.

Endpoint List:

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Security

If you discover any security related issues, please email dev@looxis.com instead of using the issue tracker.

Credits

About us

LOOXIS GmbH based in Minden, Germany.

LOOXIS is a manufacturer of personalised gift articles, which are sold throughout Europe in (photo) specialist shops and via our online shop under www.looxis.com.

License

MIT