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();
}
}