Jun 022012
Article Perl

(leer este artículo en español)

In a previous post we explained how to develop perl scripts for the automated management of Google AdWords campaings, making use of a perl library that implements the API to access AdWords. During the execution of these scripts, errors of different kinds may happen: network timeouts, rejected parameter values, etc. This post will show how to catch and react to these errors.

The Adwords API Perl library employs the CPAN module SOAP::WSDL to establish the communication between the client and the server (SOAP stands for “Simple Object Access Protocol”, and WSDL stands for “Web Services Description Language”)

In a perl script that works with Adwords campaigns using the Adwords API Perl library, the modifications to be done are performed by issuing calls to the ‘mutate’ method of the service to be accessed (AdgroupService, AdgroupAdService,etc…).

If an error happens while processing the request, the return value from the ‘mutate’ method is an object of type “SOAP::WSDL::SOAP::Typelib::Fault11”.

Therefore, to detect and handle an error, we must just check the type of the returned object, and take the adequate measures in case it is of type ‘Fault11’. In the sample code below we see how this can be done:

Note: When used in scalar context, the value of instances of a Fault11 object is the boolean value “false”. On the other hand, when a Fault11 object is “stringified” is is converted into XML. Taking this into account, the last lines in the sample code can also be written as:

 Posted by at 8:00 pm

  One Response to “How to handle errors from the Adwords API in Perl”

 Leave a Reply