In the Google Ads API, updates are done using a field mask. The field mask lists all the fields you intend to change with the update, and any specified fields that are not in the field mask will be ignored, even if sent to the server.
The recommended way to generate field masks is using our built-in field mask utility, which hides a lot of the specific details and lets you generate field masks automatically by monitoring the changes you make to the entity's fields.
Here's an example for updating a campaign:
campaign = client.resource(:Campaign) campaign.resource_name = client.path.campaign(customer_id, campaign_id) mask = client.field_mask.with campaign do campaign.status = client.enum(:CampaignStatus)::PAUSED campaign.network_settings = client.resource(:NetworkSettings) campaign.network_settings.target_search_network = client.wrapper.bool(false) end
First, we create an empty Campaign object. Then, we set its resource name so that the API will know exactly which campaign we are updating.
The example uses the
client.field_mask.with method on the campaign to
begin the block encompassing the updates. At the end of this block, the utility
will compare the current status of the campaign after the block with the initial
status of the campaign before the block, and automatically produce a field mask
enumerating the changed fields. You can then pass the returned mask directly to
the update call.
Manually creating a mask
To create a field mask from scratch, you would first create a
Google::Protobuf::FieldMask, then make an array populated with the names of
all the fields you intend to change, and finally assign the array to the field
mask = Google::Protobuf::FieldMask.new mask.path = ["status", "name"]