Resource Names

The unique identifier for an entity in the Google Ads API is called a resource name, and is represented as a string with a predictable format. If you know the constituent components of a resource name, you can generate resource names using helper methods present on many Service objects.

Service path methods

All Services that are designed to handle reading or mutating specific types of objects in the API have helper methods to make it easy to construct resource_names. For example creating a resource name for a Campaign object:

from import client

customer_id = '7892134783'
campaign_id = '1234567890'
campaign_service = client.get_service('CampaignService')
resource_name = campaign_service.campaign_path(customer_id, campaign_id)

Composite resource names

Some objects, such as the AdGroupCriterion resource, have composite resource names, which means that the last segment of the resource name is composed of multiple object IDs separated by a ~. The path helpers on services won't construct the composite segment of a resource name, so the client library has a small utility to help with this:

from import client
from import ResourceName

customer_id = '0987654321'
ad_group_id = '1234567890'
criterion_id = '74932'

ad_group_criterion_service = client.get_service('AdGroupCriterionService')

# An AdGroupCriterion resource name that uses the above IDs looks like this:
# 'customers/0987654321/adGroupCriteria/1234567890~74932'
composite_id = ResourceName.format_composite(ad_group_id, criterion_id)
resource_name = ad_group_criterion_service.ad_group_criterion_path(
    customer_id, composite_id)