Before you can create a Shopping campaign, you need to first link your Google Ads account to your Google Merchant Center account as follows:
- Send a link request from your Merchant Center account to your Google Ads account.
- Approve the link request in your Google Ads account.
Sending link requests from your Merchant Center account
There are two ways of sending a link request:
- Use the Merchant Center UI to send a link request.
- Use the Content API for Shopping to
update the
adsLinks
of yourAccount
.
Managing link requests in your Google Ads account
You can change the status of Merchant Center links in your Google Ads account by using the Google Ads UI to approve/reject a link request. You can approve, reject, or remove existing links and link requests using the Google Ads API as follows:
- To retrieve all Merchant Center links, make a request to retrieve objects
from the
MerchantCenterLink
resource. - For each
MerchantCenterLink
object you can check theMerchantCenterLinkStatus
field to find the link status.- To approve a
PENDING
link, set theMerchantCenterLinkStatus
field toENABLED
. - To reject a
PENDING
link, remove theMerchantCenterLink
object. - To unlink an
ENABLED
link, remove theMerchantCenterLink
object.
- To approve a
Step 1: List all Merchant Center links
You can use the
MerchantCenterLinkService
to
retrieve a list of links for a Google Ads customer ID.
The code example below shows how to use
ListMerchantCenterLinks
to request all links for customer_id
.
Java
ListMerchantCenterLinksResponse response = merchantCenterLinkService.listMerchantCenterLinks( ListMerchantCenterLinksRequest.newBuilder() .setCustomerId(Long.toString(customerId)) .build()); System.out.printf( "%d Merchant Center link(s) found with the following details:%n", response.getMerchantCenterLinksCount());
C#
ListMerchantCenterLinksResponse response = merchantCenterLinkService.ListMerchantCenterLinks(customerId.ToString()); Console.WriteLine($"{response.MerchantCenterLinks.Count} Merchant Center link(s)" + $" found with the following details:");
PHP
// Lists all merchant links of the specified customer ID. $merchantCenterLinkServiceClient = $googleAdsClient->getMerchantCenterLinkServiceClient(); $response = $merchantCenterLinkServiceClient->listMerchantCenterLinks($customerId); printf( "%d Merchant Center link(s) found with the following details:%s", $response->getMerchantCenterLinks()->count(), PHP_EOL );
Python
# Retrieve all the existing Merchant Center links. response = merchant_center_link_service.list_merchant_center_links( customer_id=customer_id ) print( f"{len(response.merchant_center_links)} Merchant Center link(s) " "found with the following details:" )
Ruby
# Retrieve all the existing Merchant Center links. response = client.service.merchant_center_link.list_merchant_center_links( customer_id: customer_id, )
Perl
# List all Merchant Center links of the specified customer ID. my $merchant_center_link_service = $api_client->MerchantCenterLinkService(); my $response = $merchant_center_link_service->list({customerId => $customer_id}); printf "%d Merchant Center link(s) found with the following details:\n", scalar @{$response->{merchantCenterLinks}};
Step 2: Find the Merchant Center link status
Once you have found the MerchantCenterLink
that corresponds to the Merchant Center account you want to approve/reject, you
need to check the status
. The
MerchantCenterLinkStatus
enum describes the possible statuses.
Java
System.out.printf( "Link '%s' has status '%s'.%n", merchantCenterLink.getResourceName(), merchantCenterLink.getStatus());
C#
Console.Write($"Link '{merchantCenterLink.ResourceName}' has status " + $"'{merchantCenterLink.Status}'.");
PHP
printf( "Link '%s' has status '%s'.%s", $merchantCenterLink->getResourceName(), MerchantCenterLinkStatus::name($merchantCenterLink->getStatus()), PHP_EOL );
Python
print( f"Link '{merchant_center_link.resource_name}' has status " f"'{merchant_center_link.status.name}'." )
Ruby
# Iterate the results, and filter for links with pending status. response.merchant_center_links.each do |link| # Enables the pending link. if link.status == :PENDING && link.id.to_s == merchant_center_account_id # Creates the update operation. update_operation = client.operation.update_resource.merchant_center_link( link.resource_name) do |updated_link| updated_link.status = :ENABLED end # Updates the link. mutate_response = client.service.merchant_center_link.mutate_merchant_center_link( customer_id: customer_id, operation: update_operation, ) # Display the result. puts "Enabled a Merchant Center Link with resource name " \ "#{mutate_response.result.resource_name} " \ "to Google Ads account #{customer_id}" end end
Perl
printf "Link '%s' has status '%s'.\n", $merchant_center_link->{resourceName}, $merchant_center_link->{status};
Step 3a: Approve a link request
If the link status is PENDING
, then you can approve the link by setting the
status to ENABLED
. You can use the existing
MerchantCenterLink
object to help
construct an updated MerchantCenterLink
object with the status
set to
ENABLED
.
The code example below shows how to construct the mutate operation required to change only the status.
Java
private void updateMerchantCenterLinkStatus( MerchantCenterLinkServiceClient merchantCenterLinkServiceClient, long customerId, MerchantCenterLink merchantCenterLink, MerchantCenterLinkStatus status) { // Creates an updated MerchantCenterLink object derived from the original, but with the new // status. MerchantCenterLink updatedMerchantCenterLink = merchantCenterLink.toBuilder().setStatus(status).build(); // Constructs an operation that will update the merchantCenterLink, using the FieldMasks compare // utility to derive the update mask from the changes. This mask tells the Google Ads API which // attributes of the merchantCenterLink to change. In this case we only want to change the // MerchantCenterLinkStatus. MerchantCenterLinkOperation operation = MerchantCenterLinkOperation.newBuilder() .setUpdate(updatedMerchantCenterLink) .setUpdateMask(FieldMasks.compare(merchantCenterLink, updatedMerchantCenterLink)) .build(); // Sends the operation in a mutate request. MutateMerchantCenterLinkResponse response = merchantCenterLinkServiceClient.mutateMerchantCenterLink( String.valueOf(customerId), operation); // Prints the resource name of the updated object. MutateMerchantCenterLinkResult merchantCenterLinkResult = response.getResult(); System.out.printf( "Updated Merchant Center link with resource name: '%s'.%n", merchantCenterLinkResult.getResourceName()); }
C#
private static void UpdateMerchantCenterLinkStatus(long customerId, MerchantCenterLinkServiceClient merchantCenterLinkService, MerchantCenterLink merchantCenterLink, MerchantCenterLinkStatus status) { // Enables the pending link. MerchantCenterLink linkToUpdate = new MerchantCenterLink() { ResourceName = merchantCenterLink.ResourceName, Status = status }; // Creates an operation. MerchantCenterLinkOperation operation = new MerchantCenterLinkOperation() { Update = linkToUpdate, UpdateMask = FieldMasks.AllSetFieldsOf(linkToUpdate) }; // Updates the link. MutateMerchantCenterLinkResponse mutateResponse = merchantCenterLinkService.MutateMerchantCenterLink( customerId.ToString(), operation); // Displays the result. Console.WriteLine($"The status of Merchant Center Link with resource name " + $"'{mutateResponse.Result.ResourceName}' to Google Ads account : " + $"{customerId} was updated to {status}."); }
PHP
private static function updateMerchantCenterLinkStatus( MerchantCenterLinkServiceClient $merchantCenterLinkServiceClient, int $customerId, MerchantCenterLink $merchantCenterLink, int $newMerchantCenterLinkStatus ) { // Creates an updated MerchantCenterLink object derived from the original, but with the // specified status. $merchantCenterLinkToUpdate = new MerchantCenterLink([ 'resource_name' => $merchantCenterLink->getResourceName(), 'status' => $newMerchantCenterLinkStatus ]); // Constructs an operation that will update the Merchant Center link, // using the FieldMasks utility to derive the update mask. This mask tells the // Google Ads API which attributes of the Merchant Center link you want to change. $merchantCenterLinkOperation = new MerchantCenterLinkOperation(); $merchantCenterLinkOperation->setUpdate($merchantCenterLinkToUpdate); $merchantCenterLinkOperation->setUpdateMask( FieldMasks::allSetFieldsOf($merchantCenterLinkToUpdate) ); // Issues a mutate request to update the Merchant Center link and prints some // information. $response = $merchantCenterLinkServiceClient->mutateMerchantCenterLink( $customerId, $merchantCenterLinkOperation ); printf( "Approved a Merchant Center Link with resource name '%s' to the Google Ads " . "account '%s'.%s", $response->getResult()->getResourceName(), $customerId, PHP_EOL ); }
Python
def update_merchant_center_link_status( client, customer_id, merchant_center_link_service, merchant_center_link, status, ): """Updates the status of a Merchant Center link request. Args: client: An initialized GoogleAdsClient instance. customer_id: The client customer ID string. merchant_center_link_service: A merchant center link service instance. merchant_center_link: The merchant center link to be modified. status: The updated status to apply to the merchant center link. """ # Creates an operation. operation = client.get_type("MerchantCenterLinkOperation") link_to_update = operation.update link_to_update.resource_name = merchant_center_link.resource_name # Enables the pending link. link_to_update.status = status client.copy_from( operation.update_mask, protobuf_helpers.field_mask(None, link_to_update._pb), ) # Updates the link. mutate_response = merchant_center_link_service.mutate_merchant_center_link( customer_id=customer_id, operation=operation ) # Displays the result. print( "The status of Merchant Center Link with resource name " f"'{mutate_response.result.resource_name}' to Google Ads account : " f"{customer_id} was updated to {status.name}." )
Ruby
# Iterate the results, and filter for links with pending status. response.merchant_center_links.each do |link| # Enables the pending link. if link.status == :PENDING && link.id.to_s == merchant_center_account_id # Creates the update operation. update_operation = client.operation.update_resource.merchant_center_link( link.resource_name) do |updated_link| updated_link.status = :ENABLED end # Updates the link. mutate_response = client.service.merchant_center_link.mutate_merchant_center_link( customer_id: customer_id, operation: update_operation, ) # Display the result. puts "Enabled a Merchant Center Link with resource name " \ "#{mutate_response.result.resource_name} " \ "to Google Ads account #{customer_id}" end end
Perl
foreach my $merchant_center_link (@{$response->{merchantCenterLinks}}) { printf "Link '%s' has status '%s'.\n", $merchant_center_link->{resourceName}, $merchant_center_link->{status}; # Approve a pending link request for a Google Ads account with the specified # customer ID from a Merchant Center account with the specified Merchant # Center account ID. if ( $merchant_center_link->{id} == $merchant_center_account_id && $merchant_center_link->{status} eq PENDING) { # Update the status of Merchant Center link to 'ENABLED' to approve the link. update_merchant_center_link_status( $merchant_center_link_service, $customer_id, $merchant_center_link, ENABLED ); # There is only one MerchantCenterLink object for a given Google Ads account # and Merchant Center account, so we can break early. last; } }
Step 3b: Reject a link request
To reject a link request (any link in the PENDING
state),
remove the MerchantCenterLink
by
constructing a remove
operation for the resource using
MutateMerchantCenterLinkRequest
.
See the example code below:
Java
private void removeMerchantCenterLink( MerchantCenterLinkServiceClient merchantCenterLinkServiceClient, long customerId, MerchantCenterLink merchantCenterLink) { // Creates a single remove operation, specifying the Merchant Center link resource name. MerchantCenterLinkOperation operation = MerchantCenterLinkOperation.newBuilder() .setRemove(merchantCenterLink.getResourceName()) .build(); // Sends the operation in a mutate request. MutateMerchantCenterLinkResponse response = merchantCenterLinkServiceClient.mutateMerchantCenterLink( Long.toString(customerId), operation); MutateMerchantCenterLinkResult result = response.getResult(); System.out.printf( "Removed Merchant Center link with resource name: '%s'.%n", result.getResourceName()); }
C#
private void RemoveMerchantCenterLink( MerchantCenterLinkServiceClient merchantCenterLinkServiceClient, long customerId, MerchantCenterLink merchantCenterLink) { // Creates a single remove operation, specifying the Merchant Center link resource name. MerchantCenterLinkOperation operation = new MerchantCenterLinkOperation { Remove = merchantCenterLink.ResourceName }; // Sends the operation in a mutate request. MutateMerchantCenterLinkResponse response = merchantCenterLinkServiceClient.MutateMerchantCenterLink( customerId.ToString(), operation); Console.WriteLine("Removed Merchant Center Link with resource name: " + $"{response.Result.ResourceName}"); }
PHP
private static function removeMerchantCenterLink( MerchantCenterLinkServiceClient $merchantCenterLinkServiceClient, int $customerId, MerchantCenterLink $merchantCenterLink ) { // Creates a single remove operation, specifying the Merchant Center link resource name. $merchantCenterLinkOperation = new MerchantCenterLinkOperation(); $merchantCenterLinkOperation->setRemove($merchantCenterLink->getResourceName()); // Issues a mutate request to remove the link and prints the result info. $response = $merchantCenterLinkServiceClient->mutateMerchantCenterLink( $customerId, $merchantCenterLinkOperation ); $mutateMerchantCenterLinkResult = $response->getResult(); printf( "Removed Merchant Center link with resource name: '%s'.%s", $mutateMerchantCenterLinkResult->getResourceName(), PHP_EOL ); }
Python
def remove_merchant_center_link( client, merchant_center_link_service, customer_id, merchant_center_link ): """Removes a Merchant Center link from a Google Ads client customer account. Args: client: An initialized Google Ads client. merchant_center_link_service: An initialized MerchantCenterLinkService client. customer_id: The Google Ads customer ID of the account that has the link request. merchant_center_link: The MerchantCenterLink object to remove. """ # Create a single remove operation, specifying the Merchant Center link # resource name. operation = client.get_type("MerchantCenterLinkOperation") operation.remove = merchant_center_link.resource_name # Send the operation in a mutate request. response = merchant_center_link_service.mutate_merchant_center_link( customer_id=customer_id, operation=operation ) print( "Removed Merchant Center link with resource name " f"'{response.result.resource_name}'." )
Ruby
def remove_merchant_center_link( client, merchant_center_link_service, customer_id, link) # Creates a single remove operation, specifying the Merchant Center link # resource name. operation = client.operation.remove_resource.merchant_center_link(link.resource_name) # Issues a mutate request to remove the link and prints the result info. response = merchant_center_link_service.mutate_merchant_center_link( customer_id: customer_id, operation: operation, ) puts "Removed Merchant Center link with resource name: " \ "#{response.result.resource_name}" end
Perl
sub reject_merchant_center_link { my ($api_client, $customer_id, $merchant_center_account_id) = @_; my $merchant_center_link_service = $api_client->MerchantCenterLinkService(); # Reject a pending link request or unlink an enabled link for a Google Ads # account with $customer_id from a Merchant Center account with $merchant_center_account_id. my $response = $merchant_center_link_service->list({customerId => $customer_id}); printf "%d Merchant Center link(s) found with the following details:\n", scalar @{$response->{merchantCenterLinks}}; foreach my $merchant_center_link (@{$response->{merchantCenterLinks}}) { printf "Link '%s' has status '%s'.\n", $merchant_center_link->{resourceName}, $merchant_center_link->{status}; # Check if there is a link for the Merchant Center account we are looking for. if ($merchant_center_account_id == $merchant_center_link->{id}) { # If the Merchant Center link is pending, reject it by removing the link. # If the Merchant Center link is enabled, unlink Merchant Center from Google # Ads by removing the link. # In both cases, the remove action is the same. remove_merchant_center_link($merchant_center_link_service, $customer_id, $merchant_center_link); # There is only one MerchantCenterLink object for a given Google Ads account # and Merchant Center account, so we can break early. last; } } return 1; }
Step 3c: Unlink a link
To unlink a link (any link in the ENABLED
state), remove the
MerchantCenterLink
by constructing a
remove
operation for the
resource using
MutateMerchantCenterLinkRequest
.
This is the same action as rejecting a link request.