Page Summary
-
Resource names are unique identifiers for entities in the Google Ads API, represented as strings with a predictable format.
-
The
ResourceNamesclass can construct the full resource name of an entity if you know its relevant IDs. -
For example, a campaign resource name is formatted as
customers/{customer_id}/campaigns/{campaign_id}and can be constructed using theResourceNames.campaign(customerId, campaignId)method. -
The
ResourceNamesclass can be used with other entity names by providing the necessary IDs for their specific resource name format.
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 IDs of an entity, you can use the Java client library utilities to generate or parse the full resource name.
Construct resource names with ResourceNames
The ResourceNames utility class constructs the resource name of an entity
when you know all of the relevant IDs related to that entity. For example, a
campaign resource name is in the following format:
customers/{customer_id}/campaigns/{campaign_id}
If you know the customer ID (without hyphens) and the campaign ID, use the
ResourceNames class to construct the full resource name as follows:
long customerId = 1234567890L;
long campaignId = 9876543210L;
String campaignResourceName = ResourceNames.campaign(customerId, campaignId);
You can construct resource names for other entity types as well, which accept different ID parameters depending on the final form of the resource name.
Parse resource names
While ResourceNames (com.google.ads.googleads.lib.utils.ResourceNames) is
version-agnostic across all supported API versions, the Java client library also
provides strongly-typed resource name classes (such as CampaignName,
AdGroupName, and CustomerName) in each versioned resources package (for
example, com.google.ads.googleads.v25.resources) that
let you parse a resource name string back into its constituent IDs:
import com.google.ads.googleads.v25.resources.CampaignName;
CampaignName campaignName = CampaignName.parse(campaignResourceName);
String parsedCustomerId = campaignName.getCustomerId();
String parsedCampaignId = campaignName.getCampaignId();