Update AdGroupAds fields

53 views
Skip to first unread message

Andrej Petričko

unread,
Apr 7, 2025, 1:36:19 PM4/7/25
to Google Ads API and AdWords API Forum
Hello, I am trying to update AdGroupAd using Google API with python and provided google ads api library. But I am getting Immutable field error.


The ad type is ResponsiveSearchAd so it should be mutable as described here:

I found this old example where the ad group ad fields are updated but i does not work.


Here are the code, request and response examples:


Code:

googleads_service = self.google_ads_client.get_service("AdGroupAdService")

operation = self.google_ads_client.get_type("AdGroupAdOperation")

ad_group_ad = operation.update
ad_group_ad.resource_name = ad_group_ad_resource_name

headlines = []

for headline_param in headline_params:
    headline = self.google_ads_client.get_type("AdTextAsset")
    headline.text = self.safe_transform_headline(headline_param)

    if len(headlines) < 3 and len(headlines) <  fixed_headlines_count:
          headline.pinned_field = getattr(
          self.google_ads_client.enums.ServedAssetFieldTypeEnum,
          f"HEADLINE_{len(headlines) + 1}",
          )

     headlines.append(headline)
ad_group_ad.ad.responsive_search_ad.headlines.extend(headlines)

descriptions = []
for description_param in set(description_params):


    description = self.google_ads_client.get_type("AdTextAsset")
    description.text = description_param
    descriptions.append(description)

ad_group_ad.ad.responsive_search_ad.descriptions.extend(descriptions)

ad_group_ad.ad.final_urls.append(url)

self.google_ads_client.copy_from(
operation.update_mask, protobuf_helpers.field_mask(None, ad_group_ad._pb)
)

request = self.google_ads_client.get_type("MutateAdGroupAdsRequest")
request.customer_id = self.customer_id
request.operations = [operation]
request.partial_failure = True
response = self.safe_api_call(
method=ad_group_ad_service.mutate_ad_group_ads,
request=request,
timeout=TIMEOUT_SECONDS,
)


Request:
customer_id: "<<customer_id>>"
operations {
  update {
    resource_name: "customers/<<customer_id>>/adGroupAds/<<ad_group_id>>~<<ad_id>>"
    ad {
      responsive_search_ad {
        headlines {
          pinned_field: HEADLINE_1
          text: "text_1"
        }
        headlines {
          pinned_field: HEADLINE_2
          text: "text_2"
        }
        headlines {
          text: "text_3"
        }
        headlines {
          text: "text_4"
        }
        headlines {
          text: "text_5"
        }
        descriptions {
          text: "desc_1"
        }
        descriptions {
          text: "desc_2"
        }
        descriptions {
          text: "desc_3"
        }       
      }
      final_urls: "url"
    }
  }
  update_mask {
    paths: "resource_name"
    paths: "ad.final_urls"
    paths: "ad.responsive_search_ad.headlines"
    paths: "ad.responsive_search_ad.descriptions"
  }
}
partial_failure: true

Response:
errors {
  error_code {
    request_error: IMMUTABLE_FIELD
  }
  message: "Field \'ad.final_urls\' cannot be modified by \'UPDATE\' operation."
  location {
    field_path_elements {
      field_name: "operations"
      index: 0
    }
    field_path_elements {
      field_name: "update"
    }
    field_path_elements {
      field_name: "ad"
    }
    field_path_elements {
      field_name: "final_urls"
    }
  }
}
errors {
  error_code {
    request_error: IMMUTABLE_FIELD
  }
  message: "Field \'ad.responsive_search_ad.descriptions\' cannot be modified by \'UPDATE\' operation."
  location {
    field_path_elements {
      field_name: "operations"
      index: 0
    }
    field_path_elements {
      field_name: "update"
    }
    field_path_elements {
      field_name: "ad"
    }
    field_path_elements {
      field_name: "responsive_search_ad"
    }
    field_path_elements {
      field_name: "descriptions"
    }
  }
}
errors {
  error_code {
    request_error: IMMUTABLE_FIELD
  }
  message: "Field \'ad.responsive_search_ad.headlines\' cannot be modified by \'UPDATE\' operation."
  location {
    field_path_elements {
      field_name: "operations"
      index: 0
    }
    field_path_elements {
      field_name: "update"
    }
    field_path_elements {
      field_name: "ad"
    }
    field_path_elements {
      field_name: "responsive_search_ad"
    }
    field_path_elements {
      field_name: "headlines"
    }
  }
}








Google Ads API Forum Advisor

unread,
Apr 7, 2025, 6:08:01 PM4/7/25
to petrick...@gmail.com, adwor...@googlegroups.com
Hi,

Thank you for reaching out to the Google Ads API support team. 

The AssetService only supports create operations. Once an asset is uploaded to an advertiser's account, it cannot be changed or removed programmatically. If you try to update an ad using the adGroupAds method you will encounter an IMMUTABLE_FIELD error because it's not possible to update using this method. Note that you cannot update any assets (headlines and descriptions) and final_urls because the field 'ad' itself is an immutable field which means if you try to update any sub-field under the ad then it will encounter an IMMUTABLE_FIELD error. You must use ad-level operations to manage associations between individual assets and ads. I would recommend you to use the ad method to update the ads using the Google Ads API. The example code which you shared also explains you to use the ad operation for updating the ads using the Google Ads API. However, I am sharing with you the sample request and response logs to update the responsive search ads via the Google Ads API:
Request Body:
==============

POST https://googleads.googleapis.com/v19/customers/{customerId}/ads:mutate?key=[YOUR_API_KEY] HTTP/1.1

developer-token: **********************
Authorization: Bearer [YOUR_ACCESS_TOKEN]
Accept: application/json
Content-Type: application/json

{
  "operations": [
    {
      "update": {
        "resourceName": "customers/{customerId}/ads/{adId}",
        "responsiveSearchAd": {
          "descriptions": [
            {
              "text": "sjdf ejkkejhdd"
            },
            {
              "text": "gshahd wjwdhuiwuhdd"
            }
          ],
          "headlines": [
            {
              "text": "esgegb"
            },
            {
              "text": "adhqwjjk"
            },
            {
              "text": "ajddkjae ejadeajff"
            }
          ]
        },
        "finalUrls": [
          "https://www.example.com"
        ]
      },
      "updateMask": "responsiveSearchAd.descriptions,responsiveSearchAd.headlines,finalUrls"
    }
  ]
}

Response:
===========

HTTP/1.1 200 
content-encoding: gzip
content-length: 102
content-type: application/json; charset=UTF-8
date: Mon, 07 Apr 2025 21:43:09 GMT
server: ESF
vary: Origin, X-Origin, Referer

{
  "results": [
    {
      "resourceName": "customers/{customerId}/ads/{adId}"
    }
  ]
}

I hope this clarifies.
 

Thanks,
 
Google Logo Google Ads API Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5
[2025-04-07 22:07:13Z GMT] This message is in relation to case "ref:!00D1U01174p.!500Ht01pRmlF:ref" (ADR-00298863)



Reply all
Reply to author
Forward
0 new messages