PHPackages                             mirahost/amazonproductapi - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. mirahost/amazonproductapi

ActiveLibrary[API Development](/categories/api)

mirahost/amazonproductapi
=========================

PHP library to perform product lookup and searches using the Amazon Product API.

3.0.4(8y ago)01.3k↓100%MITPHP

Since Jul 20Pushed 8y ago1 watchersCompare

[ Source](https://github.com/mirahost/AmazonProductAPI)[ Packagist](https://packagist.org/packages/mirahost/amazonproductapi)[ Docs](https://github.com/mirahost/AmazonProductAPI/)[ RSS](/packages/mirahost-amazonproductapi/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (2)Dependencies (1)Versions (6)Used By (0)

AmazonProductAPI
================

[](#amazonproductapi)

PHP library to perform product lookup and searches using the Amazon Product API.

Installation
------------

[](#installation)

This library requires the [SimpleXML](http://php.net/manual/en/book.simplexml.php) and [Curl](http://php.net/manual/en/book.curl.php) extensions to be installed and uses PHP 7+ . Installation is simple using [Composer](https://composer.io):

```
composer require mirahost/amazonproductapi
```

### Amazon Product API

[](#amazon-product-api)

It also assumes that you have some basic knowledge of Amazon's Product API and have set up an Amazon Associate account see: [Amazon Product API Set Up](http://docs.amazonwebservices.com/AWSECommerceService/2011-08-01/GSG/GettingSetUp.html).

You'll need an AWS key, secret key, and associate tag. Ensure that you keep these safe!

Examples
--------

[](#examples)

I've added some simple examples in `examples.php`. To run them create a file called `secretKeys.php` containing your secret keys:

```

```

and then run the examples with:

```
php examples.php
```

Quick Start
-----------

[](#quick-start)

Include the library in your code using the Composer autoloader and create an AmazonUrlBuilder with your credentials

```
require('vendor/autoload.php');

use MarcL\AmazonAPI;
use MarcL\AmazonUrlBuilder;

// Keep these safe
$keyId = 'YOUR-AWS-KEY';
$secretKey = 'YOUR-AWS-SECRET-KEY';
$associateId = 'YOUR-AMAZON-ASSOCIATE-ID';

// Setup a new instance of the AmazonUrlBuilder with your keys
$urlBuilder = new AmazonUrlBuilder(
    $keyId,
    $secretKey,
    $associateId,
    'uk'
);

// Setup a new instance of the AmazonAPI and define the type of response
$amazonAPI = new AmazonAPI($urlBuilder, 'simple');

$items = $amazonAPI->ItemSearch('harry potter', 'Books', 'price');
```

**Note:** Keep your Amazon keys safe. Either use environment variables or include from a file that you don't check into GitHub.

### Locale

[](#locale)

This library supports all [Product Advertising API locales](http://docs.aws.amazon.com/AWSECommerceService/latest/DG/Locales.html) and you can set it as you construct the AmazonUrlBuilder class with your keys.

At this time, these are the current supported locales:

- Brazil ('br')
- Canada ('ca')
- China ('cn')
- France ('fr')
- Germany ('de')
- India ('in')
- Italy ('it')
- Japan ('jp')
- Mexico ('mx')
- Spain ('es')
- United Kingdom ('uk')
- United States ('us')

### Item Search

[](#item-search)

To search for an item use the `ItemSearch()` method:

```
// Search for harry potter items in all categories
$items = $amazonAPI->ItemSearch('harry potter');

// Search for harry potter items in Books category only
$items = $amazonAPI->ItemSearch('harry potter', 'Books');
```

#### Default sort

[](#default-sort)

By default, the `ItemSearch()` method will search by featured. If you want to sort by another category then pass a 3rd parameter with the name of the category you wish to sort by. These differ by category type but the two you'll probably need are `price` (sort by price low to high) or `-price` (sort by price high to low). See [ItemSearch Sort Values](http://docs.aws.amazon.com/AWSECommerceService/latest/DG/APPNDX_SortValuesArticle.html) for more details.

```
// Search for harry potter items in Books category, sort by low to high
$items = $amazonAPI->ItemSearch('harry potter', 'Books', 'price');

// Search for harry potter items in Books category, sort by high to low
$items = $amazonAPI->ItemSearch('harry potter', 'Books', '-price');
```

To determine valid categories for search call `GetValidSearchNames()`:

```
// Get an array of valid search categories we can use
$searchCategories = $amazonAPI->GetValidSearchNames();
```

### Item Lookup

[](#item-lookup)

To look up product using the product ASIN number use `ItemLookup()`:

```
// Retrieve specific item by id
$items = $amazonAPI->ItemLookUp('B003U6I396');

// Retrieve a list of items by ids
$asinIds = array('B003U6I396', 'B003U6I397', 'B003U6I398');
$items = $amazonAPI->ItemLookUp($asinIds);
```

### Data Transformation

[](#data-transformation)

By default the data will be returned as SimpleXML nodes. However, you can ask for the data to be transformed differently, depending on your use case for the API. Pass a type when instantiating the AmazonAPI class as follows:

```
// Default return type is XML
$amazonAPI = new AmazonAPI($amazonUrlBuilder);
$items = $amazonAPI->ItemSearch('harry potter');
var_dump($items);
```

This will output:

```
class SimpleXMLElement#2 (2) {
	public $OperationRequest =>
		class SimpleXMLElement#3 (3) {
			public $RequestId =>
			string(36) "de58449e-0c1a-47ac-9823-00fd049c52df"
			public $Arguments =>
			class SimpleXMLElement#5 (1) {
				public $Argument =>
				array(11) {
	...
```

```
// Return simplified data
$amazonAPI = new AmazonAPI($amazonUrlBuilder, 'simple');
$items = $amazonAPI->ItemSearch('harry potter');
var_dump($items);
```

This will return a simplified version of each item with minimal data but enough for simple use cases.

```
array(10) {
	[0] =>
	array(8) {
	'asin' =>
	string(10) "B00543R3WG"
	'url' =>
	string(212) "http://www.amazon.co.uk/Harry-Potter-Complete-8-Film-Collection/dp/B00543R3WG%3FSubscriptionId%3D1BM0B8TXM1YSZ1M0XDR2%26tag%3Ddjcr-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB00543R3WG"
	'rrp' =>
	double(44.99)
	'title' =>
	string(58) "Harry Potter - The Complete 8-Film Collection [DVD] [2011]"
	'lowestPrice' =>
	double(23.4)
	'largeImage' =>
	string(53) "http://ecx.images-amazon.com/images/I/51qa9nTUsEL.jpg"
	'mediumImage' =>
	string(61) "http://ecx.images-amazon.com/images/I/51qa9nTUsEL._SL160_.jpg"
	'smallImage' =>
	string(60) "http://ecx.images-amazon.com/images/I/51qa9nTUsEL._SL75_.jpg"
	}
	[1] =>
	array(8) {
	'asin' =>
	string(10) "0747558191"
	'url' =>
	string(212) "http://www.amazon.co.uk/Harry-Potter-Philosophers-Stone-Rowling/dp/0747558191%3FSubscriptionId%3D1BM0B8TXM1YSZ1M0XDR2%26tag%3Ddjcr-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D0747558191"
	'rrp' =>
	double(6.99)
	'title' =>
	string(40) "Harry Potter and the Philosopher\'s Stone"
	…

```

The different data transformation types are defined as follows. Feel free to raise an issue if you'd like the data transforming to a new type.

- **xml** - (Default) returns data as SimpleXML nodes.
- **array** - Returns data as PHP arrays and objects.
- **simple** - Returns data as simplified arrays and doesn't contain all API data. Use this if you just need prices, title and images.
- **json** - Returns data as a JSON string. Use this for returning from a server API endpoint.

TODO
----

[](#todo)

- Need to make the simplified data less hardcoded!

Thanks
------

[](#thanks)

This library uses code based on [AWS API authentication For PHP](http://randomdrake.com/2009/07/27/amazon-aws-api-rest-authentication-for-php-5/) by [David Drake](https://github.com/randomdrake) but has been mostly rewritten.

LICENSE
-------

[](#license)

See [LICENSE](LICENSE)

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~36 days

Total

5

Last Release

3073d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7101f20c62d79eaa8bf732ae25a480c5d5957e4f00d5c355953f1e9cfa6f45e5?d=identicon)[mirahost](/maintainers/mirahost)

---

Top Contributors

[![MarcL](https://avatars.githubusercontent.com/u/1965510?v=4)](https://github.com/MarcL "MarcL (28 commits)")

---

Tags

apiamazonproduct

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mirahost-amazonproductapi/health.svg)

```
[![Health](https://phpackages.com/badges/mirahost-amazonproductapi/health.svg)](https://phpackages.com/packages/mirahost-amazonproductapi)
```

###  Alternatives

[marcl/amazonproductapi

PHP library to perform product lookup and searches using the Amazon Product API.

13212.4k1](/packages/marcl-amazonproductapi)[jakiboy/apaapi

Easily integrate with the Amazon Affiliate Program using the lightweight APAAPI library for Amazon Creators API (With OAuth 2.0 &amp; Credential-less)

543.8k](/packages/jakiboy-apaapi)[thiagomarini/amazon-mws-client

PHP client for Amazon MWS API

151.4k](/packages/thiagomarini-amazon-mws-client)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
