Most v13 services turned off today

Thursday, April 22, 2010


You might remember that six months ago we announced that on April 22, 2010 we would be sunsetting many v13 services. Since then, we’ve posted reminders over the last 100 days right here on the blog. It’s finally April 22, so today we’re sunsetting the following v13 services:

  • CampaignService
  • AdGroupService
  • CriterionService
  • AdService
  • InfoService
  • KeywordToolService
  • SiteSuggestionService
If you’re still using any of these services, you’ll start to see your calls fail with error code 213. Migrate to the v200909 version of the API to avoid failed calls. Review our per-call migration guide to move your applications over to v2009.

Please note that AccountService, ReportService, and TrafficEstimatorService will remain available in version v13 of the API until we’ve provided this functionality in the new API. We’ll give you at least four months to migrate these last three v13 services once their replacements are available.

As always, please ask questions and share your feedback on the developer forum. Our team is happy to answer questions about v2009 and starting today, is no longer supporting questions about the v13 services that we’ve sunset.

– Jason Shafton, Product Marketing Manager

Discover v2009: Error handling

Wednesday, April 14, 2010


As with any programming system, error handling is a critical part of the AdWords API as well. In v13, we used to describe every error by its own error code. While this was simple and handy, the API provided less additional information about the error itself. In v2009, we decided instead to use error types with additional fields to describe the specifics of each error. The new error handling system gives you the type of error (e.g. PolicyViolationError), the cause of error (e.g. the editorial policy that was violated), the field that triggered the error and so forth. In this blog post, I'll cover the v2009 error handling in detail, with focus on v2009 synchronous services.

Error handling in v13 and v2009 APIs

To show the difference in error handling between v13 and v2009, consider the following v13 code to create a campaign.

try {
AdWordsUser user = new AdWordsUser();
CampaignInterface service =
(CampaignInterface) user.getService(AdWordsService.V13.CAMPAIGN_SERVICE);
Campaign campaign = new Campaign();
campaign.setName("New campaign");
campaign.setBudgetPeriod(BudgetPeriod.Daily);
campaign.setBudgetAmount(50L);
campaign = service.addCampaign(campaign);
} catch (ApiException e) {
for (ApiError error : e.getErrors()) {
System.out.println("There is an error on argument " + error.getIndex()
+ ". Error code is " + error.getCode()
+ ", details are \"" + error.getDetail()
+ "\", field is " + error.getField());
}
}

This code generates the following output:

There is an error on argument 0. Error code is 34, details are "Money amount less than CurrencyMinCpc.", field is budget.

The same code in v2009 is given below:

try {
user = new AdWordsUser();
CampaignServiceInterface service = (CampaignServiceInterface)
user.getService(AdWordsService.V200909.CAMPAIGN_SERVICE);
Campaign campaign = new Campaign();
campaign.setName("New campaign");
campaign.setBiddingStrategy(new ManualCPC());
campaign.setBudget(new Budget(BudgetBudgetPeriod.DAILY,
new Money(null, 50L), BudgetBudgetDeliveryMethod.STANDARD));
CampaignOperation operation = new CampaignOperation();
operation.setOperator(Operator.ADD);
operation.setOperand(campaign);
campaign = service.mutate(new CampaignOperation[] {operation}).getValue()[0];
} catch (ApiException e) {
for (ApiError error : e.getErrors()) {
System.out.println("There is an error on argument " + error.getFieldPath()
+ ".");
if (error instanceof BudgetError) {
BudgetError budgetError = (BudgetError) error;
System.out.println("Reason is " + budgetError.getReason());
}
}
}

The code generates the following output:

There is an error on argument operations[0].operand.budget. Reason is NON_MULTIPLE_OF_MINIMUM_CURRENCY_UNIT.

As shown in the code above, v2009 returns an error object derived from ApiError, with an appropriate error reason that gives more insight into why the error occurred. This allows you to write a switch-case to handle error categories and reasons that are significant for your program more elegantly than in v13. Also, the list of exceptions raised by a service are available along with the service documentation. For instance, all the exceptions that can possibly be raised by CampaignService are listed at http://code.google.com/apis/adwords/v2009/docs/reference/CampaignService.html#errors

Retrieving the violating field using FieldPath

FieldPath is another useful item you get from a v2009 error. FieldPath stores the OGNL path to the field that caused the violation. OGNL stands for Object-Graph Navigation Language; it is an expression language for getting and setting properties of objects. You can use it as a debugging aid while developing your application, retrieve the value of the violating field, etc. For instance, the following code shows how to retrieve the value of budget that caused the error using the library from opensymphony.

try {
OgnlContext ognlContext = new OgnlContext();
ognlContext.put("operations", operations);
Object value = Ognl.getValue(error.getFieldPath(), ognlContext);
System.out.println("Violating field is " + error.getFieldPath()
+ " and value is " + value);
} catch (OgnlException e) {
e.printStackTrace();
}

