caponica/amazon-paa
PHP client for Amazon Product Advertising API (PAA). Helps build signed requests and fetch product data (items, offers, images, etc.) for affiliate-style integrations. Lightweight package aimed at simple API consumption and response handling.
Installation
composer require caponica/amazon-paa
Add the service provider to config/app.php:
'providers' => [
// ...
Caponica\AmazonPAA\AmazonPAAServiceProvider::class,
],
Configuration Publish the config file:
php artisan vendor:publish --provider="Caponica\AmazonPAA\AmazonPAAServiceProvider"
Update config/amazon-paa.php with your:
US, UK)First Use Case: Fetch Item Data
use Caponica\AmazonPAA\Facades\AmazonPAA;
$response = AmazonPAA::itemLookup(['ItemId' => 'B08N5KWBZ2']);
$items = $response->getItems();
Item Lookup Fetch product details by ASIN, ISBN, or UPC:
$response = AmazonPAA::itemLookup([
'ItemId' => ['B08N5KWBZ2', 'B07Q5JQ1X1'],
'ResponseGroup' => 'ItemAttributes,Images,Offers'
]);
Search Products
$response = AmazonPAA::search([
'Keywords' => 'wireless earbuds',
'SearchIndex' => 'Electronics',
'ItemCount' => 10
]);
Browse Nodes
$response = AmazonPAA::browseNodeLookup([
'BrowseNodeId' => '1000',
'ResponseGroup' => 'Children'
]);
Rate Limiting: The API enforces 1 request per second. Cache responses aggressively:
$cacheKey = 'amazon_'.md5(serialize($params));
return Cache::remember($cacheKey, now()->addMinutes(5), function() use ($params) {
return AmazonPAA::itemLookup($params);
});
Error Handling Wrap calls in try-catch:
try {
$response = AmazonPAA::itemLookup(['ItemId' => 'INVALID_ASIN']);
} catch (\Caponica\AmazonPAA\Exceptions\AmazonPAAException $e) {
Log::error($e->getMessage());
return response()->json(['error' => 'Amazon API failed'], 500);
}
Pagination
Use getNextToken() for paginated results:
$response = AmazonPAA::search(['Keywords' => 'laptop']);
while ($response->getNextToken()) {
$response = AmazonPAA::search([
'Keywords' => 'laptop',
'NextToken' => $response->getNextToken()
]);
}
Associate Tag Validation
AssociateTag in config must match the one registered in Amazon’s PAAPI.Response Groups
ResponseGroup values are supported for every operation. Check Amazon’s docs for valid combinations.Offers requires ItemAttributes in ItemLookup.Locale-Specific Data
Marketplace config must match the locale of your data (e.g., US for US dollars, UK for GBP).Deprecated Parameters
Version) are ignored in newer API versions. Stick to the latest PAAPI docs.Enable Debug Mode
Set debug to true in config/amazon-paa.php to log raw API responses:
'debug' => env('AMAZON_PAA_DEBUG', false),
Validate XML Responses
Use dd($response->getRawResponse()) to inspect raw XML if data is malformed.
Common Errors
InvalidParameterValue: Check for typos in SearchIndex or ItemId.AWS.AmazonAdvertisingAPI.NoSuchKey: Verify your AssociateTag and credentials.Throttling: Implement exponential backoff for rate limits.Custom Response Transformers Override the default response handling by binding a custom transformer:
AmazonPAA::extend(function ($response) {
return (object) [
'title' => $response->getItems()[0]->getTitle(),
'price' => $response->getItems()[0]->getListPrice()->getAmount()
];
});
Middleware for API Calls Add middleware to log or modify requests/responses:
AmazonPAA::middleware(function ($request, $next) {
Log::info('Amazon PAAPI Request:', $request->getParams());
return $next($request);
});
Testing Mock the API client for unit tests:
$mock = Mockery::mock(\Caponica\AmazonPAA\AmazonPAAClient::class);
$mock->shouldReceive('itemLookup')->andReturn($mockResponse);
$this->app->instance(\Caponica\AmazonPAA\AmazonPAAClient::class, $mock);
How can I help you explore Laravel packages today?