AdWords API: First Steps

Written by


SEM · 08 / 11 / 2016

The Google AdWords application Programming Interface (API) is designed for developers who represent important advertisers or third parties with extensive technical experience.

What utilities does the AdWords API offer?

  • Automatically generate keywords, ad text, target pages, and custom reports.
  • Integrate AdWords data with inventory system to manage stock-based campaigns.
  • Develop additional tools and applications to help you manage your accounts

Set up the AdWords API

To start using the AdWords API, you need to get a developer token in the MCC account or Administrator Account.

To apply for the developer token, go to the account settings.

Configuración AdWords

AdWords SetUp

Once we access the account settings, we have to access the “AdWords API Center”.

When we connect, we will see a form to fill in and so request that they give us a programmer token needed to work with the AdWords API.

Solicitar acceso API AdWords

Request AdWords API Access

Once the access is requested the screen will be updated and our “Programmer Token” will appear in test accounts mode.

Token programador API AdWords

To work with the AdWords API on this account, you need to apply for basic access, but in this case, we will start working with the API, with a TEST account in AdWords.

AdWords TEST Account

To create a test-type account in AdWords, you need to fill in the Google form To create this type of account.

Formulario Test API AdWords

Once we have created the Test account, we will see that when accessing AdWords, a message appears telling us that we are a test type account.

Cuenta Test

Cuenta Test

With the MCC Test account created, we will create an AdWords account associated to our MCC Test account. In this account is where we will do all our tests with the AdWords API.

Client ID API AdWords

Client ID API AdWords

Once we have it, we keep the client ID of the account, for later use it.

Now we will create some credentials to use the Google APIs, in our case for the Adwords API.

OAUTH2 Accreditation for Developers

Google APIS use credentials to use these APIS.

To get those credentials we have to address the Developer Console.

As we are going to use the test type account that we have just created, we log into the developer console with that account (when we are going to use the API with the normal account, we will have to do the same).

Console API Google Credentials

Console API Google Credentials

Already logged in, we access the menu “Credentials”, if we do not already have a project created, will ask to create a new project.

Click on “Create a project”, indicate the name you want and click on Create.

OAuth Credentials

OAuth Credentials

Now that we have created our project, we can create the credentials we wanted. To do this, in “Create credentials”, select “OAuth client ID”.

In the form that will appear to us, we select “Other” and add the name that we want to assign to him. And once we create it, We will have our credentials!

Credenciales OAuth API Google Console

Credentials OAuth API Google Console

We will see our customer ID, and the client’s secret.

We save this data for later and we will be closer to start using the AdWords API .

Get the client library

The AdWords API platform allows us to use this API with different programming languages, in our case we will use PHP.

In addition to PHP also include the libraries of JAVA, PYTHON, etc…

    • To download the library in PHP, you have to download the files from Github.
    • If you want to download from other languages, you can do it from here

Now we just have to start the API.

API settings

Now that we have the library, we will modify the configuration file, in this file will be added the credentials and the necessary account data.

The file is called auth.ini and is located at:

googleads-php-lib / src / Google / API / Ads / AdWords / auth.ini

If we edit it, we will see that there are several commented lines and that we ask for certain information in the variables.



        • DeveloperToken: In this variable we have to add the developer token that we ordered in our production account.
        • clientCustomerId: This line is commented, as we will start with the account type test, we will uncomment and add the identifier of the account we had created previously. If when we are in production we want to work with several accounts, just comment and pass that identifier in a dynamic way.
        • client_id: Here we have to insert the identifier of the credentials OAuth we already have created.
        • Client_secret: Here we have to include the secret also obtained from OAuth.
        • Refresh_token: This is the last data that we lack, to obtain it we have to execute in console The file GetRefreshToken.php.

      Get Refresh_token:

      First we save the file auth.ini with the credentials that we have already inserted.

      Open the console or terminal of our operating system, in my case I will use the Windows console (cmd).

      From the console we access the path where that directory is, for this we execute the following command:

      php googleads-php-lib-masterexamplesAdWordsAuthGetRefreshToken.php

      When you run it, you will ask us to connect to our AdWords account (in this case in our test type account) and access a URL.

      Do not close the console because then we will have to paste the code back!

Consola GetRefreshToken

Consola GetRefreshToken

If the URL appears somewhat like INSERT_OAUTH2_CLIENT_ID_HERE, it means that we have not saved the auth. ini file with the credentials data.

Therefore when we execute the indicated command, we have to notice that the URL that returns us, contains in that client ID section.

Permisos API AdWords

Permisos API AdWords

If everything goes correctly, Google will ask permission to manage our AdWords campaigns.

When we accept the permissions, we will see a code, we have to copy and paste it in the execution of the command we just made in console.

Paste the code where indicated, press enter and… our refresh_token will appear!

Refresh Token API AdWords

Refresh Token API AdWords

Now this code, we include it in the file auth. ini and we will have configured and running the AdWords API!

AdWords API Execution

To start using the AdWords API, we will use the examples files that appear in the downloaded library.

Let’s run the example that creates new campaigns. To do this, we go to the console, and run the file AddCampaigns. PHP, located in:


AdWords API Example

AdWords API Example

By default these files are only run in console, but if you want to run them in a server environment, we have to comment on these lines of code.

if (__FILE__ != realpath($_SERVER['PHP_SELF'])) {   return; }

And so far the process of configuring the AdWords API is a somewhat long process but the result is well worth it.

For any questions do not hesitate to ask! Also, here I leave the reference of the AdWords API. Good luck!


SEM · 18 / 06 / 2020

SEM Game: Revolutionize your Google Ads accounts

In Digital Menta we don’t like to stop. Our greatest enemy is called routine and so we are continually innovating and looking for new ways and methods to do our job better. The last idea we’ve had is called SEM game and we promise you that after reading this post you’re going to want to […]

Miriam Bayona

SEM - SEO · 04 / 06 / 2020

Voice Searches

Voice search is one of the trends that is currently experiencing the greatest growth. In fact, more than one billion voice searches are already performed each month and it is expected that by 2020 50% of searches will be performed by voice. Therefore, given its high utilization, companies cannot ignore voice searches. They must be […]


SEM · 28 / 05 / 2020

10 Problems in a digital client-agency relationship. How to solve a crisis with your digital agency?

During the relationship between a customer and a digital service agency, there may be ups and downs due to multiple situations. It’s normal for a customer to have doubts about the quality of the services provided. Here are ten questions a customer can ask about your digital service provider.

Send this to a friend