Skip to content

API requests

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

Asa2_Service::itemLookup

Deprecated Asa2_Service::itemLookup

Use Php Function Asa2 Item Lookup instead.

asa2_item_lookup

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

Description

php
<?php
$item = asa2_item_lookup( $asin [, array $options] );

API documentation

Check the API documentation page for more details.

Parameters

asin The ASIN of the product you want to render

options An array of Shortcodes Asa2 Options (same as for the Shortcodes 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 the asa2_item_lookup() function. You can check if the result is a valid object by using function asa2_is_item_object().

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
<?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_item_lookup($asin, $options);

    if (asa2_is_item_object($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;
    }
}

ASA2 - The Amazon Affiliate Plugin for WordPress