Anatomy of a REST Request (http://docs.amazonwebservices.com/AWSECommerceService/2008-08-19/DG/)

Requests

The Amazon Associates Web Service web service supports REST requests for remotely calling Amazon Associates Web Service operations hosted by Amazon servers. REST requests are simple HTTP requests, using either the GET method with parameters in the URL, or the POST method with parameters in the POST body. The response is an XML document that conforms to a schema.

You might use REST requests because they are more intuitive than their SOAP counterpart or because a SOAP toolkit is not available for your platform. The example requests used throughout this guide are in REST.

Anatomy of a REST Request

Amazon Associates Web Service REST requests are URLs, as shown in the following example.

http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&Operation=ItemSearch&
AWSAccessKeyId=[Access Key D]&AssociateTag=[ID]&SearchIndex=Apparel&
Keywords=Shirt

If you substituted real IDs in this request and put the entire example in a browser, you would be sending Amazon Associates Web Service a request.

Although the preceding example is in the form you'd enter the request into a browser, it is difficult to read. For that reason, this guide would present the same request as follows.

http://ecs.amazonaws.com/onca/xml?
Service=AWSECommerceService&
Operation=ItemSearch&
AWSAccessKeyId=[Access Key ID]&
AssociateTag=[ID]&
SearchIndex=Apparel&
Keywords=Shirt

General Request Format

Part of every Amazon Associates Web Service request is the same, the other part of the request changes according to the parameters used in the request, as shown in the following figure.

Request Terms that Remain the Same

The first two lines in the preceding example contain the endpoint, http://ecs.amazonaws.com/onca/xml, and the service name, AWSECommerceService.

Amazon hosts many web services in addition to Amazon Associates Web Service, including Mechanical Turk and S3. The service name in the request specifies that the request should be sent by the web servers to Amazon Associates Web Service. This line is always the same in every Amazon Associates Web Service request, regardless of locale.

Service=AWSECommerceService&

The endpoint value varies by locale but there are only two endpoints per locale. One endpoint in a locale is the secure version of the other endpoint. The following table lists the endpoints to use in Amazon Associates Web Service requests.

LocaleEndpoint
CA

http://ecs.amazonaws.ca/onca/xml

https://aws.amazonaws.ca/onca/xml

DE

http://ecs.amazonaws.de/onca/xml

https://aws.amazonaws.de/onca/xml

FR

http://ecs.amazonaws.fr/onca/xml

https://aws.amazonaws.fr/onca/xml

JP

http://ecs.amazonaws.jp/onca/xml

https://aws.amazonaws.jp/onca/xml

UK

http://ecs.amazonaws.co.uk/onca/xml

https://aws.amazonaws.co.uk/onca/xml

US

http://ecs.amazonaws.com/onca/xml

https://aws.amazonaws.com/onca/xml

The endpoint remains the same for all Amazon Associates Web Service requests, as shown in the following example.

http://ecs.amazonaws.com/onca/xml

The third and fourth lines identify the request submitter. The AWSAcessKey Id is required; it helps identify the request submitter. You receive an AWS Access Key ID when you sign up with Amazon Associates Web Service.

Also included in every request is a signature. This is an SHA-1 encrypted value created using the developer's Secret Access Key, which given to every developer once they sign up to become an Associate. Because the AWS Access Key ID is sent in the clear, it cannot be used as the sole identity for authenticating the request. Instead, the AWS Access Key ID is used by the Amazon Associates Web Service to look up the Secret Access Key associated with it. If that value matches the one encrypted in the request's signature parameter, the request is processed.

The other identifier, AssociateTag, is optional. It is an ID for an Associate. If you are an Associate, you must include your Associate tag in each request to receive a referral fee for a customer's purchase.

Request Terms that Change

The remaining terms in the request vary significantly according to the operation chosen. The terms, however, follow a pattern, as shown in the next figure.

The Operation parameter is required. Its value is one of the Amazon Associates Web Service operations. These operations are described throughout this guide and in the Amazon Associates Web Service API Reference Guide.

The last lines, operation parameters, are representative of parameters that the operation requires, and optional parameters that the operation can use. Requests can contain zero or more operation (up to ten) parameters. These parameters are described in the discussion of each operation in the Amazon Associates Web Service API Reference Guide.

Response Groups

A special parameter that is optional for all Amazon Associates Web Service operations is ResponseGroup. Response groups control the kind of information returned by the request. For example, the Large response group returns a great deal of information about the items included in a response, whereas the Medium and Small response groups return less.

Besides these generic response groups, there are very specific ones. For example, if you want to return images of the items included in a response, you would include the Image response group in the request. If you wanted pricing information, you would include the Offer response group in the request. To get browsenode information, you'd include the BrowseNode response group. The specificity of the response groups enables you to return only the information you want.

Each Amazon Associates Web Service operation can only work with a subset of all Amazon Associates Web Service response groups. The valid response groups that each Amazon Associates Web Service operation can use is listed in the Amazon Associates Web Service API Reference Guide.

All Amazon Associates Web Service operations use some response group by default. So, specifying additional response groups is optional. Every Amazon Associates Web Service operation uses the Request response group, which echoes operation name and the input parameters sent in the request. The other response groups used by default vary by the operation. For example, CartCreate, CartAdd, and CartModify use, by default, the Cart response group, which provides detailed information about the items in a cart. The API Reference Guide lists the default response groups used by each operation.

Now, when you read requests in this guide, your eye should jump to the Operation parameter and all of the required and optional parameters associated with the specified Amazon Associates Web Service operation.

Request Limitations

Some Amazon Associates Web Service operations have many parameters and, as you will learn in a future section, you can combine multiple single requests in one, longer batch request. The upper limit is bounded by the maximum number of characters that can be in a request. The maximum number differs by browser. For example, the limit for a URL in Microsoft's Internet Explorer is a little more than 2000 characters. It would be unusual to have a request that approached this upper boundary.

REST Syntax

One of the values of using REST is that its syntax is simple, which makes REST requests easy to read. This section summarizes all of the REST syntax rules that you must keep in mind when creating a REST request.

Spaces in Requests

Because a REST request is a URL, there can be no spaces between the parts of a request. A browser will stop reading when it runs across the first space. For example, if the last parameter read, Keywords=Blue Shirts, the request would end on "Blue." "Shirts" would never be read. If you have key words, such as names, that do have spaces in them, you must URL-encode the space using %20. For the preceding example to work, you would include a URL-encoded space, as follows.

Keywords=Blue%20Shirts

The same problem occurs if you put spaces between the parameters in a request, as shown in the following example.

SearchIndex=Apparel& Keywords=Shirt

In this example, the request would end with "Apparel&." Often, this kind of mistake returns an error because parameters required by the operation are not read. So, make sure to remove all spaces within a request.

Separator Characters

The question mark (?) and ampersand (&) separate the terms in a REST request. The first term in the request must always be the endpoint, which, in the preceding example, is,http://ecs.amazonaws.com/onca/xml. A question mark always follows the endpoint. The question mark tells the Amazon Associates Web Service web servers to start parsing the request for parameters.

Ampersands separate all of the other parameter name-value pairs in the request. The order of the parameter name-value pairs is inconsequential, as long as they all occur after the question mark.

Setting Parameter Values

Request parameter values are set using the format.

ParameterName=value

The following example is a parameter/value pair.

Operation=ItemSearch

Parameter values must be URL-encoded. There are some characters, such as an asterisk or space, that cannot go into a URL. There are equivalents of these characters that you use in requests instead. For example, the URL encoded equivalent of a space is %20. So, instead of writing Name=John Smith you would write Name=John%20Smith.

Parameter Names and Values are Case Sensitive

Parameter names and values are case sensitive. For example, the following declaration is fine.

SearchIndex=Apparel

The following examples return errors because the capitalization is incorrect.

Searchindex=Apparel
SearchIndex=apparel

As you can see in these examples, parameter names and values start with capitals. If the name or value is a compound word, the beginning of each new word is capitalized, for example, in the parameter name, SearchIndex, the "I" is capitalized.

Compound Parameters

The vast majority of parameters can be specified in a REST request using just the name of the parameter and an appropriate value, with the value URL-encoded to make the request a valid URL, as shown in the following example.

Author=Steve%20Davenport

Some parameters, however, can be repeated in a request. In that case, the parameter names are differentiated by adding a period (.) after the parameter name and then a sequence number, as shown in the following example.

Item.1=1234&
Item.2=2345

Other parameters can be repeated but, in addition, have associated parameters. These parameters extend the preceding example by adding another period and the associated parameter name, as shown in the following example.

Item.1.ASIN=3456789123&
Item.1.Quantity=2

In this example, the item being added to a shopping cart has an identifier, the ASIN, and a quantity value. The equivalent expression in an XML document is, as shown in the following example.

<Item>
  <ASIN>3456789123</ASIN>
  <Quantity>2</Quantity>
</Item>

The sequence number associates the identifier and its quantity value. The following example shows two compound parameters.

Item.1.ASIN=3456789123&
Item.1.Quantity=2&
Item.2.ASIN=123456&
Item.2.Quantity=1

The sequence numbers associate the ASIN and quantity values. This means that the compound parameters can be written in a different order without causing a problem.

Item.1.ASIN=3456789123&
Item.2.ASIN=123456&
Item.1.Quantity=2&
Item.2.Quantity=1

Batch and Multiple Operations Requests

The requests presented so far contain only one operation. Amazon Associates Web Services enables you to improve performance by submitting more than one request at the same time. There are three ways to do this:

  • Batch request—A request that uses one operation with up to two sets of parameters.

  • Multiple operations request—A request contains more than one operation. This kind of request can combine simple and batch requests.

  • Multiple ItemIds—In an ItemLookup request, you can include up to ten comma-separated values for ItemId.

Batch Requests

There might be times when you want to use the same operation in two requests, each one using different input parameters. For example, you might want to run an ItemLookup request several times, each time looking up a different item. To accomplish this task, you can submit two requests or one batch request.

The following figure shows how two simple requests can be combined into one batch request.

The new syntax introduced in the batch request centers on the ways in which the operation parameters are defined. Either the parameter values are different or they are shared between the simple requests in the batch request.

Batch requests can contain up to two sets of parameters.

[Note]Note

The Amazon Associates Web Service supports ItemLookup batch requests only when the ItemType is an EAN (European Article Number), ISBN (International Standard Book Number), or ASIN (Amazon Standard Item Number ).

Parameters That Differ

Parameters that differ between the simple requests in a batch request are identified by a reference number. The following parameter declaration syntax shows where the reference number goes.

OperationName.ReferenceNumber.Parameter=Value

The following request snippet shows an example of a reference number, 1.

ItemLookup.1.ItemId=0976925524

The ReferenceNumber is a positive integer that associates the parameters in the simple request. For example, the following parameters are part of the same simple request because they use the same reference number.

ItemLookup.1.ItemId=0976925524&
ItemLookup.1.ResponseGroup=Images

These parameters might be different from a second simple request, which is part of the same batch request.

ItemLookup.2.ItemId=0485935524&
ItemLookup.2.ResponseGroup=Collections

So, if the previous two request snippets were part of one batch request, the ItemLookup operation would be executed twice, each time with a different ItemId and ResponseGroup.

In one batch request, you can have up to two different reference numbers. For example, the following request snippet exceeds the number of allowed reference numbers in one batch request.

ItemLookup.1.ItemId=0976925524&
ItemLookup.2.ItemId=0485935524&
ItemLookup.3.ItemId=0792335535&
                
Shared Parameters

There are times when the parameter values for the simple requests in a batch request are the same, for example, ItemType=ASIN. In this case, instead of using a ReferenceNumber for each simple request, you can substitute the special value, "Shared,", as shown in the following example.

ItemLookup.Shared.ItemType=ASIN

The following parameter declarations show the equivalent of the preceeding declaration.

ItemLookup.1.ItemType=ASIN&
ItemLookup.2.ItemType=ASIN

Both forms of the request work but using the special value, Shared, reduces the amount of typing required. Generally, you only use the Shared value with required parameters. Optional parameters do not need to be included in the request and their default values, if any, are assumed and thus shared across the simple requests in the batch request.

Performing Multiple ItemLookups in One Request

The other way to execute multiple ItemLookup requests in one request is to use a comma-separated list of ItemIds, for example:

http://ecs.amazonaws.com/onca/xml?
Service=AWSECommerceService&
AWSAccessKeyId=[AWS Access Key ID]&
Operation=ItemLookup&
ItemId=B00008OE6I,B35987036I,B0002546I,B25468OE6I,B09788OE6I,B00453OE6I&
IdType=ASIN&
ResponseGroup=OfferFull&
Condition=All&
MerchantId=All    

The preceding example shows six ItemIds in the request, which means ItemLookup will be executed six times, one for each ItemId. You can specify up to ten ItemIds.

[Tip]Tip

Be careful not to introduce spaces before or after the commas in the comma-separated list of ItemIds.

Multiple Operation Requests

Amazon Associates Web Service requests can include up to two operations. These requests, called multiple operations requests, can be a combination of any number of simple and/or batch requests. The following figure shows how two simple requests can be combined into one multiple operations request, as shown in the following example.

The syntax to declare parameters in a multiple operations request is the same as it is in a batch request. A multiple operations request differs from a batch request in the definition of the Operation parameter. In a multiple operations request, the value of Operation is set to two, comma-separated operations.

Multiple operations requests can have only two different operations. One operation in the request, however, can be used as a batch operation so that it is used more than once. Extending the previous example, a valid multiple operations request could be as follows.

In this request, ItemLookup is called twice and SellerLookup is called once.

Parameters Common to All Amazon Associates Web Service Requests

Amazon Associates Web Service operations use a variety of required and optional parameters. The API Reference Guide describes the parameters that each operation can use.

There are, however, a number of parameters that all operations can use. These parameters can be grouped into types.

The following sections describe these parameter types.

Required Parameters

The parameters in the following table are required in every request.

ParameterValueDescription
Service AWSECommerceService Specifies the Amazon Associates Web Service service
AWSAccessKeyId Your Amazon-assigned Access Key ID To register for an Access Key ID from the Amazon Web site, go to http://aws.amazon.com. Every Amazon Associates Web Service 4.0 request must contain either an Access Key ID or a Subscription ID but not both.
SubscriptionId Your Amazon-assigned subscription ID Every Amazon Associates Web Service 4.0 request must contain either an Access Key ID or a Subscription ID but not both. Starting with version 2005-10-05, Amazon Associates Web Service stopped distributing Subscription IDs. If you already have one, it will continue to work.
OperationOperation you wish to perform, for example, ItemLookup One of the Amazon Associates Web Service operation types.

Related Topics

General, Optional Parameters

The parameters in the following table can be used optionally in any Amazon Associates Web Service request.

ParameterValueDescription
AssociateTagAn Amazon-assigned Associate ID The AssociateTag enables product URLs returned by Amazon Associates Web Service to be tagged as originating from your Associates Web site. To receive a referral credit for a sale, you must include an AssociateTag value in a CartCreate request. Be sure to specify the value correctly; no error is generated for incorrect values.
MerchantIdAn alphanumeric token assigned by Amazon to a merchant. MerchantId can have three settings: All, in which all merchants are included in the response, an alphanumeric identity that specifies a single merchant, or "FeaturedBuyBoxMerchant," which returns the merchant identified as the “Buy Box Winner” on a specific detail page. The "Buy Box Winner" is the merchant associated with the sale of the item listed in the Buy Box, which is the box on an item's detail page that enables you to add an item to a shopping cart. The default value for MerchantId is “Amazon.”
ResponseGroup VariousSpecifies what subset of data to return. The API Reference Guide specifies the response groups that can be used with each operation..
Version VariousVersion of the Amazon Associates Web Service 4.0 WSDL. The default is 2005-10-05. If you want another version, including the latest, you must specify it in your request.

XSL Parameters

If you are using an XSL stylesheet to specify the output returned by Amazon Associates Web Service, you may need to include some or all of the following (optional) parameters.

ParameterValueDescription
Style "XML", the default, or the URL of an XSL stylesheet The Style parameter applies to REST requests only. Use the Style parameter to control the format of the data returned by Amazon Associates Web Service. Set this parameter to "XML" to generate a pure XML response. Set this parameter to the URL of an XSL stylesheet to have Amazon Associates Web Service transform the XML response to another format you specify.
ContentType "text/xml", the default, or "text/html"The ContentType parameter is valid for REST requests only. The ContentType set in your request is returned as the content type in the HTTP headers of the response that Amazon Associates Web Service returns. Generally ContentType should only be changed when it is being used in conjunction with an XSLT stylesheet specified with the Style parameter. When you use a stylesheet to transform your Amazon Associates Web Service response to HTML, set this parameter to text/html.

For more information, go to Transforming Amazon Associates Web Service Responses into HTML Using XSLT

XML-Encoding Parameters

Another optional parameter is provided, that you may need in some environments, as described in the following table.

ParameterValueDescription
XMLEscaping "Single", the default, or "Double"XMLEscaping specifies whether responses are XML-encoded in a single pass or a double pass. By default, XMLEscaping is "Single," and Amazon Associates Web Service responses are encoded only once in XML. For example, if the response data includes an ampersand character (&), the character is returned in its regular XML encoding (&). If XMLEscaping is "Double," the same ampersand character is XML-encoded twice (&amp;). The Double value for XMLEscaping is useful in some clients, such as PHP, that do not decode text within XML elements.

Debugging Parameters

Process to Debut a Request

1Use the Validate parameter described in the following table.

ParameterValueDescription
Validate"False", the default, or "True"Use the Validate parameter to have Amazon Associates Web Service test your request without actually executing it. When present, Validate must equal "True." If the request is valid, the response will contain an element called IsValid with a value of True. If the request is invalid, the response will contain 1) an element called IsValid with a value of False and 2) the errors that would be returned if the request were actually executed. Notes: Since the request is not actually executed, only a subset of the errors for the request may be returned. This is because some errors (e.g., no_exact_matches) are only generated during execution of a request.

