How to use the Google Ads API using REST Only

4,481 views
Skip to first unread message

De1

unread,
Feb 25, 2019, 11:28:32 AM2/25/19
to AdWords API and Google Ads API Forum
Hi,

I'm creating a solution using Apps Script so I'm not using a client library. I'm finding it difficult to get at how to do things using REST as the documentation focuses on gRPC.
eg.
I would like to retrieve a list of accounts.
The section that explains the Call Structure gives some insights into the RESTful stuff, but then, to retrieve a list of accounts it says;
Note: You can retrieve the list of accounts that are directly accessible via your OAuth credentials by issuing a CustomerService.ListAccessibleCustomers request. The login-customer-id is not required for this request type, and has no effect on the list of customers returned.

I can't figure out how to resolve that into a RESTful call.

Any guidance?


Thanks
De1

derek....@metrictheory.com

unread,
Feb 25, 2019, 1:53:41 PM2/25/19
to AdWords API and Google Ads API Forum
Hi De1, 

Try this:

  var options = {
    method: 'POST',
    muteHttpExceptions: true,
    headers: {
      'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
      'developer-token': 'YOUR_DEVELOPER_TOKEN',
      'login-customer-id': 'YOUR_LOGIN_CUSTOMER_ID',
      'x-goog-api-client': 'YOUR_USER_AGENT_NAME',
    },
    body: {
      query: 'SELECT customer.id, customer.descriptive_name, customer_client.resource_name, customer_client.client_customer, customer_client.level, customer_client.hidden FROM customer_client',
    },
  };

  try {
    var response = UrlFetchApp.fetch(url, options);

    Logger.log(response.getContentText())
  } catch (err) {
    throw err;
  }

Afonso Praça

unread,
Feb 25, 2019, 2:49:58 PM2/25/19
to derek....@metrictheory.com, AdWords API and Google Ads API Forum
Tks man, I will try and let you know about that. Best,
--
Afonso Praça
Software Developer
VTEX - e-Commerce Cloud Software
+55 21 979.151515


--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
 
You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to adwor...@googlegroups.com
To unsubscribe from this group, send email to
adwords-api...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to the Google Groups "AdWords API and Google Ads API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-api...@googlegroups.com.
Visit this group at https://groups.google.com/group/adwords-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-api/cdee4e38-ed21-471a-ba00-fe1dd57cd73f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

De1

unread,
Feb 25, 2019, 4:27:24 PM2/25/19
to AdWords API and Google Ads API Forum
Thanks a bunch Derek. Seems like when in doubt...Query!
Nice.

De1

unread,
Mar 18, 2019, 7:13:29 PM3/18/19
to AdWords API and Google Ads API Forum
Actually...now that I sat down to use this. This is the wrong list. What I need is the list of accounts I have access too, not the list of accounts under a manager account. When I log in to Google Ads I am presented with different accounts to click on (some individual some MCC), it is that list I need. Hope someone can help!


On Monday, 25 February 2019 14:53:41 UTC-4, derek....@metrictheory.com wrote:

googleadsapi...@google.com

unread,
Mar 19, 2019, 1:35:24 PM3/19/19
to debla...@gmail.com, AdWords API and Google Ads API Forum
Hello,

To get the accessible accounts for a user you can use CustomerService.ListAccessibleCustomers which returns resource names of customers directly accessible by the user authenticating the call. Please give it a try, If you still has concerns, please share the screenshot of the accounts list that you are expecting to get via API? You could use reply privately to the author option while sharing the information requested.

Regards,
Sai Teja, Google Ads API Team


=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    http://googleadsdeveloper.blogspot.com/search/label/adwords_api
    https://developers.google.com/adwords/api/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

De1

unread,
Mar 19, 2019, 6:15:35 PM3/19/19
to AdWords API and Google Ads API Forum
Hi Sai,

The issue is that I'm not using a client library and I don't know how to resolve  CustomerService.ListAccessibleCustomers into a RESTful call.

googleadsapi...@google.com

unread,
Mar 20, 2019, 2:33:05 PM3/20/19
to debla...@gmail.com, AdWords API and Google Ads API Forum
Hello,

You could try using the Method: google.ads.googleads.v1.services.CustomerService/ListAccessibleCustomers and Endpoint: googleads.googleapis while trying your RESTful call. You have to pass the OAuth credentials the same way you pass for other RESTful API calls. You could refer this API call structure for reference. 

Also, below is the CURL request In case you want to take a look.

curl --header "Authorization: Bearer ACCESS_TOKEN_HERE" --header "developer-token: DEVELOPER_TOKEN_HERE" https://googleads.googleapis.com/v1/customers:listAccessibleCustomers

Please let me know if you have any further questions.

Regards,
Sai Teja, Google Ads API Team

De1

unread,
Mar 20, 2019, 2:44:21 PM3/20/19
to AdWords API and Google Ads API Forum
Awesome! That worked!
Thanks Much!
Reply all
Reply to author
Forward
0 new messages