Menu
Product Advertising API
Getting Started Guide (API Version 2013-08-01)

Product Advertising API Processing Overview

In the previous section, you saw that a Product Advertising API response is an XML document. The returned elements and their values depend on the data stored in Amazon's databases and the response groups specified in the request.

A response group tailors the information returned in a response. For example, the Images response group returns the images of items returned in the response. The TopSellers response group returns the top-selling items in a search index. The Product Advertising API Developer Guide lists all of the elements that can potentially be returned by a response group .

The elements returned by a response group are structured. For example, the Item element has several child elements, one of which is Offers, which has a child element, Subtotal, which itself has three child elements: Amount, CurrencyCode, and FormattedPrice, as shown in the following response snippet.

Copy
<Item> <Offers> <Subtotal> <Amount>999</Amount> <CurrencyCode>US</CurrencyCode> <FormattedPrice>$9.99</FormattedPrice>

The parent-to-child succession of structured elements is called an XPath. To parse a result, the Product Advertising API response is turned into an object and then XPaths are used as an efficient means of finding elements and their values.

The following PHP example shows how an XPath is used to display the FormattedPrice value after first making sure there is a value.

Copy
if(isset($current->Item->Offers->Subtotal->FormattedPrice)){ print("<br>Price:" $current->Offers->Subtotal->FormattedPrice);

The similar expression in C# is:

Copy
Label1.Text += "Price: " + Item.Offers.Subtotal.FormattedPrice + "<br />";

Returning additional values just requires the use of different XPaths.

Typically, responses return more than one item. For that reason, the parsing algorithm must iterate through all of the items returned in a response. For example, in PHP:

Copy
foreach($parsed_xml->Items->Item as $current){...}

In C#:

Copy
foreach(Item item in response){...}