We also recommend that you include the Request response group for help with debugging. The Request response group echoes back the parameters used to generate the response and allows you to verify that your request was received correctly.

Help with Operations and Response Groups

The Amazon Associates Web Service operation, Help, returns all of the required and optional input parameters for Amazon Associates Web Service operations, and all of the item attributes returned by Amazon Associates Web Service response groups. For example, to see the parameters for CartAdd , use the following request.

http://ecs.amazonaws.com/onca/xml?
Service=AWSECommerceService&
AWSAccessKeyId=[AWS Access Key ID]&
Operation=Help&
HelpType=Operation&
About=CartAdd

A snippet from the response shows the operation's parameters.

<OperationInformation>
  <Name>CartAdd</Name> 
  <RequiredParameters>
    <Parameter>AssociateTag</Parameter> 
    <Parameter>CartId</Parameter> 
    <Parameter>HMAC</Parameter> 
    <Parameter>Items</Parameter> 
  </RequiredParameters>
  <AvailableParameters>
    <Parameter>AWSAccessKeyId</Parameter> 
    <Parameter>ContentType</Parameter> 
    <Parameter>Marketplace</Parameter> 
    <Parameter>MarketplaceDomain</Parameter> 
    <Parameter>MergeCart</Parameter> 
    <Parameter>Style</Parameter> 
    <Parameter>Validate</Parameter> 
    <Parameter>Version</Parameter> 
    <Parameter>XMLEscaping</Parameter> 
  </AvailableParameters>

