Get all ad groups

17 views
Skip to first unread message

reporting info

unread,
Jun 13, 2023, 10:20:20 AM6/13/23
to Google Ads Scripts Forum
Good morning!
I'm trying to bring  the Ad groups from my account, but the code doesn't work. It doesn't bring me any Ad groups or show me any errors
Account ID: 280-950-0619
Script: Get all ad groups

Google Ads Scripts Forum Advisor

unread,
Jun 16, 2023, 9:07:29 AM6/16/23
to adwords...@googlegroups.com

Hi,

 

Thank you for reaching out to the Google Ads Scripts Forum Channel.

 

Upon checking the script, I would recommend placing the function getAllAdGroups() outside of your main() function and call the former function within the latter. You can refer to the snippet of code below for reference:

function main() {
  
  getAllAdGroups();
    
}
 
function getAllAdGroups() {
    const adGroupIterator = AdsApp.adGroups().get();
    console.log('Total adGroups found : ' + adGroupIterator.totalNumEntities());
    return adGroupIterator;
}

 

As an aside, I would recommend refering to our documentation of the AdGroupSelector <https://developers.google.com/google-ads/scripts/docs/reference/adsapp/adsapp_adgroupselector> for a sample implementation which you may directly implement within your main() function as it can also yield the same results.

 

Let us know if you have any clarifications.

 

This message is in relation to case "ref:_00D1U1174p._5004Q2mCTty:ref"

Thanks,
 
Google Logo Google Ads Scripts Team


Reply all
Reply to author
Forward
0 new messages