#!/usr/bin/perl # # Sample AdWords API client code for sending CustomReportJobs to ReportService. # Note that this code requires SOAP::Lite 0.65 or better to work correctly. # # Copyright 2007 Google. use strict; use warnings; use SOAP::Lite; my $url = 'http://adwords.google.com/api/adwords/v9/ReportService?WSDL'; my $namespace = 'https://adwords.google.com/api/adwords/v9'; # Uncomment and fill this in with your login information. # my $email = '...'; # my $password = '...'; # my $useragent = '...'; # my $developerToken = '...'; # my $applicationToken = '...'; # Set up the connection to the server. my $service = SOAP::Lite->service($url); # Disable autotyping. $service->autotype(0); # Uncomment this line to display the XML request/response. # $service->on_debug(sub {print(@_)}); # Register a fault handler. $service->on_fault(\&faulthandler); my @headers = ( SOAP::Header->name('email')->value($email)->uri($namespace), SOAP::Header->name('password')->value($password)->uri($namespace), SOAP::Header->name('useragent')->value($useragent)->uri($namespace), SOAP::Header->name('developerToken')->value($developerToken)->uri($namespace), SOAP::Header-> name('applicationToken')->value($applicationToken)->uri($namespace) ); # Create the new report structure. my $report = { 'name' => 'test', 'aggregationType' => 'Summary', 'startDay' => '2006-10-10', 'endDay' => '2006-12-19', 'campaigns' => 1234567, 'customOptions' => SOAP::Data->value('AveragePosition', 'Clicks', 'Cpc', 'Impressions'), }; # Explicit type information is needed to identify this as a CustomReportJob. my $request = SOAP::Data->name('customReportJob', $report); $request->attr({ 'xsi:type' => 'CustomReportJob', 'xmlns' => $namespace }); # Schedule the report. my $jobId = $service->scheduleReportJob($request, @headers); # Print out the results. print('Job ID: ' . $jobId . '.' . "\n"); # Helper functions. sub faulthandler { my ($soap, $response) = @_; die('SOAP fault: ' . $response->faultstring() . ' For input "' . $response->fault()->{'detail'}->{'fault'}->{'trigger'} . '" (error code ' . $response->fault()->{'detail'}->{'fault'}->{'code'} . ')'); }