mcc script

154 views
Skip to first unread message

Noor Digitalbyrå 1

unread,
Jan 6, 2023, 10:19:04 AM1/6/23
to Google Ads Scripts Forum
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!



InputError: Invalid input: 472-669-2312. Expected a ManagedAccount or an Account at oa.check (adsmanagerapp_compiled:172:11) at Xh.select (adsmanagerapp_compiled:2811:19)




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

   


     
    }
  }
}

Google Ads Scripts Forum

unread,
Jan 10, 2023, 12:08:31 AM1/10/23
to Google Ads Scripts Forum
Reposting the last inquiry (https://groups.google.com/g/adwords-scripts/c/5r-UtDRKAoI) from the forum as it wasn't routed to our support queue. 

Cheers, 
James
Google Ads Scripts Team

Google Ads Scripts Forum

unread,
Jan 17, 2023, 1:55:22 AM1/17/23
to Google Ads Scripts Forum
Reposting the last inquiry (https://groups.google.com/g/adwords-scripts/c/5r-UtDRKAoI) from the forum as it wasn't routed to our support queue. 

Cheers, 
James
Google Ads Scripts Team

Google Ads Scripts Forum

unread,
Jan 17, 2023, 1:59:57 AM1/17/23
to Google Ads Scripts Forum
Hello,

I’m James, a part of the Google Ads Scripts Team. Thank you for reaching out to us.

Can you please provide us the following items below so that we can further check?
  • Google Ads account ID / CID wherein the given code is implemented
  • Script name

Regards,
James
Google Ads Scripts Team

Noor Digitalbyrå 1

unread,
Jan 23, 2023, 9:01:37 AM1/23/23
to Google Ads Scripts Forum
4726692312 is our mcc id.

what I want to do is having a script in mcc level.
That can take new keywords from a spreedsheet from a specific customer.

Now i have solved and it works when i add the code in the customers script but i want it in my mcc account.
And i cant get it to work

Google Ads Scripts Forum

unread,
Feb 9, 2023, 6:56:55 AM2/9/23
to Google Ads Scripts Forum
Reposting the last inquiry (https://groups.google.com/g/adwords-scripts/c/5r-UtDRKAoI) from the forum as it wasn't routed to our support queue.

Regards,
Yasmin
Google Ads Scripts Team

Google Ads Scripts Forum

unread,
Feb 14, 2023, 5:23:28 AM2/14/23
to Google Ads Scripts Forum
Reposting the last inquiry (https://groups.google.com/g/adwords-scripts/c/5r-UtDRKAoI) from the forum as it wasn't routed to our support queue.

Regards,
Yasmin
Google Ads Scripts Team

Google Ads Scripts Forum Advisor

unread,
Feb 14, 2023, 6:43:36 AM2/14/23
to adwords...@googlegroups.com

Hi,

 

This is Yasmin from the Google Ads Scripts Team. Please excuse us for only getting back now as your message failed to be routed to our support queue.

 

You can follow this guide from our documentation on how to Work on client accounts in order to implement the script at the MCC level. Once you've retrieved the client accounts, you can iterate through them using the iterator's hasNext and next methods. You need to use the select method to switch the execution context to a client account. After you select a client account, any further API calls apply to the client account until you explicitly select another account.

 

As an aside, for guides on how to work with Ads Manager Scripts, you can check the full documentation.

 

Let us know if you encounter any issues.

 

Best regards,

 

Google Logo
Yasmin Gabrielle
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2izyLX:ref
Reply all
Reply to author
Forward
0 new messages