This code will print the output as

Violating field is operations[0].operand.budget and value is 50.

In case you are interested in just the index of the violating operation, you can evaluate it using a simple regex as follows:

public static int getOperationsIndex(String ognl) {
String OPERATIONS_INDEX_REGEX = "^operations\\[(\\d+)\\]";
Matcher m = Pattern.compile(OPERATIONS_INDEX_REGEX).matcher(ognl);
if (m.find()) {
return Integer.parseInt(m.group(1));
} else {
return -1;
}
}

Validating API calls using validateOnly

AdWords API also allows you to validate your API calls to see if the request will generate any errors or not. You can validate any API call by setting the validateOnly SOAP header to true and making the API call as usual. If the request contains errors, you will get ApiError objects. If the request is fine, no errors are thrown, and the API call doesn't perform any action either. In addition to providing a way to validate your API calls, validateOnly is significantly cheaper than normal calls. You can refer to the rate sheet to calculate how many API units a validateOnly call will cost you. For more details on how to use validateOnly headers, you can refer to our blog post here

In our next blog post, we will cover how v2009 error handling works in BulkMutateJobService. We've included support for error handling in all of our client libraries to help get you started, so please try it out and share your feedback with us on the forum.

-- Anash P. Oommen, AdWords API Team

14 days left to migrate to v2009

Thursday, April 08, 2010


If you haven’t migrated to the new v2009 AdWords API yet you have only 14 days left to do so. Developers that don’t migrate by April 22 will experience failed calls to most v13 services. The only v13 services that will remain accessible are AccountService, ReportService, and TrafficEstimatorService.

Have questions about migrating? Review the per-call migration guide, visit the developer forum and follow us on Twitter.

– Jason Shafton, Product Marketing Manager

AdWords Downtime: April 10th, 10am-2pm PDT

Tuesday, April 06, 2010


We'll be performing routine system maintenance on Saturday, April 10th from approximately 10:00am to 2:00pm PDT. You won't be able to access AdWords or the API during this time frame, but your ads will continue to run as normal.

Best,
- Eric Koleda, AdWords API Team 

Discover v2009: Do more with mutate

Thursday, March 25, 2010


In previous versions of the API, services had separate methods for adding, updating, and removing items in an AdWords account. The v2009 version changed this paradigm and combined the functionality into a single method called mutate. The mutate method works on operations, where each operation defines the action to perform (operator) and the item to perform it against (operand).

While it may not be immediately obvious, the mutate method is designed to process many operations in one call. For example, the following method uses the PHP client library to add multiple keywords in one request.

function addKeywords($keywords, $adGroupId, $adGroupCriterionService) {
$operations = array();

foreach ($keywords as $keyword) {
// Create biddable ad group criterion.
$adGroupCriterion = new BiddableAdGroupCriterion();
$adGroupCriterion->adGroupId = $adGroupId;
$adGroupCriterion->criterion = $keyword;

// Create operation.
$operation = new AdGroupCriterionOperation();
$operation->operand = $adGroupCriterion;
$operation->operator = 'ADD';

// Add operation to array.
$operations[] = $operation;
}

// Make mutate request.
$results = $adGroupCriterionService->mutate($operations);

return $results;
}

It’s important to note that performing multiple operations in one request can be substantially faster then performing them one at a time. Making any request to the AdWords API comes with a certain amount of overhead, so performing more work per request can dramatically improve the performance of your application. For example, in a simple test I ran adding 500 keywords in a single request was over 100x faster than performing 500 separate requests.

Also of note is that the operations in a mutate request can contain any mixture of operators and span any number of campaigns, ad groups, etc. That means you can add a keyword to one ad group and update a keyword in a different ad group in the same request.

More information on the mutate method of a service and the operations it supports can be found in the developer documentation, and any questions you have can be posted to the forum.

- Eric Koleda, AdWords API Team

Alert: 30 days before major v13 sunset

Tuesday, March 23, 2010


Attention AdWords API developers: you now have just 30 days to migrate your application to the new AdWords API. On April 22, most v13 services will be sunset. We announced version v200909 on October 22, 2009 and told you that in six months we would sunset most v13 services. If you have not begun migrating your application to v200909, it’s very important that you start right away.

Be sure to follow us on Twitter for the latest news, tips, and tricks about the AdWords API and please post your migration questions to the Developer Forum.

– Jason Shafton, Product Marketing Manager

AdWords Downtime: March 20th, 10am-2pm PDT

Wednesday, March 17, 2010


We'll be performing routine system maintenance on Saturday, March 20th from approximately 10:00am to 2:00pm PDT. You won't be able to access AdWords or the API during this time frame, but your ads will continue to run as normal.

Best,
- Eric Koleda, AdWords API Team