How to deal with manager account levels and check to what manager account an account belongs

14 views
Skip to first unread message

Seb

unread,
Mar 6, 2019, 11:39:29 AM3/6/19
to Google Ads Scripts Forum
Hi,

Situation: 
I have a manager account with sub accounts, some of which are manager accounts. They, in turn, also have accounts below them, some of which might also be manager accounts etc. Now, for the first layer, there are specific manager accounts I would like to get all the sub accounts of. Then, for each sub account, I want to check to which manager they belong and if they are also manager accounts. If so, check all the sub accounts and do the same up until the bottom layer, so that I can create reports for each account and include in the report to which manager account it belongs. I have been looking through the docs for hours, but unfortunately I was unable to find the syntax for certain parts of this problem, mainly how to check to what manager account an account belongs.

Code:

function getAccounts() {
  var masterAccount = AdsApp.currentAccount(),
      masterName = masterAccount.getName(),
      accountIterator = AdsManagerApp.accounts().get();
  
  while(accountIterator.hasNext()) {
    var account = accountIterator.next(),
        name = account.getName(),
        id = account.getCustomerId();
        //for current account, get manager account name + id 
        //make report for account
  }
  AdsManagerApp.select(masterAccount); 
}

Remarks
Now, I don't actually want to get all of the accounts. Ideally I would: 

- Define id's of top layer manager accounts 
- At the top layer, get all manager accounts with the defined id's. (In other words, I only want to get all accounts of certain manager accounts)
- For each of these manager accounts, get all the accounts.
- For each of these accounts, get the name, id, and to what manager account it belongs.
- Create a report for each account that is not a manager account.

I don't think this is actually possible in the way I described so I would need a creative solution. Hopefully someone will be able to help me out here!

Kind regards,

Seb 






googleadsscrip...@google.com

unread,
Mar 6, 2019, 4:06:11 PM3/6/19
to Seb via Google Ads Scripts Forum, Google Ads Scripts Forum
Hi Seb,

While there is no method to see what manager account an account belongs to, you can use a withCondition on the ManagerCustomerId and CanManageClients fields to get data on sub accounts. Once you iterate through accounts, you can either use getStatsFor or an Account Performance Report to get reports on accounts.

Regards,
Anthony
Google Ads Scripts Team

=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    http://googleadsdeveloper.blogspot.com/search/label/adwords_scripts
    https://developers.google.com/google-ads/scripts/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-scripts+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-scripts/63b9d4ed-4e5d-483a-8b40-ad5a4fc50f12%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages