1. Go to this page and download the library: Download tims/laravel-amazon-spapi library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tims / laravel-amazon-spapi example snippets
use SpApi\Api\sellers\v1\SellersApi;
use Tims\AmazonSpApi\Facades\AmazonSpApi;
use Tims\AmazonSpApi\SpApiManager;
public function index(SpApiManager $spApi)
{
/** @var SellersApi $api */
$api = $spApi->make(SellersApi::class);
$result = $api->getMarketplaceParticipations();
return response()->json($result);
}
// Or via facade:
$api = AmazonSpApi::make(SellersApi::class);
use Tims\AmazonSpApi\Models\Credentials;
use Tims\AmazonSpApi\Models\Seller;
$seller = Seller::create(['name' => 'My Seller']);
$credentials = Credentials::create([
'seller_id' => $seller->id,
'selling_partner_id' => 'A********',
'region' => 'NA',
// Optional when using shared app credentials from .env
'client_id' => null,
'client_secret' => null,
'refresh_token' => 'Atzr|...',
]);
use SpApi\Api\sellers\v1\SellersApi;
$api = $credentials->make(SellersApi::class);
$result = $api->getMarketplaceParticipations();
use Tims\AmazonSpApi\Enums\Marketplace;
use Tims\AmazonSpApi\OAuth;
$oauth = OAuth::fromConfig();
$authorizeUrl = $oauth->getAuthorizationUri(
marketplace: Marketplace::US,
state: $state,
draftApp: true,
);
// After Amazon redirects back with spapi_oauth_code:
$refreshToken = $oauth->getRefreshToken($request->query('spapi_oauth_code'));
use SpApi\Api\orders\v0\OrdersV0Api;
use Tims\AmazonSpApi\Facades\AmazonSpApi;
$ordersApi = AmazonSpApi::make(OrdersV0Api::class, options: [
'data_elements' => ['buyerInfo', 'shippingAddress'],
]);
$result = $ordersApi->getOrders(
['ATVPDKIKX0DER'],
'2024-01-01T00:00:00Z',
);
use SpApi\Api\notifications\v1\NotificationsApi;
use Tims\AmazonSpApi\Enums\GrantlessScope;
use Tims\AmazonSpApi\Facades\AmazonSpApi;
$api = AmazonSpApi::makeGrantless(
NotificationsApi::class,
GrantlessScope::Notifications, // or ClientCredentialRotation
);
$destinations = $api->getDestinations();