2
votes

I have a custom API written in GAS (Google Apps Script) and would like to utilize the Adwords API from within it.

Sometimes used along with the MccApp, the service is readily available from within Adwords Scripts itself (My Client Center > Scripts).

For Example:

            function account(client) {
              var result = {
                  'id': null,
                  'campaigns': {}
              }
              result.id = client.getCustomerId()
              var currentAct = AdWordsApp.currentAccount()
              MccApp.select(client)
              var campaignIterator = AdWordsApp.campaigns().get()
              while (campaignIterator.hasNext()) {
                  var campaign = campaignIterator.next()
                  result.campaigns[campaign.getName()] = campaign.getId()
              }
              MccApp.select(currentAct)
              return result
            }

However, this API is not readily available inside a Google Apps Script. I have tried enabling it under "Resources > Advanced Google Services" and also under the developer console, but the UI offers no option that I can see.

QUESTION: Is it possible to enable use of the AdwordsApp and MccApp inside a Google Apps script so that the above code snippet would work in GAS?

If not, I understand already there are two workarounds:

  1. Just use Adwords Script

  2. Communicate with the API from GAS as though it were an external service (i.e... using SOAP, REST, etc...)

2
So, you already know about UrlFetchApp.fetchApp(the url) ? Google Documentation - UrlFetchApp ClassAlan Wells
Yes, but I am hoping there is a way to use the Adwords API in GAS in the same way that it is used in an Adwords Script.Joshua Dannemann

2 Answers

3
votes

After much research, there really is no way to add the MccApp and AdwordsApp services for use in a Google Apps script. The nearest solution is to communicate with the API as though it were external or just use an Adwords Script.

1
votes

It looks like you might be able to get to the AdWord API through the Management API:

See the Conceptual Overview section:

AdWords Links can be constructed at the Web Property level.

Google Developer Guide - What Is The Management API - Overview

and you can get to the Management API with the Google Analytics API.

Quote:

The Analytics service allows you to use the Google Analytics Management API and Reporting APIs in Apps Script

Google Documentation - Google Analytics API

So, you need to use the RESOURCES menu, Choose, ADVANCED GOOGLE SERVICES, and then turn the Google Analytics API on.

With the Google Analytics API, you can access the Management API.