use Python to download reports from multiple accounts

420 views
Skip to first unread message

Ronen

unread,
Apr 5, 2016, 9:05:24 AM4/5/16
to AdWords API Forum
Hi,
Written a Python code to download reports (e.g. AD_PERFORMANCE_REPORT ), am using my mcc account to get reports for a client account, now i want to get reports of many client accounts (all under the same mcc manager account).
I am new to python (and programming), so I have few questions to fill up my knowledge gaps so I can tailor the best solution. 

1)
just filled all the variables with my token etc., and used the CLIENT_CUSTOMER_ID of my MCC. 
So my first question is - what exactly this code does? 
My app didn't work until I run this piece of code, but I cannot understand -is this something you need to run once? like to "register" your application? Or is it initiating some session that gets expired after a while? 
Also - I am using yaml file. It works fine but the sample says "without_yaml" so I'm obviously not using it the way i should have, but I am not sure how my yaml file is related to this sample code (some fields are obviously duplicated, but the CLIENT_CUSTOMER_ID is not the same, in the yaml i use the one of the client account, not the mcc). 

2)
So in my ymal file I field my token etc. (same as in the aforementioned sample code), but here i use the CLIENT_CUSTOMER_ID is the client account. 
So as far as I understand it, every time I want to get the report for a different client account (under the same mcc), I need to switch to a different ymal file (like if i'll hold many yaml files, one for each client account, and pass a variable with the correct file path to LoadFromStorage(MY_CLIENT_YAML_PATH) ) - is this the right way to go?

3)
Is there a way to get all the AD_PERFORMANCE_REPORT reports for all the client accounts under my mcc account?
My current solution is to write the AWQL I need, then iterate and run the query on each account one at a time (pointing to the different yaml files as described in question 2 above) - is this the way to go?

I've went through all training materials I found and couldn't quite find my answers, so I'll mighty appreciate any guidance. 

Thanks !


Yin Niu

unread,
Apr 5, 2016, 12:47:50 PM4/5/16
to AdWords API Forum
Hello, 

The CLIENT_CUSTOMER_ID field should be AdWords account clientCustomerID, not MCC customerID. 

This code is an example how to authenticate AdWords client without yaml file. You don't have to run this code in order to run other examples. 

You can only specify one clientCustomerID each time you make an API request. To query for different clientCustomerID, you will have to make separate requests. This applies to reports, too. 

Most of examples create adWordsClient using yaml file:


adwords_client = adwords.AdWordsClient.LoadFromStorage()


The example you have used creates client without yaml file:

adwords_client = adwords.AdWordsClient(
developer_token, oauth2_client, user_agent, client_customer_id)

You can modify it so that you can run multiple requests for different adWords accounts in the same program. 

Thanks,
Yin, AdWords API Team. 

Ronen

unread,
Apr 5, 2016, 2:07:10 PM4/5/16
to AdWords API Forum
Hi Yin Niu,

Thank you for your answer, it is very helpful. 

But one thing I still fail to understand. 

In the yaml file, I use the clientCustomerID, not MCC customerID (just as you suggest). Still my application did not work. I always got "permission denied" errors. 

I solved the problem by running the example code, but there I used the MCC customerID (NOT the clientCustomerID). When I run it, I received the message "You are logged in as customer: 123456789".  

Only after I run this example code, my application worked. I have'nt seen any "permission denied" errors after that. 

Can you explain this scenario?

Thanks,
Ronen

Yin Niu

unread,
Apr 5, 2016, 2:13:05 PM4/5/16
to AdWords API Forum
Hi Ronen, 

USER_PERMISSION_DENIED error occurs when there's no link between the MCC and the AdWords client account. Please double check to make sure the accounts are linked. 
Reply all
Reply to author
Forward
0 new messages