Update an extension setting

Updating an extension setting is as simple as modifying the ExtensionFeedItem. Any associated customers, campaigns, and feeds will be automatically updated to use the new values.

In the example below, we demonstrate how to update a sitelink's link text. The extension feed item resource name is carried over from the previous example.

Java

private void runExample(
    GoogleAdsClient googleAdsClient, long customerId, long feedItemId, String sitelinkText) {
  try (ExtensionFeedItemServiceClient extensionFeedItemServiceClient =
      googleAdsClient.getLatestVersion().createExtensionFeedItemServiceClient()) {
    // Creates an extension feed item using the specified feed item ID and sitelink text.
    ExtensionFeedItem extensionFeedItem =
        ExtensionFeedItem.newBuilder()
            .setResourceName(ResourceNames.extensionFeedItem(customerId, feedItemId))
            .setSitelinkFeedItem(SitelinkFeedItem.newBuilder().setLinkText(sitelinkText).build())
            .build();
    // Constructs an operation that will update the extension feed item, using the FieldMasks
    // utility to derive the update mask. This mask tells the Google Ads API which attributes of
    // the extension feed item you want to change.
    ExtensionFeedItemOperation operation =
        ExtensionFeedItemOperation.newBuilder()
            .setUpdate(extensionFeedItem)
            .setUpdateMask(FieldMasks.allSetFieldsOf(extensionFeedItem))
            .build();
    // Sends the operation in a mutate request.
    MutateExtensionFeedItemsResponse response =
        extensionFeedItemServiceClient.mutateExtensionFeedItems(
            Long.toString(customerId), ImmutableList.of(operation));
    // Prints the resource name of each updated object.
    for (MutateExtensionFeedItemResult mutateExtensionFeedItemResult :
        response.getResultsList()) {
      System.out.printf(
          "Updated extension feed item with the resource name: '%s'.%n",
          mutateExtensionFeedItemResult.getResourceName());
    }
  }
}

C#

public void Run(GoogleAdsClient client, long customerId, long feedItemId,
    string sitelinkText)
{
    // Get the ExtensionFeedItemService.
    ExtensionFeedItemServiceClient extensionFeedItemService =
        client.GetService(Services.V6.ExtensionFeedItemService);

    // Create an extension feed item using the specified feed item ID and sitelink text.
    ExtensionFeedItem extensionFeedItem = new ExtensionFeedItem
    {
        ResourceName = ResourceNames.ExtensionFeedItem(customerId, feedItemId),
        SitelinkFeedItem = new SitelinkFeedItem
        {
            LinkText = sitelinkText
        }
    };

    // Construct an operation that will update the extension feed item using the FieldMasks
    // utilities to derive the update mask. This mask tells the Google Ads API which
    // attributes of the extension feed item you want to change.
    ExtensionFeedItemOperation extensionFeedItemOperation = new ExtensionFeedItemOperation
    {
        Update = extensionFeedItem,
        UpdateMask = FieldMasks.AllSetFieldsOf(extensionFeedItem)
    };

    try
    {
        // Issue a mutate request to update the extension feed item.
        MutateExtensionFeedItemsResponse response =
            extensionFeedItemService.MutateExtensionFeedItems(
                customerId.ToString(), new[] {extensionFeedItemOperation});

        // Print the resource name of the updated extension feed item.
        Console.WriteLine("Updated extension feed item with resource name " +
            $"'{response.Results.First().ResourceName}'.");
    }
    catch (GoogleAdsException e)
    {
        Console.WriteLine("Failure:");
        Console.WriteLine($"Message: {e.Message}");
        Console.WriteLine($"Failure: {e.Failure}");
        Console.WriteLine($"Request ID: {e.RequestId}");
        throw;
    }
}

PHP

public static function runExample(
    GoogleAdsClient $googleAdsClient,
    int $customerId,
    int $feedItemId,
    string $sitelinkText
) {
    // Creates an extension feed item using the specified feed item ID and sitelink text.
    $extensionFeedItem = new ExtensionFeedItem([
        'resource_name' => ResourceNames::forExtensionFeedItem($customerId, $feedItemId),
        'sitelink_feed_item' => new SitelinkFeedItem(['link_text' => $sitelinkText])
    ]);

    // Constructs an operation that will update the extension feed item, using the FieldMasks
    // utility to derive the update mask. This mask tells the Google Ads API which attributes of
    // the extension feed item you want to change.
    $extensionFeedItemOperation = new ExtensionFeedItemOperation();
    $extensionFeedItemOperation->setUpdate($extensionFeedItem);
    $extensionFeedItemOperation->setUpdateMask(FieldMasks::allSetFieldsOf($extensionFeedItem));

    // Issues a mutate request to update the extension feed item.
    $extensionFeedItemServiceClient = $googleAdsClient->getExtensionFeedItemServiceClient();
    $response = $extensionFeedItemServiceClient->mutateExtensionFeedItems(
        $customerId,
        [$extensionFeedItemOperation]
    );

    // Prints the resource name of the updated extension feed item.
    /** @var ExtensionFeedItem $updatedExtensionFeedItem */
    $updatedExtensionFeedItem = $response->getResults()[0];
    printf(
        "Updated extension feed item with resource name: '%s'.%s",
        $updatedExtensionFeedItem->getResourceName(),
        PHP_EOL
    );
}

Ruby

client = Google::Ads::GoogleAds::GoogleAdsClient.new

operation = client.operation.update_resource.extension_feed_item(efi_resource_name) do |efi|
  efi.sitelink_feed_item = client.resource.sitelink_feed_item
  efi.sitelink_feed_item.link_text = "Hours of Operation"
end

client.service.extension_feed_item.mutate_extension_feed_items(customer_id, [operation])
    

Perl

sub update_sitelink {
  my ($api_client, $customer_id, $feed_item_id, $sitelink_text) = @_;

  # Create an extension feed item using the specified feed item ID and sitelink text.
  my $extension_feed_item =
    Google::Ads::GoogleAds::V6::Resources::ExtensionFeedItem->new({
      resourceName =>
        Google::Ads::GoogleAds::V6::Utils::ResourceNames::extension_feed_item(
        $customer_id, $feed_item_id
        ),
      sitelinkFeedItem =>
        Google::Ads::GoogleAds::V6::Common::SitelinkFeedItem->new({
          linkText => $sitelink_text
        })});

  # Construct an operation that will update the extension feed item, using the
  # FieldMasks utility to derive the update mask. This mask tells the Google Ads
  # API which attributes of the extension feed item you want to change.
  my $extension_feed_item_operation =
    Google::Ads::GoogleAds::V6::Services::ExtensionFeedItemService::ExtensionFeedItemOperation
    ->new({
      update     => $extension_feed_item,
      updateMask => all_set_fields_of($extension_feed_item)});

  # Issue a mutate request to update the extension feed item.
  my $extension_feed_items_response =
    $api_client->ExtensionFeedItemService()->mutate({
      customerId => $customer_id,
      operations => [$extension_feed_item_operation]});

  # Print the resource name of the updated extension feed item.
  printf
    "Updated extension feed item with resource name: '%s'.\n",
    $extension_feed_items_response->{results}[0]{resourceName};

  return 1;
}