galahadxvi / amazon-product-api-php
A lightweight PHP package for Amazon Product Advertising API 5.0
Requires
- php: >=7.4
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
- mockery/mockery: ^1.4
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2025-07-07 18:56:44 UTC
README
Note: This package is currently in progress and under active development. Features may change and the API is not yet stable.
A lightweight PHP package for interacting with Amazon's Product Advertising API 5.0. This package provides a simple and reliable way to fetch product data from Amazon's catalog using the Product Advertising API.
Features
- Simple, straightforward API for getting Amazon product information
- Handles AWS v4 request signing
- Supports all Amazon marketplaces
- Fully unit tested
- No dependency on Amazon's SDK
Implementation Status
- ✅ GetItems - Implemented
- ❌ GetBrowseNodes - Not implemented
- ❌ GetVariations - Not implemented
- ❌ SearchItems - Not implemented
Requirements
- PHP 7.4 or higher
- Guzzle HTTP client
Installation
You can install the package via composer:
composer require galahadxvi/amazon-product-api-php:dev-main
Warning: This package is currently in development. The dev-main branch is subject to breaking changes. Use in production at your own risk.
Usage
Basic Usage
<?php use Custom\AmazonAdvertisingApi\AmazonProductApi; use Custom\AmazonAdvertisingApi\Enums\Region; use Custom\AmazonAdvertisingApi\Enums\GetItems\Resource; // Initialize the client with your Amazon PA-API credentials $client = new AmazonProductApi( 'YOUR_ACCESS_KEY', 'YOUR_SECRET_KEY', 'YOUR_PARTNER_TAG', Region::UNITED_STATES // Optional, defaults to US ); // Get a single product by ASIN try { $product = $client->getItem('B07PDHSJ1H', [ Resource::ITEM_INFO_TITLE, Resource::IMAGES_PRIMARY, Resource::OFFERS_LISTINGS ]); if ($product) { echo "Product Title: " . $product['ItemInfo']['Title']['DisplayValue'] . "\n"; echo "Product URL: " . $product['DetailPageURL'] . "\n"; } else { echo "Product not found.\n"; } } catch (Exception $e) { echo "Error: " . $e->getMessage() . "\n"; } // Get multiple products by ASINs try { $response = $client->getItems(['B07PDHSJ1H', 'B07G4MNFS1'], [ Resource::ITEM_INFO_TITLE, Resource::IMAGES_PRIMARY ]); foreach ($response['ItemsResult']['Items'] as $product) { echo "Product Title: " . $product['ItemInfo']['Title']['DisplayValue'] . "\n"; } } catch (Exception $e) { echo "Error: " . $e->getMessage() . "\n"; }
Available Resources
The package provides constants for all available resources in the Resource
enum:
use Custom\AmazonAdvertisingApi\Enums\Resource; // Use specific resources $resources = [ Resource::ITEM_INFO_TITLE, Resource::ITEM_INFO_FEATURES, Resource::ITEM_INFO_PRODUCT_INFO, Resource::IMAGES_PRIMARY, Resource::OFFERS_LISTINGS ]; // Or get all available resources $all_resources = Resource::getAllResources();
Regional Support
The package supports all Amazon marketplaces through the Region
enum:
use Custom\AmazonAdvertisingApi\Enums\Region; // UK marketplace $client = new AmazonAdvertisingApi( 'YOUR_ACCESS_KEY', 'YOUR_SECRET_KEY', 'YOUR_PARTNER_TAG', Region::UNITED_KINGDOM ); // Germany marketplace $client = new AmazonAdvertisingApi( 'YOUR_ACCESS_KEY', 'YOUR_SECRET_KEY', 'YOUR_PARTNER_TAG', Region::GERMANY );
Available Regions
Region::AUSTRALIA
- Amazon AustraliaRegion::BRAZIL
- Amazon BrazilRegion::CANADA
- Amazon CanadaRegion::FRANCE
- Amazon FranceRegion::GERMANY
- Amazon GermanyRegion::INDIA
- Amazon IndiaRegion::ITALY
- Amazon ItalyRegion::JAPAN
- Amazon JapanRegion::MEXICO
- Amazon MexicoRegion::NETHERLANDS
- Amazon NetherlandsRegion::SINGAPORE
- Amazon SingaporeRegion::SAUDI_ARABIA
- Amazon Saudi ArabiaRegion::SPAIN
- Amazon SpainRegion::SWEDEN
- Amazon SwedenRegion::TURKEY
- Amazon TurkeyRegion::UNITED_ARAB_EMIRATES
- Amazon UAERegion::UNITED_KINGDOM
- Amazon UKRegion::UNITED_STATES
- Amazon US
Background
Why this package?
I developed this package because Amazon's own SDK was returning 500 Bad Response errors when attempting to interact with the Amazon Product Advertising API. This made the SDK unusable for our needs.
Our solution
This package resolves these issues by manually implementing a simple version of the Amazon Product Advertising API request using Guzzle.
Testing
The package includes a comprehensive test suite. You can run the tests with the following command:
composer test
Available Operations
Currently, this package only supports the following PA-API operations:
GetItems
- Retrieve product information for one or more ASINsGetItem
- Convenience method to retrieve product information for a single ASIN
Future releases will add support for additional operations such as:
- SearchItems
- GetBrowseNodes
- GetVariations
Extending
While this package currently only supports the GetItems operation, you can extend the AmazonAdvertisingApi
class to add support for additional operations:
use Custom\AmazonAdvertisingApi\AmazonProductApi; class ExtendedAmazonApi extends AmazonProductApi { private const SEARCH_ITEMS_URI_PATH = '/paapi5/searchitems'; private const SEARCH_ITEMS_TARGET = 'com.amazon.paapi5.v1.ProductAdvertisingAPIv1.SearchItems'; public function searchItems(string $keywords, array $resources = []): array { // Implementation here... } }
Please note that while you can extend the class to add more operations, we recommend waiting for official support in future releases to ensure proper implementation and testing.
License
This package is open-sourced software licensed under the MIT license.