HelpType is either "Operation" or "ResponseGroup." The About parameter is set to an Amazon Associates Web Service operation or response group.

Paging and Sorting Through Responses

The only drawback of having so many items at your fingertips is the possibility of receiving too many in a response. Amazon Associates Web Service handles this problem in several ways:

  • Results are returned on page, generally, up to ten results per page

  • The Sort parameter orders results

Paging Through Results

It is possible to create a request that returns many thousands of items in a response. This is problematic for several reasons. Returning all of the item attributes for those items would dramatically impact the performance of Amazon Associates Web Service in a negative way. Also, posting a thousand responses on a web page is impractical.

For that reason, Amazon Associates Web Service developed the strategy of returning results a little at a time. The good news is that you can return any page of results. For example, the first request can return the last page of results. To do that, you have to specify the desired page of results using one of the parameters that enable you to return result pages.

To page through results

  • Use the appropriate paging parameter in the request. Operations have their own paging parameters. For example, the following ItemSearch request uses ItemPage to ask for the fourth page of results.

http://ecs.amazonaws.com/onca/xml?
Service=AWSECommerceService&
AWSAccessKeyId=[AWS Access Key ID]&
Operation=ItemSearch&
Keywords=Potter&
SearchIndex=Books&
ItemPage=4

The following snippet of the response shows that the fourth page of results has been returned.

