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.

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' => new StringValue(['value' => $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])