Making REST 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.

Topics

Amazon Associates Web Service REST requests are URLs, for 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 example above 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

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.

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 first two lines identify the request submitter. The first line is required; every request must contain an AWS Access Key ID, which identifies the submitter. You receive an AWS Access Key ID when you sign up with Amazon Associates Web Service.

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

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.

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.

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.

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.

Request parameter values are set using the format:

ParameterName=value

For example,

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