- PHP >= 7.0
- Laravel >= 5.5
composer require revolution/laravel-amazon-product-api
php artisan vendor:publish --provider="Revolution\Amazon\ProductAdvertising\Providers\AmazonProductServiceProvider"
AMAZON_API_KEY=
AMAZON_API_SECRET_KEY=
AMAZON_ASSOCIATE_TAG=
AMAZON_COUNTRY=com
https://docs.aws.amazon.com/AWSECommerceService/latest/DG/Locales.html
e.g.
- US=com
- UK=co.uk
This package depends on https://github.com/Exeu/apai-io
<?php
use AmazonProduct;
# string $category, string $keyword = null, int $page = 1
$response = AmazonProduct::search('All', 'amazon' , 1);
dd($response);
# returns normal array
# string $browse Browse node
$response = AmazonProduct::browse('1');
# sort by TopSeller
# Response Group: NewReleases
$response = AmazonProduct::browse('1', 'NewReleases');
# string $asin ASIN
$response = AmazonProduct::item('ASIN1');
# array $asin ASIN
$response = AmazonProduct::items(['ASIN1', 'ASIN2']);
# setIdType: support only item() and items()
$response = AmazonProduct::setIdType('EAN')->item('EAN');
# reset to ASIN
AmazonProduct::setIdType('ASIN');
browse()
is not contains detail data.
$response = AmazonProduct::browse('1');
$nodes = array_get($response, 'BrowseNodes');
$items = array_get($nodes, 'BrowseNode.TopSellers.TopSeller');
$asins = array_pluck($items, 'ASIN');
$results = AmazonProduct::items($asins);
Probably, you need try-catch or Laravel's rescue()
helper.
try {
$response = AmazonProduct::browse('1');
} catch() {
}
$response = rescue(function () use ($browse_id) {
return AmazonProduct::browse($browse_id);
}, []);
<?php
use AmazonProduct;
use ApaiIO\Operations\Search;
$search = new Search();
$search->setCategory('All');
$search->setKeywords('amazon');
$search->setResponseGroup(['Large']);
$response = AmazonProduct::run($search);
dd($response);
# returns normal array
<?php
use ApaiIO\ApaiIO;
use ApaiIO\Configuration\GenericConfiguration;
use ApaiIO\Request\GuzzleRequest;
use ApaiIO\ResponseTransformer\XmlToArray;
use GuzzleHttp\Client;
$client = new Client();
$request = new GuzzleRequest($client);
$request->setScheme('https');
$config = config('amazon-product');
$conf = new GenericConfiguration();
$conf->setCountry($config['country'])
->setAccessKey($config['api_key'])
->setSecretKey($config['api_secret_key'])
->setAssociateTag($config['associate_tag'])
->setResponseTransformer(new XmlToArray())
->setRequest($request);
$apaiio = new ApaiIO($conf);
AmazonProduct::config($apaiio);
use ApaiIO\ApaiIO;
use ApaiIO\Configuration\GenericConfiguration;
use ApaiIO\Request\GuzzleRequest;
use ApaiIO\ResponseTransformer\XmlToArray;
use GuzzleHttp\Client;
//...
public function boot()
{
\AmazonProduct::macro('reconfig', function (array $config) {
$client = new Client();
$request = new GuzzleRequest($client);
$request->setScheme('https');
$conf = new GenericConfiguration();
$conf->setCountry($config['country'])
->setAccessKey($config['api_key'])
->setSecretKey($config['api_secret_key'])
->setAssociateTag($config['associate_tag'])
->setResponseTransformer(new XmlToArray())
->setRequest($request);
$apaiio = new ApaiIO($conf);
$this->config($apaiio);
return $this;
});
}
$config = [
'api_key' => '',
'api_secret_key' => '',
'associate_tag' => '',
'country' => '',
];
\AmazonProduct::reconfig($config);
Customize Operation.
use ApaiIO\Operations\Lookup;
//...
public function boot()
{
\AmazonProduct::hook('item', function (Lookup $lookup) {
return $lookup->setMerchantId('Amazon');
});
}
- search
- browse
- item
- items
- run
MIT
Copyright kawax