unable to remove labels from AdGroupCriterion using php client library

55 views
Skip to first unread message

orzorc

unread,
Dec 14, 2017, 5:29:51 AM12/14/17
to AdWords API Forum
Hi,
I found that AdGroupCriterion.setLabels requires an array which means you can not set null to labels.
But if you pass it with an empty array and upload, you will get errors like 'operations[0].operand.labels[0].id=>EntityNotFound.INVALID_ID'.
So one will not be able to remove labels from those AdGroupCriterion instances.
Any workaround beside copy every property to a new instances?

Milind Sankeshware (AdWords API Team)

unread,
Dec 14, 2017, 3:29:34 PM12/14/17
to AdWords API Forum
Hi Orzorc,

To removes labels from the AdGroupCriterion, you can use mutateLabel of AdGroupCriterionService and pass the label id which you want to remove. For more information please check this guide

Could you try this and let me know if you are facing any issues?

Thanks,
Milind, AdWords API Team.

orzorc

unread,
Dec 14, 2017, 10:47:35 PM12/14/17
to AdWords API Forum
Hi Milind,
Sorry I didn't make myself clear.
Actually I am not trying to remove labels from exsiting criterion but set labels property to null in AdGroupCriterion instance.
And this is my case:
I get some AdGroupCriterion objects via AdGroupCriterionService and pass them through my code, in this process, I may modify those objects, including remove their labels property.
I will use those modified object in follow up Operations, maybe Operator::ADD. If I could set the labels property to null, I will not need to remove it using mutateLabel

Milind Sankeshware (AdWords API Team)

unread,
Dec 15, 2017, 4:34:58 PM12/15/17
to AdWords API Forum
Hi Orzorc,

When you perform an AdGroupCriterionService.get(), you will have the labels populated, if there is a label set for that criterion. To add or remove the label to the criterion, the only option is to use the AdGroupCriterionService.muateLabel(). If you are trying to model a new AdGroupCriterion instance from the existing one and remove the already present label in that instance, you could try passing any empty Label array. For instance, in Java you could do something as given below :

biddableAdGroupCriterion.setLabels(new Label[]{});

Let me know if you have further questions.

Thanks,
Milind, AdWords API Team

orzorc

unread,
Dec 15, 2017, 8:58:03 PM12/15/17
to AdWords API Forum
Hi Milind,

I have tried to passing an empty Label array.
But I got 'operations[0].operand.labels[0].id=>EntityNotFound.INVALID_ID' error as my previous post said.
Now I am using Reflection in PHP to set the property to null and it works fine.
But I don't think it's a good practice. 
Maybe client library could have a method to set property 'labels' to null.

Milind Sankeshware (AdWords API Team)

unread,
Dec 18, 2017, 3:07:35 PM12/18/17
to AdWords API Forum
Hi Orzorc,

I tried the below line of code in PHP and was able to set the Label in the AdGroupCriterion to null in the request. Please check the attached logs for reference. 

$adGroupCriterion->setLabels([new Label()]);

Could you please try passing the empty array as above and let me know if you are still facing issues? If so, please share the SOAP logs and your code snippet so that I can check the issue.
Request_empty_label_array
Reply all
Reply to author
Forward
0 new messages