<ItemSearchRequest>
  <ItemPage>4</ItemPage> 
  <Keywords>Potter</Keywords> 
  <SearchIndex>Books</SearchIndex> 
</ItemSearchRequest>
</Request>
<TotalResults>9729</TotalResults> <TotalPages>973</TotalPages> 

This example shows that 9729 items matched the search criteria. Also, it shows that those results are on 973 (~9729/10) pages. You might try putting in an ItemPage value over 400. If you do, Amazon Associates Web Service returns the following error.

<Error>
  <Code>AWS.ParameterOutOfRange</Code> 
  <Message>The value you specified for ItemPage is invalid. Valid values must be between 1 and 400.</Message> 
</Error>

So, how do you get that 973rd page? You cannot. A better approach is to submit a new request that is more targeted and yields fewer items in the response.

Maximum Number Of Returned Pages

The last example showed that Amazon Associates Web Service returns only so many pages for any one request. This is because performance must be optimized for the tens of thousands of Amazon Associates Web Service developers and customers. For that reason, many Amazon Associates Web Service operations have pagination parameters and associated maximum values, as shown in the following table.

OperationParameter NameMaximum Page Number
ItemLookup VariationPage150
ItemLookup ReviewPage20
ItemLookup OfferPage100
ItemSearch ItemPage400
ListLookup ProductPage30
ListSearch ListPage20
CustomerContentLookupReviewPage10
CustomerContentSearchCustomerPage20

