Skip to content

edwinmugendi/amazon-apai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Amazon Product Advertising API wrapper

This library wraps the following functions of Amazon's Product Advertising API:

1. ItemSearch
2. BrowseNodeLookup
3. ItemLookup
4. SimilarityLookup
5. CartAdd
6. CartClear
7. CartCreate
8. CartGet
9. CartModify

Usage

1. Load and initialize Apai Class ```php require_once __DIR__ . '/../vendor/autoload.php'; // Autoload files using Composer autoload

use Edwinmugendi\Amazon\Apai;

$apai = new Apai();

2. Set the following 4 configs using the <code>$apai->setConfig()</code> function
```php
//Set configs
$apai->setConfig('ApiKey', 'XXXXX');
$apai->setConfig('ApiSecret', 'XXXX');
$apai->setConfig('AssociativeTag', 'XXXX');
$apai->setConfig('EndPoint', 'webservices.amazon.de');
  1. If you are looping via a list of items, you might need to reset the parameters. This basically removes any preset parameters
//Reset parameters first. This is important if you are looping through items
$apai->resetParam();
  1. Set the parameters using the $apai->setParam() function
//Set parameters
$apai->setParam('SearchIndex', 'All');
$apai->setParam('ResponseGroup', 'Offers');
$apai->setParam('Keywords', 'hp laptop');
  1. Call the actual function eg ItemSearch
$verbose = true; //Print url sent to Amazon and the results from Amazon
$response = $apai->itemSearch($verbose);
  1. Handle the response. The response is an array with status and response keys. If the request is successful, status will be 1 and response will have the xml string that you should parse with SimpleXMLElement, otherwise status will be 0 and response will have the error message.
if ($response['status']) {
    $item_lookup_xml = new \SimpleXMLElement($response['response']);
} else {
    echo $response['response'];
}//E# if else statement

For sample code of every function, check the tests folder.

Contact me on [email protected] if you need any assistance.

About

Amazon Product Advertising API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages