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

Retrieving Errors

Typically, you want your application to check whether or not a request generated an error before spending any time processing results. The easiest way to find out if an error occurred is to look for an Error node in the response.

XPath syntax provides a simple way to search for the presence of an Error node, as well as an easy way to retrieve the error code and message. The following code snippet uses Perl and the XML::XPath module to determine if an error occurred during a request. If an error occurred, the code prints the first error code and message in the response.

Copy to clipboard
use XML::XPath; my $xp = XML::XPath->new(xml =>$response); if ( $xp->find("//Error") ) {print "There was an error processing your request:\n", " Error code: ", $xp->findvalue("//Error[1]/Code"), "\n", " ", $xp->findvalue("//Error[1]/Message"), "\n\n"; }