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 web interface 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
Link requests are managed differently in Google Ads API depending on whether you're using version v15 or newer of the API, or an earlier version.
If you're using
You can change the status of Merchant Center links in your Google Ads account by using the Google Ads web interface to approve or reject an invitation. You can also update invitations or remove existing links using the Google Ads API as explained below.
List all Merchant Center invitations
You can run a Google Ads API report using the following GAQL query to retrieve a list of all pending invitations to link a Google Ads customer ID to a Merchant Center account.
SELECT
product_link_invitation.merchant_center.merchant_center_id,
product_link_invitation.type
FROM product_link_invitation
WHERE product_link_invitation.status = 'PENDING_APPROVAL'
AND product_link_invitation.type = 'MERCHANT_CENTER'
To retrieve all invitations, remove the filtering condition for the
product_link_invitation.status
field in the query above.
Accept an invitation
You can approve the link by setting the product_link_invitation
status to
ACCEPTED
.
Construct an
UpdateProductLinkInvitationRequest
object and set thecustomer_id
field as the Google Ads customer ID.Set the
resource_name
field as the resource name of theproduct_link_invitation
.Set the
product_link_invitation_status
toACCEPTED
.Issue an
UpdateProductLinkInvitation
API call.
If the invitation flow is attempted by a user who is already an
administrator on both accounts, then a
NO_INVITATION_REQUIRED
error is thrown. You can check for this error and fall back to the direct
link flow in such cases.
Reject an invitation
Rejecting an invitation is similar to accepting an
invitation except that the
product_link_invitation_status
field is set to REJECTED
. If an invitation is rejected, it remains in the
REJECTED
state and cannot be accepted. You must then create a new
invitation if required.
Direct linking without invitation
If the user attempting to link the Google Ads account to the Merchant Center account is an administrator on both accounts, then you can bypass the invitation step and link both accounts directly using the Google Ads API.
Construct a
CreateProductLinkRequest
object and set thecustomer_id
field as the Google Ads customer ID.Create a new
ProductLink
object and set itsmerchant_center_id
field to the ID of the Merchant Center account.Set the
ProductLink
to theproduct_link
field of the request object.Issue a
CreateProductLink
API call.
If direct linking is attempted by a user who doesn't have sufficient
permissions, then a
CREATION_NOT_PERMITTED
error is thrown. You can check for this error and fall back to the
invitation flow in such cases.
List all Merchant Center links
You can run a Google Ads API report using the following GAQL query to retrieve a list of links for a Google Ads customer ID.
SELECT
product_link.merchant_center.merchant_center_id,
product_link.product_link_id
FROM product_link
WHERE product_link.type = 'MERCHANT_CENTER'
Unlink a link
Take the following steps to unlink a link:
Construct a
RemoveProductLinkRequest
object and set thecustomer_id
field as the Google Ads customer ID.Set the
resource_name
as the resource name of theproduct_link
.Issue a
RemoveProductLink
API call.
If you're using
You can change the status of Merchant Center links in your Google Ads account by using the Google Ads web interface to approve or reject a link request or remove an existing link. Remove existing links and update invitations 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 reject 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( ListMerchantCenterLinksRequest::build($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.v14.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
MerchantCenterLinkService
that
corresponds to the Merchant Center account you want to approve or 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.v14.update_resource.merchant_center_link( link.resource_name) do |updated_link| updated_link.status = :ENABLED end # Updates the link. mutate_response = client.service.v14.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
, 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 following code example 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( MutateMerchantCenterLinkRequest::build($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.v14.update_resource.merchant_center_link( link.resource_name) do |updated_link| updated_link.status = :ENABLED end # Updates the link. mutate_response = client.service.v14.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 with a link in the PENDING
state, remove the
MerchantCenterLink
by constructing a
remove
operation for the
resource using
MutateMerchantCenterLinkRequest
:
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( MutateMerchantCenterLinkRequest::build( $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.v14.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 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.