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

Checking Request Execution in Product Advertising API

You can check the execution of a request first by examining the IsValid element in each response.

If the element is set to True, the request was executed successfully and you can display the information in the response.

If the value is False, there was an error in the request syntax. You can start troubleshooting the error in the request by viewing the errors returned in the response. The following example error statement shows that the request did not contain a required parameter, ItemId.

Copy
<IsValid>False</IsValid> ... <Error> <Code>AWS.MissingParameters</Code> <Message>Your request is missing required parameters. Required parameters include ItemId.</Message> </Error>

The IsValid element, however, is not always returned when a request fails. For example, if you mistype the name of the operation, Product Advertising API returns the following message, which does not include the IsValid element :

Copy
<Error> <Code>AWS.InvalidOperationParameter</Code> <Message>The Operation parameter is invalid. Please modify the Operation parameter and retry. Valid values for the Operation parameter include ListLookup, CartGet, SellerListingLookup, ItemLookup, SimilarityLookup, SellerLookup, ItemSearch, BrowseNodeLookup, CartModify, CartClear, CartCreate, CartAdd, SellerListingSearch. </Message> </Error>

Although an IsValid value of True specifies that the request was valid and executed, it does not mean that a result was obtained. There may not have been any items that satisfied the search criteria, for example. To check for this condition, either search for the presence of an Error element, or evaluate the value of the TotalItems element. If the value is zero, there are no results to display, as shown in the following example.

Copy
<IsValid>True</IsValid> ... <Error> <Code>AWS.ECommerceService.NoExactMatches</Code> <Message>We did not find any matches for your request.</Message> </Error> ... <TotalResults>0</TotalResults> <TotalPages>0</TotalPages>

Java

Errors can occur at many levels in the XML response. The following example determines if the response contains the element, OperationRequest. This response element is included in every response. If it missing, the response is null. That might happen, for example, if the Product Advertising API web service times out the request. The second error check determines if there is an Items response element in the response.

Copy
assertNotNull("OperationRequest is null", operationRequest ); System.out.println("Result Time = " + operationRequest.getRequestProcessingTime()); for (Items itemList : response.getItems()) { Request requestElement = itemList.getRequest(); assertNotNull("Request Element is null", requestElement);

To do a thorough job of error checking, you would have to evaluate all of the response elements returned to see if they were, in fact, returned. The preceding example provides a template for such code. Including all of that code here would complicate the example beyond the scope of this guide.

C#

The following code snippet verifies that the request was executed successfully. The code checks for a null response.

Copy
//Verify a successful request ItemSearchResponse response = service.ItemSearch(itemSearch); //Check for null response if (response == null) throw new Exception("Server Error - no response received!"); ItemSearchResult[] itemsArray = response.GetItemSearchResult; if (response.OperationRequest.Errors != null) throw new Exception(response.OperationRequest.Errors[0].Message);

Perl

The following code snippet verifies that the request was executed successfully. The code checks for the presence of "Error" in the response.

Copy
#See if "Error" is in the response. if ( $xp->find("//Error") ) { print "There was an error processing your request:\n", " Error code: ", $xp->findvalue("//Error/Code"), "\n", " ", $xp->findvalue("//Error/Message"), "\n\n"; }

PHP

The following code snippet verifies that the request was executed successfully. The code checks for an Error element in the XML response.

Copy
//Verify a successful request foreach($parsed_xml->OperationRequest->Errors->Error as $error){ echo "Error code: " . $error->Code . "\r\n"; echo $error->Message . "\r\n"; echo "\r\n"; }

On this page: