apaapi
apaapi copied to clipboard
⚡ Quick connection to Amazon Affiliate Program using the lightweight Amazon Product Advertising API Library v5 (APAAPI)
APAAPI
Amazon Product Advertising API V5.0 (Without Amazon SDK).
This repository contains a PHP Lightweight (155 Ko) Wrapper Library, Allows you accessing the Amazon Product Advertising API V5.0 from your PHP App, Quickly & easily!
-- Become an Amazon Affiliate With PHP --
🔧 Installing:
Using Composer:
composer require jakiboy/apaapi
Without Composer?
- 1 - Download repository ZIP (Latest version).
- 2 - Extract ZIP (apaapi-master).
- 3 - Include this lines beelow (apaapi self-autoloader).
include('apaapi-master/src/Autoloader.php');
\apaapi\Autoloader::init();
- 4 - You can now use the Quickstart examples.
🔨 Upgrade :
See changes before migrate:
This version includes:
- Support for disabled cURL (Used Stream).
- Throws exception if cURL AND Stream are disabled.
- Error reporting (Including semantic errors with status 200 & HTTP Client Errors), More.
- HTTP Client helpers (RequestClient::hasCurl() & RequestClient::hasStream()).
- Response parsing (object/array/serialized).
- Throws exception if Locale (Region/TLD) is invalid, More.
- Throws exception if Resource (e.g. Images.Primary.Large) is invalid, More.
And had many improvements:
- Uses default Ressources for each Operation.
- Clean ecosystem.
- Extendable HTTP Client.
⚡ Getting Started:
Variables (Basics):
- "{Your-partner-tag}" : From your Amazon Associates (your locale), More.
- "{Your-secrect-key}" : From your Amazon Associates (your locale), More.
- "{Your-key-id}" : From your Amazon Associates (your locale), More.
- "{Your-keywords}" : What you are looking for (Products), More.
- "{Your-region}" : TLD of the target to which you are sending requests (com/fr/com.be/de), Get TLD.
- "{ASIN}" : Amazon Standard Identification Number (your locale), More.
Quickstart:
/**
* @see You can use Composer,
* Or include Apaapi Autoloader Here.
*/
use Apaapi\operations\SearchItems;
use Apaapi\lib\Request;
use Apaapi\lib\Response;
/**
* @see With Three Easy Steps,
* You can Achieve Quick Connection to Amazon Affiliate Program,
* Via Amazon Product Advertising API Library.
*/
// (1) Set Operation
$operation = new SearchItems();
$operation->setPartnerTag('{Your-partner-tag}')->setKeywords('{Your-keywords}');
// (2) Prapere Request
$request = new Request('{Your-key-id}','{Your-secrect-key}');
$request->setLocale('{Your-region}')->setPayload($operation);
// (3) Get Response
$response = new Response($request);
echo $response->get(); // JSON ready for parsing
- See all available TLDs used by setLocale() at /docs/tlds.md
Operations:
use Apaapi\operations\GetItems;
use Apaapi\operations\SearchItems;
use Apaapi\operations\GetVariations;
use Apaapi\operations\GetBrowseNodes;
/**
* @see 4 Operations.
* @see https://webservices.amazon.com/paapi5/documentation/operations.html
*/
// GetItems
$operation = new GetItems();
$operation->setPartnerTag('{Your-partner-tag}')
->setItemIds(['{ASIN}']); // Array|String
// SearchItems
$operation = new SearchItems();
$operation->setPartnerTag('{Your-partner-tag}')
->setKeywords('{Your-keywords}'); // Array|String
// GetVariations
$operation = new GetVariations();
$operation->setPartnerTag('{Your-partner-tag}')
->setASIN('{ASIN}'); // String
// GetBrowseNodes
$operation = new GetBrowseNodes();
$operation->setPartnerTag('{Your-partner-tag}')
->setBrowseNodeIds(['{NodeId}']); // Array|String
Advanced (Custom ressources):
/**
* @see Using setResources() method to set custom ressources,
* Instead of default ressources,
* This can improve response time.
*/
// Set Operation
$operation->setPartnerTag('{Your-partner-tag}')->setKeywords('{Your-keywords}')
->setResources(['Images.Primary.Small','ItemInfo.Title','Offers.Listings.Price']);
- See all available ressources used by setResources() at /docs/ressources.md
Advanced (Custom HTTP Request Client):
use Apaapi\operations\GetItems;
use Apaapi\lib\Request;
use Apaapi\lib\Response;
use Apaapi\includes\RequestClient;
/**
* @see Extending RequestClient: Allows Overriding cURL|Stream Settings,
* Or Using Other Stream Instead.
*/
class MyRequestClient extends RequestClient
{
// ...
}
// Set Operation
$operation = new GetItems();
$operation->setPartnerTag('{Your-partner-tag}')->setItemIds('{ASIN}');
// Prapere Request
$request = new Request('{Your-key-id}','{Your-secrect-key}');
$request->setLocale('{your-region}')->setPayload($operation);
// Set Custom Client After Payload
$request->setClient(
new MyRequestClient($request->getEndpoint(), $request->getParams())
);
// Get Response
$response = new Response($request);
echo $response->get(); // JSON ready for parsing
Advanced (Response Type Helper):
use Apaapi\includes\ResponseType;
/**
* @see Helps generating quick decoded response.
* @param object|array|serialized
*/
// Get Response
$response = new Response($request, new ResponseType('array'));
return $response->get(); // Array ready to be used
use Apaapi\includes\ResponseType;
/**
* @see Helps parsing response.
* @param Response::PARSE
*/
// Get Response
$response = new Response($request, new ResponseType('object'), Response::PARSE);
return $response->get(); // Object ready to be used
Advanced (Response Errors):
/**
* @see Error catching.
*/
// Get Response
$response = new Response($request);
$data = $response->get(); // JSON error ready for parsing
if ( $response->hasError() ) {
/**
* @param bool $single error
* @return mixed
*/
echo $response->getError(true); // Parsed error
}
Add to cart:
// Set Cart
$cart = new Cart();
$cart->setLocale('{Your-locale}');
$cart->setPartnerTag('{Your-partner-tag}');
// Set Items
$items = [
'{ASIN1}' => '3', // ({ASIN} => {Quantity})
'{ASIN2}' => '5'
];
// Get Response
return $cart->add($items); // String URL
Contributing:
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
Versioning:
We use SemVer for versioning. For the versions available, see the tags on this repository.
Authors:
- Jihad Sinnaour - Jakiboy (Initial work)
See also the full list of contributors who participated in this project. Any suggestions (Pull requests) are welcome!
License:
This project is licensed under the MIT License - see the LICENSE file for details.
⭐ Support:
Please give it a Star if you like the project.
💡 Notice:
- The Amazon logo included in top of this page refers only to the Amazon Product Advertising API V5.
- All available use case examples located in /examples.