Google Ads API is returning to beta status. Please read our blog post for more details.

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 UI to send a link request.
  2. Use the Content API for Shopping to update the adsLinks of your 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. For existing links, you can unlink Merchant Center from Google Ads accounts 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.
    1. To approve a PENDING link, set the MerchantCenterLinkStatus field to ENABLED.
    2. To reject a PENDING link, remove the MerchantCenterLink object.
    3. 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());

Once you have found the MerchantCenterLink that corresponds to the Merchant Center account you wish 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());

If the link is 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(
      "Approved Merchant Center link with resource name: '%s'.%n",
      merchantCenterLinkResult.getResourceName());
}

To reject a link request (any link in a PENDING state), you need to remove the MerchantCenterLink object for a customerId. You can do this by constructing a remove operation for the resource using MutateMerchantCenterLink.

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

To unlink a link (any link in a ENABLED state), you need to remove the MerchantCenterLink object for a customerId. You can do this by constructing a remove operation for the resource using MutateMerchantCenterLink. This is the same action as rejecting a link request.