Why can't I add keywords to my adGroup it says newKeywordBuilder is not a function of adGroup

42 views
Skip to first unread message

Dan Savage

unread,
Aug 9, 2023, 4:51:15 AM8/9/23
to Google Ads Scripts Forum

This script will add an ad group to my campaign but will not add the keywords or ads.
It gives me an error of 
newKeywordBuilder is not a function of adGroup. 

I'm following the documentation so not sure what is going on. It does successful add the adgroup to the campaign but then gives the error.

function main() {
  // Specify the campaign name where you want to upload the ads
  var campaignName = ' myCampaign 1';

  // Specify the CPC bid in cents (11 cents in this case)
  var cpcBidInDollars = .05;

  // Array of ad data containing headlines, descriptions, and URLs
  var adData = [{
"headlines": [
"Headline1",
"Headline2",
"Headline3",
"Headline4"
],
"descriptions": [
"descr 1.",
"descr 2"
],
"finalUrl": "https://website.com",
"keywords": [
"keywords phrase"
]
}
  ];
 




  // Create ads from the ad data array
 var campaign = AdsApp.campaigns().withCondition("Name = '" + campaignName + "'").get().next();

  // Create adgroup from the ad data array
  for (var i = 0; i < adData.length; i++) {
    var adGroup = campaign.newAdGroupBuilder()
      .withName('Ad Group ' + (i))
       .withCpc(.05)
  .build();
 
  var keywordOperation = adGroup.newKeywordBuilder()
   .withText(adData[i].keywords[0])
   .withCpc(.05)
   .build();
   

    var adOperation = adGroup.newAd().responsiveSearchAdBuilder()
  .withHeadlines(adData[i].headlines)
  .withDescriptions(adData[i].descriptions)
  .withFinalUrl("https://treatmentminer.com")
  .build();
  }

}
Reply all
Reply to author
Forward
0 new messages