Mark Hamill | Mark YAML

It’s a beautiful file containing everything you need to connect to the Google Ads API, well almost everything. You’ll need a computer, client library, adwords account and half an interest in making API calls to Google Ads – or a manager who’s telling you you have half an interest in making calls to it.

It’s good to start out by just saving the googleads.yaml file in the root of the project folder you’re working in as the client library will automatically look for it there, however in production you’ll most likely want to load the credentials from environment variables.
If you are reading straight from the file ensure you add it to the gitignore as you don’t want to be pushing it up to a public repository!

Here’s an overview of how to make your first API call, it’s OK but for total noobs it can leave a few questions unanswered.

First off you’ll need the ID of the main account you want to extract the data from, when you first start out it’s a little confusing having customer, client, customer_client, client_customer… however just get the main client account you want to read from and later on you’ll get all the customers under that

Resources & Services

There are two key things you need to know about the Google Ads API – Resources and Services.
Think of resources as API endpoints – when you call that resource you supply the resource name and a unique identifier, so if you were calling the Customer endpoint (the main client account in our example, lets say 123456789) your endpoint would be:

customers/123456789

and from this endpoint we’d be able to extract all the data we need for that customer.

If we then wanted a specific campaign under that account we’d need to reference the customer endpoint, the account (OK customer) id, the campaign endpoint and then the campaign id (assume 987654321) we want to retrieve the data for, it’ll end up looking something like this:

customer/123456789/campaigns/987654321

Now this is all fine until you start translating that through the client libraries, prepare to open up a can of worms.
We’ll come back to resources when we work through some examples however the other key topic is services.

So services are things you use to modify resources, and while there are a plethora of Resources; fortunately we only have to remember 3 services – and they’re pretty easy depending on what you want to modify.

  • CustomerService – used to modify Customers
  • CampaignService – used to modify Campaigns
  • AdGroupService- yes you guessed it, used to modify Ad Groups!

The final piece in the puzzle is the ability to to retrieve objects and performance data – you do this by using the GoogleAdsService. When using the GoogleAdsService you pass in a query that references the resource you’re looking to query along with the attributes and performance metrics.
You can break down the data even further using filters. There’s a Query Language Guide however when first starting out I found the Query Language Builder a great tool to get up and running quickly.

Because we’re accessing our own Google Ads Account and not building an application that needs to request access to others we can skip over Oath for the now… we may revisit later if I remember.

Next up we’ll run a query to get the accounts under a manager account