API requests

This page contains information about ASA 2 PHP functions you can use in your scripts to manually send requests to the Amazon Product Advertising API.

Asa2_Service::itemLookup

This method lets you work directly with an ASA 2 item object. You can access all placeholder keys as public properties.

Description

<?php
$item = Asa2_Service::itemLookup( $asin [, array $options] );

Parameters

asin
The ASIN of the product you want to render
options

An array of Options (same as for the [asa2] shortcode).

  • ajax Set to 1 activate the AJAX mode
  • country_code The product’s country code
  • no_cache Set to 1 to bypass the cache
  • tpl The template name
  • tplid The template ID
  • tracking_id Custom tracking ID

Examples

Based on the custom field “asin” this code tries to create an ASA 2 item object by using Asa2_Service::itemLookup(). You can check if the result is a valid object by using Asa2_Service::isItem().

On a valid item object you can access all Placeholders as public properties. For example, if you want to access the item’s title, known as placeholder {{ Title }}, use $item->Title.

<?php
// get ASIN from custom field
$asin = get_post_meta($post->ID, 'asin', true);

if (!empty($asin)) {

    $tplid = get_post_meta($post->ID, 'tplid', true);

    $options = array();
    if (!empty($tplid)) {
        $options['tplid'] = $tplid;
    }

    $item = Asa2_Service::itemLookup($asin, $options);

    if (Asa2_Service::isItem($item)) {
        // it is an ASA 2 item object

        echo '<h1>' . $item->Title . '</h1>';
        printf('<img src="%s" width="%d" height="%d">', $item->SmallImageURL, $item->SmallImageWidth, $item->SmallImageHeight);
        echo 'List price: ' . $item->ListPriceFormattedPrice . '<br>';
        echo 'Current price: ' . $item->OffersMainPriceFormattedPrice . '<br>';
        echo $item->CustomerReviewsImgTag;
    }
}