To add an array of $keywords to my ad group I am currently using the following code:
$adGroupCriterionService = $adwordsUser->GetService('AdGroupCriterionService', 'v201109');
$operations = array();
foreach ($keywords AS $keyword) {
$keywordobj = new Keyword();
$keywordobj->text = $keyword;
$keywordobj->matchType = 'BROAD';
$keywordAdGroupCriterion = new BiddableAdGroupCriterion();
$keywordAdGroupCriterion->adGroupId = $identifier;
$keywordAdGroupCriterion->criterion = $keywordobj;
$keywordAdGroupCriterionOperation = new AdGroupCriterionOperation();
$keywordAdGroupCriterionOperation->operand = $keywordAdGroupCriterion;
$keywordAdGroupCriterionOperation->operator = 'ADD';
$operations[] = $keywordAdGroupCriterionOperation;
}
$result = $adGroupCriterionService->mutate($operations);
This works fine. However, I’ve started to realise that doing such operations uses up API Units rather more quickly than I had anticipated. Is there a more API Unit friendly approach to doing this operation? Or is this simply the ‘catch’ with the Google Adwords API pricing?
Depending on how many keywords you’re uploading at a time, you can use the MutateJobService; the coding is a little more complicated but you should save 50% of the unit cost.