These parameters are defined in the section of the API reference that describes the associated operation.

Sorting Results

The following Amazon Associates Web Service operations have a Sort parameter that arranges results:

  • ItemSearch

  • ListLookup

  • SellerListingSearch

To Sort Results

  1. Consult the appendix, APPNDX_SortValuesArticle Sort Values, to determine available sort values.

    Available sort values vary by locale and search index.

  2. Add the Sort parameter to a request that uses one of the preceding operations.

For example, the following request returns books with "Harry Potter" in their title or description in alphabetical order.

http://ecs.amazonaws.com/onca/xml?
Service=AWSECommerceService&
AWSAccessKeyId=1MEXAMPLEZBG2&
Operation=ItemSearch&
Keywords=Harry%20Potter&
SearchIndex=Books&
Sort=titlerank&
ItemPage=29&
Version=2006-09-13

A small snippet of the response shows that the book titles are returned in alphabetical order.

<Title>Aventuras de Harry Potter, Las</Title> 
...
<Title>Beacham's Sourcebook For Teaching Young Adult Fiction: Exploring Harry Potter</Title> 
...
<Title>Beatrix Potter to Harry Potter: Portraits of Children's Writers</Title> 

Amazon Associates Web Service provides many different sorting criteria, for example, price (high to low, or low to high), salesrank (best to worst selling, or worst to best selling), publication date, review rank, and release date. Valid sort parameters vary by search index, for example, the DigitalMusic search index can be sorted by UploadedDate. That value for Sort would not make sense in the Automotive search index, for example. Sort parameters also differ by locale.

