I got the script working on client account. But I try modify it and ad it on my mcc and add customers id i got error. Can someone please help me?
I want the scirpt to be on my mcc account but i want to choose what customer i want to use it on. Thanks!
function main() {
MccApp.select("472-669-2312");
// Replace "customerAccountId" with the ID of the customer account
AdWordsApp.currentAccount().withIds(["710-349-9933"]).select();
// Replace "SHEET_URL" with the URL of your Google Sheets document
var sheetUrl = "
https://docs.google.com/spreadsheets/d/1rAbzK5jIX9e9IGsfZjHIGu5Jcs";
// Replace "SHEET_NAME" with the name of the sheet that contains the data
var sheetName = "Sheet1";
// Replace "CAMPAIGN_NAME" with the name of the campaign that you want to modify
var campaignName = "testkampanj charlie ingen budget";
// Use the SpreadsheetApp class to open the Google Sheets document and retrieve the data
var sheet = SpreadsheetApp.openByUrl(sheetUrl).getSheetByName(sheetName);
console.log(sheet); // Print the value of the "sheet" object to the console
var data = sheet.getRange(2, 1, sheet.getLastRow() - 1, sheet.getLastColumn()).getValues();
// Use the AdWordsApp.campaigns() function to select the campaign that you want to modify
var campaignIterator = AdWordsApp.campaigns()
.withCondition("Name = '" + campaignName + "'")
.get();
// Check if the campaign was found
if (campaignIterator.hasNext()) {
// Select the campaign
var campaign = campaignIterator.next();
// Use a loop to iterate through the rows of the data array and add the keywords
for (var i = 0; i < data.length; i++) {
// Get the values from the current row of the data array
var keyword = data[i][0];
var bid = data[i][1];
var matchType = 'PHRASE'; // Set the match type to broad
var adGroupName = data[i][3];
var url = data[i][4];
// Check if the ad group already exists in the campaign
var adGroupIterator = campaign.adGroups().withCondition("Name = '" + adGroupName + "'").get();
if (!adGroupIterator.hasNext()) {
// Create the ad group if it doesn't exist
var adGroup = campaign.newAdGroupBuilder().withName(adGroupName).build();
} else {
// Select the ad group if it exists
var adGroup = adGroupIterator.next();
}
// Create the keyword and set the bid and match type
var keywordBuilder = adGroup.newKeywordBuilder()
.withText(keyword)
// Set the destination URL if it is specified
if (url) {
keywordBuilder.withFinalUrl(url);
}
// Create the keyword
var keyword = keywordBuilder.build();
}
}
}