This library wraps the following functions of Amazon's Product Advertising API:
1. ItemSearch2. BrowseNodeLookup
3. ItemLookup
4. SimilarityLookup
5. CartAdd
6. CartClear
7. CartCreate
8. CartGet
9. CartModify
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');
- 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();
- Set the parameters using the
$apai->setParam()
function
//Set parameters
$apai->setParam('SearchIndex', 'All');
$apai->setParam('ResponseGroup', 'Offers');
$apai->setParam('Keywords', 'hp laptop');
- Call the actual function eg ItemSearch
$verbose = true; //Print url sent to Amazon and the results from Amazon
$response = $apai->itemSearch($verbose);
- Handle the response. The response is an array with
status
andresponse
keys. If the request is successful,status
will be1
andresponse
will have the xml string that you should parse withSimpleXMLElement
, otherwisestatus
will be0
andresponse
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.