For more information about sort values by locale and search index, see the appendix, ItemSearch Sort Values By Locale.

Default Sort Values

There are many sort values. The majority are not applied unless the Sort parameter is included in the request. There are two sort values, however, that are used by default.

  • For ItemSearch requests that do not use the BrowseNode parameter, results are sorted by Relevance

  • For ItemSearch requests that do use the BrowseNode parameter, results are sorted by BestSeller ranking

Transforming Amazon Associates Web Service Responses into HTML Using XSLT

Perhaps you want to use a different set of tags in Amazon Associates Web Service responses than those that are returned by default. For example, because you want to display responses on a web page, you want to turn the responses into HTML. You have two choices: you can receive the default Amazon Associates Web Service response and then transform it into HTML (or another set of XML tags) or you can tell Amazon Associates Web Service to do the transformation for you so that the result is ready for you to use. To make Amazon Associates Web Service do the work for you, you just need to reference an XSL stylesheet in your Amazon Associates Web Service request.

Amazon Associates Web Service provides an XSLT (Extensible Stylesheet Language Transformation) service to ensure that even novice developers can produce rich content without complex parsing or programming. XSL is an XML-based language for transforming XML tags into HTML or any other set of XML tags. To use the Amazon Associates Web Service XSLT service, the request must be in REST, and the XSL style sheet must be referenced using the Style input parameter.

