Resource names

  • A resource name is the unique identifier for an entity in the Google Ads API, formatted as a string with a predictable structure.

  • The ResourceNames class is a utility for constructing entity resource names using their relevant IDs.

  • You can build a campaign resource name by providing the customer ID and campaign ID to the ResourceNames.Campaign method.

  • The ResourceNames class can be used for various entity names, requiring different IDs based on the resource name format.

A resource name is the unique identifier for an entity in the Google Ads API and is represented as a string with a predictable format.

Construct resource names with ResourceNames

ResourceNames is a utility class that provides a way to construct the resource name of an entity if you know all of the relevant IDs related to that entity. For example, a campaign resource name follows the format customers/{customer_id}/campaigns/{campaign_id}. If you know the customer ID and the campaign ID, you can 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 entities as well by calling the corresponding method on ResourceNames with the required IDs.

Parse resource names

The .NET client library also provides strongly-typed resource name classes (such as CampaignName, AdGroupName, and CustomerName in the Google.Ads.GoogleAds.V25.Resources namespace) that let you parse a resource name string back into its individual ID components:

using Google.Ads.GoogleAds.V25.Resources;

CampaignName campaignName = CampaignName.Parse(campaignResourceName);
string parsedCustomerId = campaignName.CustomerId;
string parsedCampaignId = campaignName.CampaignId;