how to display all accounts (including managers and clients) php?

188 views
Skip to first unread message

silent_coder

unread,
Jul 19, 2017, 9:53:04 AM7/19/17
to AdWords API Forum
I've tried to use the example code of getting all accounts ( GetAccountHierarchy.php ) but somehow it is not working as expected. It only return 11 or 12 accounts where in fact it should be  more or less 30. I understand it uses recursion to get all accounts in hierarchy but perhaps example of working with accounts the other way might help. Tia. 

Shwetha Vastrad (AdWords API Team)

unread,
Jul 19, 2017, 1:55:57 PM7/19/17
to AdWords API Forum
Hi, 

Could you check that you have set the clientCustomerId correctly in your adsapi_php.ini file? Could you also check if there are any hidden accounts under your AdWords Manager account? Please enable logging and provide the request and response log for this request so I can take a look. Please use Reply privately to author when responding. 

Thanks,
Shwetha, AdWords API Team.
Message has been deleted

silent_coder

unread,
Jul 19, 2017, 2:11:09 PM7/19/17
to AdWords API Forum
Yes, I've set the customer id properly. It should return more or less 31 accounts (parent and child) but unexpectedly it return only 12.

I'm using this particular code from the example (returns 12):

private static function printAccountHierarchy($account,
      $customerIdsToAccounts, $customerIdsToChildLinks, $depth = null) {
    if ($depth === null) {
      print "(Customer ID, Account Name)<br>";
      self::printAccountHierarchy(
          $account, $customerIdsToAccounts, $customerIdsToChildLinks, 0);
      return;
    }

    print str_repeat('-', $depth * 2);
    $customerId = $account->getCustomerId();
    printf("%s, %s<br>", $customerId, $account->getName());

    if (array_key_exists($customerId, $customerIdsToChildLinks)) {
      foreach ($customerIdsToChildLinks[$customerId] as $childLink) {
        $childAccount =
            $customerIdsToAccounts[$childLink->getClientCustomerId()];
        self::printAccountHierarchy($childAccount, $customerIdsToAccounts,
            $customerIdsToChildLinks, $depth + 1);
      }
    }
  }

But if I try to use this plain code to display accounts, it will return 31 accounts.

foreach ($customerIdsToAccounts as $account) {
echo $account->getName() . '
';
}

What did I missed here? Thanks

silent_coder

unread,
Jul 19, 2017, 2:16:44 PM7/19/17
to AdWords API Forum
There'll be no errors that will be reflected on soap logs because I think it assumes that it is getting all the accounts.
Reply all
Reply to author
Forward
0 new messages