Unable to replicate code in AdWords script through python APIs

52 views
Skip to first unread message

Hadil Charafeddine

unread,
Nov 30, 2021, 7:38:26 AM11/30/21
to AdWords API and Google Ads API Forum
Hello,

We have scripts on our GoogleAds account that periodically extract campaign report data from the platform and saves them in our BigQuery database on Google Cloud.

The script begins by looping over all our accounts and then fetches the reports of the campaigns under each account:

var excluded_account_ids = ['xxx', 'xxx', 'xxx'];
  
  // Retrieve all child accounts.
  var accountIterator = AdsManagerApp.accounts().get();

  // this array will hold all of the insert 
  var values_array = [];

  // Iterate through the account list.
  while (accountIterator.hasNext()) {
    var account = accountIterator.next();

    // Making sure that the account ID isn't among the excluded ones
    if(excluded_account_ids.indexOf(account.getCustomerId()) < 0) {     
      Logger.log(account.getCustomerId())
      AdsManagerApp.select(account);

      var report = AdsApp.report(
        'SELECT Date, CampaignId, CampaignName, AdGroupId, AdGroupName, Device, DayOfWeek, Impressions, Clicks, Ctr, VideoViews, VideoViewRate, VideoQuartile100Rate, VideoQuartile25Rate, VideoQuartile50Rate, VideoQuartile75Rate, Conversions, Cost, ActiveViewMeasurability, ActiveViewViewability, ActiveViewImpressions, ActiveViewMeasurableImpressions, ViewThroughConversions ' +
        'FROM   ADGROUP_PERFORMANCE_REPORT ' +
        'DURING ' + current_date[0] + ',' + current_date[0], {
          includeZeroImpressions: false,
          returnMoneyInMicros: true
        });

      var rows = report.rows();

When we print the customer IDs fetched by the above script, we get 207 different customer IDs.

However, when we try to do the same in our python scripts through APIs, we're only able to get the IDs of the most top-level accounts (only 3 IDs and one isn't enabled) and when we proceed with fetching the campaigns under these top-level accounts, the search always comes back empty. A snippet of the python script is attached and our main account's customer ID is 325-177-1939.

Can you please advise on what we're doing wrong in the python script?
adwords_snippet.py

Google Ads API Forum Advisor

unread,
Dec 1, 2021, 11:33:27 AM12/1/21
to hadil.cha...@mmpww.com, adwor...@googlegroups.com
Hi Hadil,

Thank you for sending us your sample code and your description of what you are looking for. Listing accessible customers only gives the accounts that can be accessed with the credentials used without using a login customer Id. This only includes accounts that you are added as user directly into the account. This will also include all accounts even if they are not in the same hierarchy. 

To access a hierarchy using a login customer Id that the underlying accounts don't have you as a user, you can use the get account hierarchy sample instead.

Reminder: Share your feedback about the Google Ads (AdWords) API! Take the 2021 Google Ads API and AdWords API Annual Survey
 
Regards,
 
Google Logo
Aryeh Baker
Google Ads API Team
 


ref:_00D1U1174p._5004Q2RxAAU:ref

Hadil Charafeddine

unread,
Dec 2, 2021, 9:15:23 AM12/2/21
to AdWords API and Google Ads API Forum
Hello Aryeh,

We'd already tried the account hierarchy script before sending the message here and it was giving us errors on many customer IDs. After further investigation, we saw that the errors are only happening on hidden and cancelled accounts. So, with simple try/except statements we should be able to avoid these errors and to retrieve the customer IDs of our active accounts.

Thank you for your help.

Kind regards,
Hadil Charafeddine

Google Ads API Forum Advisor

unread,
Dec 3, 2021, 2:56:27 AM12/3/21
to hadil.cha...@mmpww.com, adwor...@googlegroups.com
Hi Hadil,

Thank you for your follow up.

Could you confirm if your get account hierarchy requests are returning the said cancelled accounts? If yes, so our team can investigate further, could you provide the complete request and response logs, with the request-id?

If you haven't yet, logging can be enabled for Python by referring to this guide.

You may then send the requested information via the Reply privately to author option. If this option is not available, you may send the details directly to our googleadsa...@google.com alias instead.

Best regards,

Google Logo
Peter Laurence Napa Oliquino
Google Ads API Team
 


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