Link your Merchant Center and Google Ads accounts

Before you can create a Shopping campaign, you need to first link your Google Ads account to your Google Merchant Center account as follows:

  1. Send a link request from your Merchant Center account to your Google Ads account.
  2. Approve the link request in your Google Ads account.

There are two ways of sending a link request:

  1. Use the Merchant Center web interface to send a link request.
  2. Use the Content API for Shopping to update the adsLinks of your Account.

Link requests are managed differently in the Google Ads API, depending on whether you're using version v15 or later 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.

  1. Construct an UpdateProductLinkInvitationRequest object and set the customer_id field as the Google Ads customer ID.

  2. Set the resource_name field as the resource name of the product_link_invitation.

  3. Set the product_link_invitation_status to ACCEPTED.

  4. 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.

  1. Construct a CreateProductLinkRequest object and set the customer_id field as the Google Ads customer ID.

  2. Create a new ProductLink object and set its merchant_center_id field to the ID of the Merchant Center account.

  3. Set the ProductLink to the product_link field of the request object.

  4. 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.

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'

Take the following steps to unlink a link:

  1. Construct a RemoveProductLinkRequest object and set the customer_id field as the Google Ads customer ID.

  2. Set the resource_name as the resource name of the product_link.

  3. 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:

  1. To retrieve all Merchant Center links, make a request to retrieve objects from the MerchantCenterLink resource.

  2. For each MerchantCenterLink object you can check the MerchantCenterLinkStatus field to find the link status.

  3. To approve a PENDING link, set the MerchantCenterLinkStatus field to ENABLED.

    1. To reject a PENDING link, remove the MerchantCenterLink object.
    2. To unlink an ENABLED link, remove the MerchantCenterLink object.

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}};
      

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};
      

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;
  }
}
      

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;
}
      

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.

Business Manager is a unified representation of a business on Google. When you manage both your Google Ads account and your Merchant Center accounts using a Business Manager account, Business Manager automatically creates links between your Google Ads account and the Merchant Center account. You can retrieve these links using the Google Ads API, but these links cannot be mutated with the Google Ads API.