To utilize the new feature you’ll need to set this extra SOAP header:
partialFailure = true
Here’s an example from the Java client library:
// usual initialization code
AdWordsUser user = new AdWordsUser();
// Enable partial failure
user.setUsePartialFailure(true);
// Get the AdGroupCriterionService
AdGroupCriterionServiceInterface adGroupCriterionService =
user.getService(AdWordsService.V201008.ADGROUP_CRITERION_SERVICE);
// Set up operations and operands here
List<AdGroupCriterionOperation> operations = new ArrayList<AdGroupCriterionOperation>();
// [...]
// Execute operations (add ad group criteria)
AdGroupCriterionReturnValue result =
adGroupCriterionService.mutate(operations.toArray(
new AdGroupCriterionOperation[] {}));
Now processing succeeded results:
// Display results
if ((result != null) && (result.getValue() != null)) {
// A result is returned for every operation requested
for (AdGroupCriterion adGroupCriterionResult : result.getValue()) {
// Successful operation result will contain a non-null Criterion
if (adGroupCriterionResult.getCriterion() != null) {
System.out.printf("Ad group criterion with ad group id '%d', and " +
"criterion id '%d', and keyword '%s' was added.\n",
adGroupCriterionResult.getAdGroupId(),
adGroupCriterionResult.getCriterion().getId(),
((Keyword) adGroupCriterionResult.getCriterion()).getText());
}
}
} else {
System.out.println("No ad group criteria were added.");
}
Here is how to handle the failed operations:
// Is there any Partial Failure errors in the results?
if ((result != null) && (result.getPartialFailureErrors() != null)) {
// Retrieving ApiError object for each of failures
for (ApiError apiError : result.getPartialFailureErrors()) {
// The order of the fields might be different to the order of operations in the
// request, so we are getting the corresponding operation index from the fieldPath.
Matcher matcher = operationIndexPattern.matcher(apiError.getFieldPath());
if (matcher.matches()) {
int operationIndex = Integer.parseInt(matcher.group(1));
AdGroupCriterion adGroupCriterion =
operations.get(operationIndex).getOperand();
System.out.printf("Ad group criterion with ad group id '%d' and " +
"keyword '%s' triggered a failure for the following reason: '%s'.\n",
adGroupCriterion.getAdGroupId(),
((Keyword) adGroupCriterion.getCriterion()).getText(),
apiError.getErrorString());
} else {
System.out.printf(
"A failure for the following reason: '%s' has occurred.\n",
apiError.getErrorString());
}
}
}
Partial Failure is fully supported in our client libraries. If you have any questions please post them on the AdWords API forum. This topic is also covered in a video presentation.
-- Danial Klimkin, AdWords API Team.
