PHP code example of jakiboy / apaapi

1. Go to this page and download the library: Download jakiboy/apaapi library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jakiboy / apaapi example snippets




/**
 * @see You can use Composer, 
 * Or e 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



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



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



use Apaapi\operations\GetItems;
use Apaapi\lib\Request;
use Apaapi\lib\Response;
use Apaapi\her 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



use Apaapi\e 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\e 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



/**
 * @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
}



// 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