The field attempted to be mutated is immutable

521 views
Skip to first unread message

Quang Quy

unread,
Jul 26, 2022, 10:55:41 AM7/26/22
to Google Ads Scripts Forum
I want to remove the audience from the ad group but get an error. I don't know how to fix it, can someone tell me where the error is.
Here is my code:
const operation = adGroup
            .videoTargeting()
            .newAudienceBuilder()
            .withAudienceId(audience.audience_id)
            .withAudienceType(audience.adGroupCriterion.type)
            .exclude();

          if (!operation.isSuccessful()) {
            console.warn(
              `Failed to exclude audience ${audience.adGroupCriterion.displayName} from ad group ${audience.adGroup.name}. ` +
                `Errors: ${operation.getErrors().join(', ')}'`
            );
          }

This is the error I get:
Errors: The field attempted to be mutated is immutable. ({"errorCode":{"fieldError":"IMMUTABLE_FIELD"},"message":"The field attempted to be mutated is immutable.","location":{"fieldPathElements":[{"fieldName":"mutate_operations" ,"index":0},{"fieldName":"ad_group_criterion_operation"},{"fieldName":"create"},{"fieldName":"negative"}]}})

---------------------------------------------------------------
screenshot_1658833333.png

Google Ads Scripts Forum Advisor

unread,
Jul 27, 2022, 2:29:39 AM7/27/22
to adwords...@googlegroups.com

Hi Quang,

 

Thank you for reaching out to us. This is Yasmin from the Google Ads Scripts team.

 

For us to further investigate and better address your issue, it would be highly appreciated if you can provide the following information below:

  • Google Ads account ID / CID
  • Script name
  • Shareable link (guide) of your spreadsheet, if applicable.

 

Kindly send the requested items via `Reply privately to author` option. If the said option is not available on your end, you may send those through this email alias <googleadsscr...@google.com> instead.

 

Regards,

 

Google Logo
Yasmin Gabrielle
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2d1bzO:ref

Google Ads Scripts Forum Advisor

unread,
Jul 28, 2022, 2:46:32 AM7/28/22
to adwords...@googlegroups.com

Hello Quang,

I made a copy of your script and tested it, then I was able to reproduce the same issue on my end. I checked our documentation, and I didn’t see any references for this kind of immutable behavior upon excluding a specific audience on video ad group level. Having said that, I will be raising this issue to our internal for further investigation. Rest assured that someone from our team will get back to you with an update.

Regards,

Google Logo
James Howell
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2d1bzO:ref

Google Ads Scripts Forum Advisor

unread,
Aug 23, 2022, 9:28:49 PM8/23/22
to adwords...@googlegroups.com

Hi Quang,

 

We appreciate your patience. I just heard back from the team regarding this issue.

 

Upon their investigation, they stated that it looks like you have already included Handbags as a user interest target and want to remove the targeting. But you have written code to create an exclusion rule for Handbags, and you are getting an error because the system interprets this as a request to toggle the positive target to a negative target (which is not allowed).

 

If you just want to remove all Handbag targeting, you should replace this part of the code snippet:

const operation = videoAdGroup
    .videoTargeting()
    .newAudienceBuilder()
    .withAudienceId(audienceId)
    .withAudienceType('USER_INTEREST')
    .exclude();

 

with the following code snippet:

const audiences = videoAdGroup.videoTargeting().audiences().get();
for (const audience of audiences) {
  if (audience.getAudienceId() === String(audienceId)) {
    audience.remove();
  }
}

 

Additionally, if you would like to toggle the Handbag targeting from a positive target to a negative target, then you should combine the two code snippets together. This will remove the positive target and then create the exclusion rule.

const audiences = videoAdGroup.videoTargeting().audiences().get();
for (const audience of audiences) {
  if (audience.getAudienceId() === String(audienceId)) {
    audience.remove();
  }
}

const operation = videoAdGroup
    .videoTargeting()
    .newAudienceBuilder()
    .withAudienceId(audienceId)
    .withAudienceType('USER_INTEREST')
    .exclude();

 

Let us know how it goes over at your end.

 

Regards,

 

 

Google Logo
Yasmin Gabrielle
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2d1bzO:ref
Reply all
Reply to author
Forward
0 new messages