Share your feedback about the Google Ads (AdWords) API. Take the 2021 AdWords API and Google Ads API Annual Survey.

Example: Updating flight prices

Assume you have a flight reservation site where you've set up Dynamic Remarketing ads, and you want to update the sale price on some flights and remove the sale price on others. To ensure that your ads display the correct prices for each flight, you'll want to update the price on each flight's corresponding FeedItem.

Updating the price of a flight

This is similar to creating new FeedItem objects. However, to update the FeedItemAttributeValue of flight price, you must update the FeedItem with the new FeedItemAttributeValue. In order to do so, you must retrieve the feed_attribute_id using the FlightPlaceholderField, so that you can indicate which FeedAttribute. It's also important to note that you must include all of the other existing FeedItemAttributeValue objects that you don't want to change in the FeedItem. If you fail to do so, they will be removed from the FeedItem. Full list of FlightPlaceholderField values.

The basic steps to modify each flight entry are:

  1. Get the mapping from placeholder to feed attribute ID using the utility method.
  2. Use the mapping and placeholder field to get the ID of the FeedItemAttributeValue.
  3. Get the FeedItem containing the FeedItemAttributeValue that will be updated.
  4. Create a FeedItemAttributeValue using the feed_attribute_id obtained previously and the updated value of the FeedItemAttributeValue.
  5. Construct a new FeedItem from the existing FeedItem. Any FeedItemAttributeValues that are not included in the updated FeedItem will be removed from the FeedItem, which is why you must create the FeedItem from the existing FeedItem and set the fields that are to be updated.
  6. Create a new FeedItemOperation as an update operation with an update_mask of the set fields of the newly created FeedItem.

Java

private void updateFeedItem(
    GoogleAdsClient googleAdsClient,
    long customerId,
    long feedId,
    long feedItemId,
    String flightPlaceholderField,
    String attributeValue) {
  // Gets the feed resource name.
  String feedResourceName = ResourceNames.feed(customerId, feedId);

  // Gets a map of the placeholder values and feed attributes.
  Map<FlightPlaceholderField, FeedAttribute> feedAttributes =
      AddFlightsFeed.getFeed(googleAdsClient, customerId, feedResourceName);

  // Gets the ID of the attribute to update. This is needed to specify which
  // FeedItemAttributeValue will be updated in the given FeedItem.
  long attributeId =
      feedAttributes
          .get(FlightPlaceholderField.valueOf(flightPlaceholderField.toUpperCase()))
          .getId();
  // Gets the feed item resource name.
  String feedItemResourceName = ResourceNames.feedItem(customerId, feedId, feedItemId);
  // Retrieves the feed item and its associated attributes based on its resource name.
  FeedItem feedItem = getFeedItem(googleAdsClient, customerId, feedItemResourceName);
  // Creates the updated FeedItemAttributeValue.
  FeedItemAttributeValue feedItemAttributeValue =
      FeedItemAttributeValue.newBuilder()
          .setFeedAttributeId(attributeId)
          .setStringValue(attributeValue)
          .build();
  // Creates a new FeedItem from the existing FeedItem. Any FeedItemAttributeValues that are
  // not included in the updated FeedItem will be removed from the FeedItem, which is why you
  // must create the FeedItem from the existing FeedItem and set the field(s) that will be
  // updated.
  feedItem =
      feedItem.toBuilder()
          // Sets the attribute value of the FeedItem given its index relative to other attributes
          // in the FeedItem.
          .setAttributeValues(
              // Gets the index of the attribute value that will be updated.
              getAttributeIndex(feedItem, feedItemAttributeValue), feedItemAttributeValue)
          .build();

  // Creates the operation.
  FeedItemOperation operation =
      FeedItemOperation.newBuilder()
          .setUpdate(feedItem)
          .setUpdateMask(FieldMasks.allSetFieldsOf(feedItem))
          .build();

  // Creates the feed item service client.
  try (FeedItemServiceClient feedItemServiceClient =
      googleAdsClient.getLatestVersion().createFeedItemServiceClient()) {
    // Updates the feed item.
    MutateFeedItemsResponse response =
        feedItemServiceClient.mutateFeedItems(
            Long.toString(customerId), ImmutableList.of(operation));
    for (MutateFeedItemResult result : response.getResultsList()) {
      System.out.printf("Updated feed item with resource name '%s'.%n", result.getResourceName());
    }
  }
}
      

C#

private void UpdateFeedItem(GoogleAdsClient client, long customerId, long feedId,
    long feedItemId, string flightPlaceholderFieldName, string attributeValue)
{
    // Get the FeedItemServiceClient.
    FeedItemServiceClient feedItemService =
        client.GetService(Services.V9.FeedItemService);

    // Gets the feed resource name.
    string feedResourceName = ResourceNames.Feed(customerId, feedId);

    // Gets a map of the placeholder values and feed attributes.
    Dictionary<FlightPlaceholderField, FeedAttribute> feedAttributes =
        GetFeed(client, customerId, feedResourceName);

    // Gets the ID of the attribute to update. This is needed to specify which
    // FeedItemAttributeValue will be updated in the given FeedItem.
    FlightPlaceholderField placeholderField = (FlightPlaceholderField) Enum.Parse(
        typeof(FlightPlaceholderField), flightPlaceholderFieldName);
    long attributeId = feedAttributes[placeholderField].Id;

    // Gets the feed item resource name.
    string feedItemResourceName = ResourceNames.FeedItem(customerId, feedId, feedItemId);
    // Retrieves the feed item and its associated attributes based on its resource name.
    FeedItem feedItem = GetFeedItem(client, customerId, feedItemResourceName);
    // Creates the updated FeedItemAttributeValue.
    FeedItemAttributeValue feedItemAttributeValue = new FeedItemAttributeValue()
    {
        FeedAttributeId = attributeId,
        StringValue = attributeValue
    };

    // Creates a new FeedItem from the existing FeedItem. Any FeedItemAttributeValues that
    // are not included in the updated FeedItem will be removed from the FeedItem, which is
    // why you must create the FeedItem from the existing FeedItem and set the field(s)
    // that will be updated.
    int attributeIndex = feedItem.AttributeValues
        .Select((item, index) => new { item, index })
        .Where(itemIndexPair =>
            itemIndexPair.item.FeedAttributeId == feedItemAttributeValue.FeedAttributeId)
        .Select(itemIndexPair => itemIndexPair.index + 1)
        .FirstOrDefault() - 1;

    if (attributeIndex == -1)
    {
        throw new ArgumentException("No matching feed attribute found for " +
            $"value '{feedItemAttributeValue}'.");
    }

    feedItem.AttributeValues[attributeIndex] = feedItemAttributeValue;

    // Creates the operation.
    FeedItemOperation operation = new FeedItemOperation()
    {
        Update = feedItem,
        UpdateMask = FieldMasks.AllSetFieldsOf(feedItem)
    };

    // Updates the feed item.
    MutateFeedItemsResponse response =
        feedItemService.MutateFeedItems(customerId.ToString(), new[] { operation });

    foreach (MutateFeedItemResult result in response.Results)
    {
        Console.WriteLine($"Updated feed item with resource name " +
            $"'{result.ResourceName}'.");
    }
}

/// <summary>
/// Retrieves details about a feed. The initial query retrieves the FeedAttributes, or
/// columns, of the feed. Each FeedAttribute will also include the FeedAttributeId, which
/// will be used in a subsequent step. The example then inserts a new key, value pair into
/// a map for each FeedAttribute, which is the return value of the method. The keys are the
/// placeholder types that the columns will be. The values are the FeedAttributes.
/// </summary>
/// <param name="client">The Google Ads client.</param>
/// <param name="customerId">
/// The Google Ads customer ID for which the flights feed is added.
/// </param>
/// <param name="feedResourceName">The resource name of the feed.</param>
/// <returns>A Map containing the FlightPlaceholderField and FeedAttribute.</returns>
public Dictionary<FlightPlaceholderField, FeedAttribute> GetFeed(
    GoogleAdsClient client, long customerId, string feedResourceName)
{
    // Get the GoogleAdsService.
    GoogleAdsServiceClient googleAdsService = client.GetService(
        Services.V9.GoogleAdsService);

    // Constructs the query.
    string query = "SELECT feed.attributes FROM feed WHERE feed.resource_name = " +
        $"'{feedResourceName}'";

    // Constructs the request.
    SearchGoogleAdsRequest request = new SearchGoogleAdsRequest()
    {
        CustomerId = customerId.ToString(),
        Query = query
    };

    // Issues the search request and get the first result, since we only need the single
    // feed item we created previously..
    GoogleAdsRow googleAdsRow = googleAdsService.Search(request).First();

    // Gets the attributes list from the feed and creates a map with keys of each attribute
    // and values of each corresponding ID.
    Dictionary<FlightPlaceholderField, FeedAttribute> feedAttributes =
        new Dictionary<FlightPlaceholderField, FeedAttribute>();

    // Loops through the feed attributes to populate the map.
    foreach (FeedAttribute feedAttribute in googleAdsRow.Feed.Attributes)
    {
        switch (feedAttribute.Name)
        {
            case "Flight Description":
                feedAttributes[FlightPlaceholderField.FlightDescription] = feedAttribute;
                break;

            case "Destination ID":
                feedAttributes[FlightPlaceholderField.DestinationId] = feedAttribute;
                break;

            case "Flight Price":
                feedAttributes[FlightPlaceholderField.FlightPrice] = feedAttribute;
                break;

            case "Flight Sale Price":
                feedAttributes[FlightPlaceholderField.FlightSalePrice] = feedAttribute;
                break;

            case "Final URLs":
                feedAttributes[FlightPlaceholderField.FinalUrls] = feedAttribute;
                break;
            // The full list of FlightPlaceholderFields can be found here
            // https://developers.google.com/google-ads/api/reference/rpc/latest/FlightPlaceholderFieldEnum.FlightPlaceholderField
            default:
                throw new Exception("Invalid attribute name.");
        }
    }

    return feedAttributes;
}

/// <summary>
/// Retrieves a feed item and its attribute values given a resource name.
/// </summary>
/// <param name="client">The Google Ads client.</param>
/// <param name="customerId">
/// The Google Ads customer ID for which the flights feed is added.
/// </param>
/// <param name="feedItemResourceName">Feed item resource name.</param>
/// <returns>FeedItem with the given resource name.</returns>
private FeedItem GetFeedItem(GoogleAdsClient client, long customerId,
    string feedItemResourceName)
{
    // Get the GoogleAdsService.
    GoogleAdsServiceClient googleAdsService = client.GetService(
        Services.V9.GoogleAdsService);

    // Constructs the query.
    string query = "SELECT feed_item.attribute_values FROM feed_item WHERE " +
        $"feed_item.resource_name = '{feedItemResourceName}'";

    // Constructs the request.
    SearchGoogleAdsRequest request = new SearchGoogleAdsRequest()
    {
        CustomerId = customerId.ToString(),
        Query = query
    };

    return googleAdsService.Search(request).First().FeedItem;
}
      

PHP

public static function runExample(
    GoogleAdsClient $googleAdsClient,
    int $customerId,
    int $feedId,
    int $feedItemId,
    string $flightPlaceholderFieldName,
    string $attributeValue
) {
    // Gets a map of the placeholder values to feed attributes.
    $placeHoldersToFeedAttributesMap = Feeds::flightPlaceholderFieldsMapFor(
        ResourceNames::forFeed($customerId, $feedId),
        $customerId,
        $googleAdsClient
    );
    // Gets the ID of the feed attribute for the placeholder field. This is needed to specify
    // which feed item attribute value will be updated in the given feed item.
    $attributeId = $placeHoldersToFeedAttributesMap[
        FlightPlaceholderField::value($flightPlaceholderFieldName)]->getId();
    // Creates the updated feed item attribute value.
    $updatedFeedItemAttributeValue = new FeedItemAttributeValue([
        'feed_attribute_id' => $attributeId,
        'string_value' => $attributeValue
    ]);

    // Retrieves the feed item and its associated attributes based on the resource name.
    $feedItem = Feeds::feedItemFor(
        ResourceNames::forFeedItem($customerId, $feedId, $feedItemId),
        $customerId,
        $googleAdsClient
    );
    // Gets the index of the attribute value that will be updated in the feed item.
    $attributeIndex = Feeds::attributeIndexFor($updatedFeedItemAttributeValue, $feedItem);
    // Any feed item attribute values that are not included in the updated feed item will be
    // removed from the feed item, which is why you must create the feed item from the existing
    // feed item and its attribute values. Then, update only the attribute that you want.
    $feedItemAttributeValues = $feedItem->getAttributeValues();
    $feedItemAttributeValues[$attributeIndex] = $updatedFeedItemAttributeValue;
    $feedItem->setAttributeValues($feedItemAttributeValues);

    // Creates the feed item operation.
    $operation = new FeedItemOperation();
    $operation->setUpdate($feedItem);
    $operation->setUpdateMask(FieldMasks::allSetFieldsOf($feedItem));

    // Issues a mutate request to update the feed item and print some information.
    $feedItemServiceClient = $googleAdsClient->getFeedItemServiceClient();
    $response = $feedItemServiceClient->mutateFeedItems($customerId, [$operation]);
    printf(
        "Feed item with resource name '%s' was updated.%s",
        $response->getResults()[0]->getResourceName(),
        PHP_EOL
    );
}
      