To transform the response

  • Include the Style parameter in your request.

    The referenced stylesheet must be publically accessible.

For example, the following ItemSearch request specifies the XSLT stylesheet http://ecs.amazonaws.com/xsl/aws4/item-search.xsl.

http://ecs.amazonaws.com/onca/xml?
Service=AWSECommerceService&
AWSAccessKeyId=[AWS Access Key ID]&
Operation=ItemLookup&
IdType=ASIN&
ItemId=B00008OE6I&
ResponseGroup=Large&
Style=http://ecs.amazonaws.com/xsl/aws4/item-search.xsl

XSLT Service URLs

For security reasons, Amazon Web Services use a different set of domains for processing XSLT requests. XSLT requests sent to the standard domains (for example, http://ecs.amazonaws.com) are re-directed. If your web client does not support re-directs, you must send your XSLT requests directly to one of the domains, as shown in the following table.

LocaleURL
CAxml-ca.amznxslt.com
DExml-de.amznxslt.com
FRxml-fr.amznxslt.com
JPxml-jp.amznxslt.com
UKxml-uk.amznxslt.com
USxml-us.amznxslt.com

Creating an XSL Style Sheet

It is beyond the scope of this book to explain in detail how to create an XSL style sheet. To see a sample style sheet, go to http://ecs.amazonaws.com/xsl/aws4/item-search.xsl.

You use "xmlns" to define a namespace prefix at the top of the style sheet. You may name the namespace prefix anything, however, the namespace URL must match the namespace URL that is returned in the Amazon Associates Web Service response. The preceding example uses "aws" as the namespace prefix, as follows.

xmlns:aws="http://xml.amazon.com/AWSECommerceService/2006-09-13">

Once you have created a namespace prefix, use it to match elements in the Amazon Associate Web Service response. For example, if you are trying to match an element called "ItemLookupResponse," and your prefix is "aws," the matching string would be aws:ItemLookupResponse.

The following example shows how and where the namespace prefix should be used.

<xsl:template match="/">
  <xsl:apply-templates select="aws:Items/aws:Item"/>
</xsl:template>
<xsl:template match="aws:Items/aws:Item">
  <tr>
    <td style="border-bottom:C0C0C0 dotted 1px;padding:10px">
      <table cellpadding="0" cellspacing="0" style="width: 90%;padding:5px">
        <tr>
          <xsl:if test="aws:SmallImage/aws:URL">
            <td valign="top" width="50">
              <img>
                <xsl:attribute name="src">
                  <xsl:value-of select="aws:SmallImage/aws:URL" />
                </xsl:attribute>
                <xsl:attribute name="border">0</xsl:attribute>
              </img>
            </td>
          </xsl:if>
          <td valign="top">
            <xsl:value-of select="aws:ItemAttributes/aws:Title" />
            <br />
            <span style="font-size:10px">
              <xsl:if test="aws:ItemAttributes/aws:Author">
                by <xsl:value-of select="aws:ItemAttributes/aws:Author" />
              </xsl:if>
              <xsl:if test="aws:ItemAttributes/aws:Artist">
                by <xsl:value-of select="aws:ItemAttributes/aws:Artist" />
              </xsl:if>
              <xsl:if test="aws:ItemAttributes/aws:Director">
                by <xsl:value-of select="aws:ItemAttributes/aws:Director" />
              </xsl:if>
              <xsl:if test="aws:ItemAttributes/aws:Composer">
                by <xsl:value-of select="aws:ItemAttributes/aws:Composer" />
              </xsl:if>
              <xsl:if test="aws:ItemAttributes/aws:Manufacturer">
                from <xsl:value-of select="aws:ItemAttributes/aws:Manufacturer" />
              </xsl:if>
            </span>
            <br />
            <br />
            <span style="font-size:11px;">
              List Price: <xsl:value-of
                select="aws:ItemAttributes/aws:ListPrice/aws:FormattedPrice" />
            </span>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</xsl:template>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值