jakiboy/apaapi

Quick connection to Amazon Affiliate Program using Amazon Product Advertising API v5 Library (APAAPI)

1.1.7 2023-06-14 17:10 UTC

This package is auto-updated.

Last update: 2024-04-24 05:45:10 UTC


README

Amazon Product Advertising API PHP

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();

🔨 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:

⚡ 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

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']);

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: