Adding Bulk Campigns, AdGroups and Keywords

64 views
Skip to first unread message

pcj

unread,
Apr 2, 2015, 10:11:47 AM4/2/15
to adwor...@googlegroups.com
Hi 

  I am developing app in java where I need to Add Campaigns within those Campaigns AdGroups, and for those AdGroups their repesctive keywords. So fo adding Ad Group we need Campaign ID, and for adding keywords need AdGroup ID.

So for now I am doing like this : 

  First Adding Batch of Campiagns like below :
   CampaignOperation[] campaignOperations = new CampaignOperation[ ] { cOp1, cOp2, cOp3};
    // Add campaigns.
   CampaignReturnValue addResult = campaignService.mutate(campaignOperations);

   // Retriving IDs for added campians

  Then I Add AdGroups To Respective Campaigns using Campaign IDs I got, as below :

    AdGroupOperation[] adAdGroupsOperations = new AdGroupOperation[] { cOp1AdGrp1, cOp1AdGrp2, cOp1AdGrp3,                 cOp2AdGrp1, cOp2AdGrp2, cOp3AdGrp1,};

    // Add ad groups.
    AdGroupReturnValue result = adGroupService.mutate(adAdGroupsOperations);

    // I retriev Group IDs here 

  Then I Add Keywords To Respective AdGroups using AdGroup IDs I got, as below :

  AdGroupCriterionOperation[] keywordsOperations = new AdGroupCriterionOperation[ cOp1AdGrp1KeywrdOp1,                     cOp1AdGrp1KeywrdOp1, .................., cOp[N]AdGrp[N]KeywrdOp[N];

  // Add keywords.
   AdGroupCriterionReturnValue result = adGroupCriterionService
.mutate(keywordsOperations);

Above code will do like : 

1] Adds Campaigns,
2] Adds AdGroups to respective Campaigns,
3] Adds Keywords to Respective AdGroups,

Now my problem is that if any of these fails I need to roll back,
Is there any way to rollback changes made by perticular session 


OR

Is there any way that I can do like this :
1] Create nested operations

mainOperation {
 CampaignOperation1 {
    AdGroupOperation1, {
      KeywordOperation1,
      KeywordOperation2, 
    }
    AdGroupOperation2, {
      KeywordOperation1,
      KeywordOperation2,
    } 
    AdGroupOperation3, {
      KeywordOperation1,
      KeywordOperation2,
    } 
    AdGroupOperation4, {
      KeywordOperation1,
      KeywordOperation2,
    } 
 },
 CampaignOperation1 {
    AdGroupOperation1, {
      KeywordOperation1,
      KeywordOperation2, 
    }
    AdGroupOperation2, {
      KeywordOperation1,
      KeywordOperation2,
    } 
    AdGroupOperation3, {
      KeywordOperation1,
      KeywordOperation2,
    } 
    AdGroupOperation4, {
      KeywordOperation1,
      KeywordOperation2,
    } 
 }
}

2] And then add these operations in single batch.


Is this possible, and how ? 


Nadine Sundquist (AdWords API Team)

unread,
Apr 2, 2015, 12:04:01 PM4/2/15
to adwor...@googlegroups.com
Hello,

The Adwords API does not have the ability to roll back successful operations or create nested operations. However, the AdWords API does support a feature called Partial Failure where you can submit a collection of operations and do error handling on only the failed operations. The successful operations will commit, but the failed operations will come back to you with an explanation. You can then determine what to do. For example, if one of your campaigns operations fail, you can avoid any operations that rely on that campaign operation. Here's a snippet of the Java code example:

    // Enable partial failure.
    session.setPartialFailure(true);

   
// Do some operations here.

   
// Iterate through the result to see if any of the operations failed.
    for (ApiError apiError : result.getPartialFailureErrors()) {
      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());
      }
    }

Happy coding!
Nadine, AdWords API Team
Reply all
Reply to author
Forward
0 new messages