– Amazon Affiliate With PHP –
Apaapi is an unofficial PHP library for accessing the Amazon Creators API, without relying on the Amazon SDK. It is lightweight (~300 KB) and simplifies interaction with the Amazon Creators API, making it easier to integrate Amazon product data into PHP applications.
[!CAUTION] Apaapi 2.x exclusively uses the Amazon Creators API.
Support for Apaapi 1.x (PA-API v5) has been discontinued!
composer require jakiboy/apaapi
include('apaapi-main/src/Autoloader.php');
\Apaapi\Autoloader::init();
| **cURL | Stream (file)** |
“CREDENTIAL_SECRET” : From your Amazon Creators API (your locale), More.
Recommended using Apaapi Builder or Apaapi Product (Scraped data) if you dont have API credentials.
/**
* @see Use Composer,
* Or include Apaapi Autoloader Here.
*/
use Apaapi\includes\Builder;
// (1) Init request builder
$builder = new Builder('_CREDENTIAL_ID_', '_CREDENTIAL_SECRET_', '_TAG_', '_LOCALE_');
// (2) Get response (Search)
$data = $builder->searchOne('Sony Xperia 1 VI'); // Normalized array
[!Note]
See full builder usage at /wiki/Builder and use case /examples
/**
* @see Use Composer,
* Or include Apaapi Autoloader Here.
*/
use Apaapi\includes\Product;
// (1) Init product
$product = new Product('B00NLZUM36', 'com', 'test-21');
// (2) Get response
$data = $product->get(); // Array
[!Note]
See full product usage at /wiki/ProductRating:
Get customer reviews of product as average rating and count (Scraped data).
use Apaapi\includes\Rating;
// Init Rating
$rating = new Rating('B00NLZUM36', 'com', 'test-21');
// Get Response
$data = $rating->get(); // Array
Get affiliate cart URL.
use Apaapi\lib\Cart;
// Init Cart
$cart = new Cart();
$cart->setLocale('com')->setPartnerTag('test-21');
// Get Response
$data = $cart->set(['B00NLZUM36' => 3]); // String
Extensible search method.
use Apaapi\operations\SearchItems;
use Apaapi\lib\Request;
use Apaapi\lib\Response;
// (1) Set operation
$operation = new SearchItems();
$operation->setPartnerTag('_TAG_')->setKeywords('_KEYWORDS_');
// (2) Prapere request
$request = new Request('_CREDENTIAL_ID_', '_CREDENTIAL_SECRET_');
$request->setLocale('_LOCALE_')->setPayload($operation);
// (3) Get response
$response = new Response($request);
$data = $response->get(); // Array
[!Note]
See all available TLDs used by setLocale() at /wiki/TLDs
Extensible get method.
use Apaapi\operations\GetItems;
use Apaapi\lib\Request;
use Apaapi\lib\Response;
// Set operation
$operation = new GetItems();
$operation->setPartnerTag('_TAG_')->setItemIds(['_ASIN_']);
// Prapere request
$request = new Request('_CREDENTIAL_ID_', '_CREDENTIAL_SECRET_');
$request->setLocale('_LOCALE_')->setPayload($operation);
// Get response
$response = new Response($request);
$data = $response->get(); // Array
All available operations.
use Apaapi\operations\GetItems;
use Apaapi\operations\SearchItems;
use Apaapi\operations\GetVariations;
use Apaapi\operations\GetBrowseNodes;
// (1) GetItems
$operation = new GetItems();
$operation->setPartnerTag('_TAG_');
$operation->setItemIds(['_ASIN_']); // Array
// (2) SearchItems
$operation = new SearchItems();
$operation->setPartnerTag('_TAG_');
$operation->setKeywords('_KEYWORDS_'); // String
// (3) GetVariations
$operation = new GetVariations();
$operation->setPartnerTag('_TAG_');
$operation->setASIN('_ASIN_'); // String
// (4) GetBrowseNodes
$operation = new GetBrowseNodes();
$operation->setPartnerTag('_TAG_');
$operation->setBrowseNodeIds(['_NODE_']); // Array
Optimize response time by setting only the needed resources.
use Apaapi\operations\SearchItems;
// Set Operation
$operation = new SearchItems();
$operation->setPartnerTag('_TAG_')->setKeywords('_KEYWORDS_');
// Set Resources (3)
$operation->setResources(['images.primary.small', 'itemInfo.title', 'offersV2.listings.price']);
[!Note]
See all available resources used by setResources() at /wiki/Resources
Skip the coffee! If you like the project, a Star would mean a lot.
[!IMPORTANT]
The Amazon logo included in top of this page refers only to the Amazon Creators API, Amazon Inc. or its affiliates.