Python

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

    Args:
        client: an initialized GoogleAdsClient instance
        customer_id: a client customer ID
        feed_id: the ID of feed containing the feed item to be updated
        feed_item_id: The ID of the feed item to be updated
        flight_placeholder_field_name: the flight placeholder field name for
            the attribute to be updated
        attribute_value: the new value to set the feed attribute to
    """
    feed_service = client.get_service("FeedService")
    # Gets a map of the placeholder values to feed attributes.
    placeholders_to_feed_attribute_map = _flight_placeholder_fields_map(
        client, customer_id, feed_service.feed_path(customer_id, feed_id)
    )
    # Gets the ID of the feed attribute for the placeholder field. This is
    # needed to specify which feed item attribute value will be updated in
    # the given feed item.
    flight_placeholder_field_enum = client.enums.FlightPlaceholderFieldEnum
    flight_placeholder_enum_value = getattr(
        flight_placeholder_field_enum, flight_placeholder_field_name
    )
    attribute_id = placeholders_to_feed_attribute_map[
        flight_placeholder_enum_value
    ].id

    # Creates the updated feed item attribute value.
    updated_feed_item_attribute_value = client.get_type(
        "FeedItemAttributeValue"
    )
    updated_feed_item_attribute_value.feed_attribute_id = attribute_id
    updated_feed_item_attribute_value.string_value = attribute_value

    # Retrieves the feed item and its associated attributes based on the
    # resource name.
    feed_item_service = client.get_service("FeedItemService")
    feed_item = _get_feed_item(
        client,
        customer_id,
        feed_item_service.feed_item_path(customer_id, feed_id, feed_item_id),
    )

    # Gets the index of the attribute value that will be updated in the
    # feed item.
    attribute_index = _get_attribute_index(
        updated_feed_item_attribute_value, feed_item
    )
    # Any feed item attribute values that are not included in the updated
    # feed item will be removed from the feed item, which is why you must
    # create the feed item from the existing feed item and its attribute
    # values. Then, update only the attribute that you want.
    feed_item_operation = client.get_type("FeedItemOperation")
    client.copy_from(feed_item_operation.update, feed_item)
    updated_feed_item = feed_item_operation.update
    client.copy_from(
        updated_feed_item.attribute_values[attribute_index],
        updated_feed_item_attribute_value,
    )

    # Create a field mask using the old feed_item and the updated_feed_item.
    client.copy_from(
        feed_item_operation.update_mask,
        protobuf_helpers.field_mask(feed_item._pb, updated_feed_item._pb),
    )

    response = feed_item_service.mutate_feed_items(
        customer_id=customer_id, operations=[feed_item_operation]
    )
    print(
        "Feed item with resource name: "
        f"'{response.results[0].resource_name}' was updated."
    )
      

Ruby

def update_flights_feed_item_string_attribute_value(
  customer_id,
  feed_id,
  feed_item_id,
  flight_placeholder_field_name,
  attribute_value)
  # GoogleAdsClient will read a config file from
  # ENV['HOME']/google_ads_config.rb when called without parameters
  client = Google::Ads::GoogleAds::GoogleAdsClient.new

  # Gets a map of the placeholder values to feed attributes.
  placeholders_to_feed_attributes_map = flight_placeholder_fields_map_for(
    client,
    customer_id,
    client.path.feed(customer_id, feed_id),
  )

  # Gets the ID of the feed attribute for the placeholder field. This is
  # needed to specify which feed item attribute value will be updated in the
  # given feed item.
  attribute_id = placeholders_to_feed_attributes_map[
    flight_placeholder_field_name.to_sym].id

  # Retrieves the feed item and its associated attributes based on the resource
  # name.
  feed_item_resource_name = client.path.feed_item(customer_id, feed_id, feed_item_id)
  feed_item = feed_item_for(
    client,
    customer_id,
    feed_item_resource_name,
  )

  # Creates the updated feed item attribute value.
  updated_feed_item_attribute_value = client.resource.feed_item_attribute_value do |v|
    v.feed_attribute_id = attribute_id
    v.string_value = attribute_value
  end

  # Gets the index of the attribute value that will be updated in the feed item.
  attribute_index = attribute_index_for(
    updated_feed_item_attribute_value,
    feed_item,
  )

  # Any feed item attribute values that are not included in the feed item will
  # be removed, which is why you must retain all other feed attribute values
  # here.
  feed_item_attribute_values = feed_item.attribute_values
  puts feed_item_attribute_values
  feed_item_attribute_values[attribute_index] =
    client.resource.feed_item_attribute_value do |v|
      v.feed_attribute_id = attribute_id
      v.string_value = attribute_value
    end

  # Creates the feed item operation.
  operation = client.operation.update_resource.feed_item(feed_item_resource_name) do |item|
    item.attribute_values.replace(feed_item_attribute_values.to_a)
  end

  # Issues a mutate request to update the feed item and print some information.
  response = client.service.feed_item.mutate_feed_items(
    customer_id: customer_id,
    operations: [operation],
  )
  puts "Feed item with resource name " \
    "'#{response.results.first.resource_name}' was updated."
end
      

Perl

sub update_flights_feed_item_string_attribute_value {
  my ($api_client, $customer_id, $feed_id, $feed_item_id,
    $flight_placeholder_field_name,
    $attribute_value)
    = @_;

  # Get the feed resource name.
  my $feed_resource_name =
    Google::Ads::GoogleAds::V9::Utils::ResourceNames::feed($customer_id,
    $feed_id);

  # Get a hash of the placeholder values and feed attributes.
  my $feed_attributes =
    get_feed($api_client, $customer_id, $feed_resource_name);

  # Get the ID of the attribute to update. This is needed to specify which
  # FeedItemAttributeValue will be updated in the given FeedItem.
  my $attribute_id = $feed_attributes->{uc($flight_placeholder_field_name)}{id};

  # Get the feed item resource name.
  my $feed_item_resource_name =
    Google::Ads::GoogleAds::V9::Utils::ResourceNames::feed_item($customer_id,
    $feed_id, $feed_item_id);

  # Retrieve the feed item and its associated attributes based on its resource name.
  my $feed_item =
    get_feed_item($api_client, $customer_id, $feed_item_resource_name);

  # Create the updated FeedItemAttributeValue.
  my $feed_item_attribute_value =
    Google::Ads::GoogleAds::V9::Resources::FeedItemAttributeValue->new({
      feedAttributeId => $attribute_id,
      stringValue     => $attribute_value
    });

  # Get the index of the attribute value that will be updated.
  my $attribute_index = get_attribute_index($feed_item, $attribute_id);

  # Set the attribute value of the FeedItem given its index relative to other attributes
  # in the FeedItem.
  $feed_item->{attributeValues}[$attribute_index] = $feed_item_attribute_value;

  # Create a feed item operation.
  my $feed_item_operation =
    Google::Ads::GoogleAds::V9::Services::FeedItemService::FeedItemOperation->
    new({
      update     => $feed_item,
      updateMask => all_set_fields_of($feed_item)});

  # Update the feed item.
  my $feed_items_response = $api_client->FeedItemService()->mutate({
      customerId => $customer_id,
      operations => [$feed_item_operation]});

  printf "Updated feed item with resource name: '%s'.\n",
    $feed_items_response->{results}[0]{resourceName};

  return 1;
}
      

Removing the sale price of a flight

Removing a FeedItemAttributeValue from a FeedItem requires basically the same steps as updating a FeedItemAttributeValue because, in either case, you must perform an update FeedItemOperation to update the FeedItem. The only difference is that instead of updating the FeedItemAttributeValue from the FeedItem, you remove it.

The basic steps to remove an FeedItemAttributeValue from a FeedItem are:

  1. Get the ID of the attribute you want to remove.
  2. Retrieve the FeedItem you will be updating.
  3. Create a new FeedItemAttributeValue with the attribute ID you retrieved earlier. You don't have to set the value for the FeedItemAttributeValue because the FeedItemAttributeValue will be removed.
  4. Get the index of the attribute that will be removed.
  5. Remove the attribute value from the FeedItem and perform the update operation on the FeedItem in the same way you would if you were updating the attribute value.

Java

private FeedItem removeAttributeValueFromFeedItem(
    GoogleAdsClient googleAdsClient,
    long customerId,
    Map<FlightPlaceholderField, FeedAttribute> feedAttributes,
    String feedItemResourceName,
    FlightPlaceholderField flightPlaceholderField) {
  // Gets the ID of the FeedAttribute for the placeholder field and converts to an integer.
  long attributeId = feedAttributes.get(flightPlaceholderField).getId();

  // Retrieves the feed item and its associated attributes based on its resource name.
  FeedItem feedItem = getFeedItem(googleAdsClient, customerId, feedItemResourceName);
  // Creates the FeedItemAttributeValue that will be updated.
  FeedItemAttributeValue feedItemAttributeValue =
      FeedItemAttributeValue.newBuilder().setFeedAttributeId(attributeId).build();
  // Gets the index of the attribute value that will be removed.
  int attributeIndex = getAttributeIndex(feedItem, feedItemAttributeValue);

  // Returns the feed item with the removed FeedItemAttributeValue. Any FeedItemAttributeValues
  // that are not included in the updated FeedItem will be removed from the FeedItem, which is
  // why you must create the FeedItem from the existing FeedItem and set the field(s) that will
  // be removed.
  return feedItem.toBuilder().removeAttributeValues(attributeIndex).build();
}
      

C#

private FeedItem RemoveAttributeValueFromFeedItem(GoogleAdsClient client, long customerId,
    long feedId, long feedItemId,
    Dictionary<FlightPlaceholderField, FeedAttribute> placeholdersToFeedAttributesMap,
    FlightPlaceholderField flightPlaceholderFieldName)
{
    // Gets the ID of the FeedAttribute for the placeholder field.
    long attributeId = placeholdersToFeedAttributesMap[flightPlaceholderFieldName].Id;

    // Retrieves the feed item and its associated attributes based on its resource name.
    FeedItem feedItem = GetFeedItem(client, customerId, feedId, feedItemId);

    //Creates the FeedItemAttributeValue that will be updated.
    FeedItemAttributeValue feedItemAttributeValue = new FeedItemAttributeValue
    {
        FeedAttributeId = attributeId
    };

    // Gets the index of the attribute value that will be removed.
    int attributeIndex = feedItem.AttributeValues
        .Select((item, index) => new { item, index })
        .Where(itemIndexPair =>
            itemIndexPair.item.FeedAttributeId == feedItemAttributeValue.FeedAttributeId)
        .Select(itemIndexPair => itemIndexPair.index + 1)
        .FirstOrDefault() - 1;

    if (attributeIndex == -1)
    {
        throw new ArgumentException("No matching feed attribute found for " +
            $"value '{feedItemAttributeValue}'.");
    }

    // Returns the feed item with the removed FeedItemAttributeValue. Any
    // FeedItemAttributeValues that are not included in the updated FeedItem will be
    // removed from the FeedItem, which is why you must create the FeedItem from the
    // existing FeedItem and set the field(s) that will be removed.
    feedItem.AttributeValues.RemoveAt(attributeIndex);
    return feedItem;
}
      

PHP

// Gets a map of the placeholder values to feed attributes.
$placeHoldersToFeedAttributesMap = Feeds::flightPlaceholderFieldsMapFor(
    ResourceNames::forFeed($customerId, $feedId),
    $customerId,
    $googleAdsClient
);
// Gets the ID of the feed attribute for the placeholder field.
$attributeId = $placeHoldersToFeedAttributesMap[
    FlightPlaceholderField::value($flightPlaceholderFieldName)]->getId();
// Creates the feed item attribute value that will be removed, so only the feed attribute ID
// is needed.
$removedFeedItemAttributeValue = new FeedItemAttributeValue([
    'feed_attribute_id' => $attributeId
]);

// Retrieves the feed item and its associated attributes based on the resource name.
$feedItem = Feeds::feedItemFor(
    ResourceNames::forFeedItem($customerId, $feedId, $feedItemId),
    $customerId,
    $googleAdsClient
);
// Gets the index of the attribute value that will be removed in the feed item.
$attributeIndex = Feeds::attributeIndexFor($removedFeedItemAttributeValue, $feedItem);
// Any feed item attribute values that are not included in the feed item will be removed,
// which is why you must retain all other feed attribute values here.
$feedItemAttributeValues = array_filter(
    iterator_to_array($feedItem->getAttributeValues()->getIterator()),
    function ($index) use ($attributeIndex) {
        return $index !== $attributeIndex;
    },
    ARRAY_FILTER_USE_KEY
);
$feedItem->setAttributeValues($feedItemAttributeValues);
      

Python

# Get the FeedItemService client.
feed_item_service = client.get_service("FeedItemService")

# Create the FeedItemOperation.
feed_item_operation = client.get_type("FeedItemOperation")

# Get a map of the FlightPlaceholderFields to FeedAttributes.
placeholders_to_feed_attributes_map = _get_feed(
    client, customer_id, feed_id
)

# Remove the attribute from the feed item.
flight_placeholder_field = client.enums.FlightPlaceholderFieldEnum[
    flight_placeholder_field_name
].value
feed_item = _remove_attribute_value_from_feed_item(
    client,
    customer_id,
    feed_id,
    feed_item_id,
    placeholders_to_feed_attributes_map,
    flight_placeholder_field,
)
client.copy_from(feed_item_operation.update, feed_item)
# Configure the operation.
client.copy_from(
    feed_item_operation.update_mask,
    protobuf_helpers.field_mask(None, feed_item._pb),
)

# Update the feed item and print the results.
response = feed_item_service.mutate_feed_items(
    customer_id=customer_id, operations=[feed_item_operation]
)
      

Ruby

# Gets a map of the placeholder values to feed attributes.
placeholders_to_feed_attributes_map = flight_placeholder_fields_map_for(
  client,
  customer_id,
  client.path.feed(customer_id, feed_id),
)

# Gets the ID of the feed attribute for the placeholder field.
attribute_id = placeholders_to_feed_attributes_map[
  flight_placeholder_field_name.to_sym].id

# Creates the feed item attribute value that will be removed, so only the
# feed attribute ID is needed.
remove_feed_item_attribute_value = client.resource.feed_item_attribute_value do |v|
  v.feed_attribute_id = attribute_id
end

# Retrieves the feed item and its associated attributes based on the resource
# name.
feed_item_resource_name = client.path.feed_item(customer_id, feed_id, feed_item_id)
feed_item = feed_item_for(
  client,
  customer_id,
  feed_item_resource_name,
)

# Gets the index of the attribute value that will be removed in the feed item.
attribute_index = attribute_index_for(
  remove_feed_item_attribute_value,
  feed_item,
)

# Any feed item attribute values that are not included in the feed item will
# be removed, which is why you must retain all other feed attribute values
# here.
feed_item_attribute_values = feed_item.attribute_values.select.with_index {
  |item, idx| idx != attribute_index
}
      

Perl

# Get the feed resource name.
my $feed_resource_name =
  Google::Ads::GoogleAds::V9::Utils::ResourceNames::feed($customer_id,
  $feed_id);

# Get a hash of the placeholder values and feed attributes.
my $feed_attributes =
  get_feed($api_client, $customer_id, $feed_resource_name);

# Get the feed item resource name.
my $feed_item_resource_name =
  Google::Ads::GoogleAds::V9::Utils::ResourceNames::feed_item($customer_id,
  $feed_id, $feed_item_id);

# Remove the attribute from the feed item.
my $feed_item =
  remove_attribute_value_from_feed_item($api_client, $customer_id,
  $feed_attributes, $feed_item_resource_name,
  uc($flight_placeholder_field_name));