DEPRECATED: Update an extension setting

Stay organized with collections Save and categorize content based on your preferences.

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.V13.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
    );
}
      

Python

def main(client, customer_id, feed_item_id, sitelink_text):
    """The main method that creates all necessary entities for the example.

    Args:
        client: an initialized GoogleAdsClient instance.
        customer_id: a client customer ID.
        feed_item_id: the ID of an extension feed item.
        sitelink_text: the updated sitelink text.
    """
    extension_feed_item_service = client.get_service("ExtensionFeedItemService")
    extension_feed_item_operation = client.get_type(
        "ExtensionFeedItemOperation"
    )
    extension_feed_item = extension_feed_item_operation.update
    # Update the extension feed item using the specified feed item ID
    extension_feed_item.resource_name = extension_feed_item_service.extension_feed_item_path(
        customer_id, feed_item_id
    )
    extension_feed_item.sitelink_feed_item.link_text = sitelink_text

    # Produce a field mask enumerating the changed fields
    client.copy_from(
        extension_feed_item_operation.update_mask,
        protobuf_helpers.field_mask(None, extension_feed_item._pb),
    )

    # Update the extension feed item
    response = extension_feed_item_service.mutate_extension_feed_items(
        customer_id=customer_id, operations=[extension_feed_item_operation]
    )
    print(
        "Updated extension feed item with resource name: "
        f'"{response.results[0].resource_name}".'
    )
      

Ruby

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

operation = client.operation.update_resource.extension_feed_item(
  client.path.extension_feed_item(customer_id, feed_item_id)
) do |efi|
  efi.sitelink_feed_item = client.resource.sitelink_feed_item do |sitelink|
    sitelink.link_text = sitelink_text
  end
end

response = client.service.extension_feed_item.mutate_extension_feed_items(
  customer_id: customer_id,
  operations: [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::V13::Resources::ExtensionFeedItem->new({
      resourceName =>
        Google::Ads::GoogleAds::V13::Utils::ResourceNames::extension_feed_item(
        $customer_id, $feed_item_id
        ),
      sitelinkFeedItem =>
        Google::Ads::GoogleAds::V13::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::V13::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;
}