Solution for creating a label when creating a TextAd

203 views
Skip to first unread message

Alan Coleman

unread,
Oct 3, 2014, 6:37:01 AM10/3/14
to adwor...@googlegroups.com
Hello everyone,

I'd like to be able to add a label to a TextAd when creating the TextAd.

I'm creating the TextAd using AdGroupAdOperation.

If I want to use AdGroupAdLabelOperation to add a label then I first have to return the TextAd id from the AdGroupAdOperation.

So am I right in saying that to add a label to a TextAd I have to create both using separate operations then add the Label to the TextAd?

I think I may have answered my own question here, but any suggestions would be helpful.
Many thanks

Michael Cloonan (AdWords API Team)

unread,
Oct 3, 2014, 1:19:06 PM10/3/14
to adwor...@googlegroups.com
Hello,

You are correct; you must create the TextAd first, and then in a separate operation you may assign a label to it. There is no way to assign a label to the TextAd at the time of creation.

Regards,
Mike, AdWords API Team

Alan Coleman

unread,
Oct 8, 2014, 4:18:07 AM10/8/14
to adwor...@googlegroups.com
Thanks for getting back to me Michael! :-)

Martin

unread,
Oct 8, 2014, 6:18:46 PM10/8/14
to adwor...@googlegroups.com
Hi all!
I disagree with the accepted solution. I am currently assigning labels to Text Ads in a single operation at the time of creation. Below is the relevant snippet from my python code. I'm using the MutateJobService and it works just fine.
                adgroup_ad_operations.append({
                    'xsi_type': 'AdGroupAdOperation',
                    'operator': 'ADD',
                    'operand': {
                        'xsi_type': 'AdGroupAd',
                        'adGroupId': adGroupId,
                        'ad': textad,
                        'status': 'ENABLED',
                        'labels': [{'id': Label_id}],
                    },
                })

I hope this helps. :)
Cheers!
Martin

Alan Coleman

unread,
Oct 23, 2014, 5:14:40 AM10/23/14
to adwor...@googlegroups.com
Hi Martin,

Sorry to keep going on about this but I'm confused about how you're getting this to work.

Can I confirm that I'm trying to achieve the same outcome as yourself?
  1.  A Label has been created previously and I have the ID
  2. I want to create a TextAd and assign the above label whilst creating the TextAd
I've tried two services:
  1. AdGroupAdService
  2. MutateJobService
With variations on the following code:

$textAd->displayUrl = $textDisplayUrl;
$textAd->url = $textUrl;
$textAd->labels = $labelid;

This is returning an Undefined index error.

The documentation clearly states that the services are read only and that AdGroupAdService.mutateLabel should be used to add an existing Label to an existing AdGroupAd.
I'd really like to be able to add an existing label when creating a TextAd, I'm just confused about how you're achieving this.

Many thanks

Martin

unread,
Oct 27, 2014, 2:27:39 PM10/27/14
to adwor...@googlegroups.com
Hi Alan,

That's right! The outcome is the same.
I'm using MutateJobServive,mutate and the operations are a list of the ads created. My previous snippet is the creation of such a list.
So it's a regular TextAd creation operation, with an additional key in the dictionary.
Relevant documentation: type AdGroupAd (v201409)
For the label field it states: This field is read only and will be ignored when sent to the API for the following Operators: REMOVE and SET.
What we are doing is an ADD operation because we want to assign the label at the time of creation, so there's no conflict there.

Possible issues that might make your request fail:
  1. Old API version (I guess not as the link you sent is from v201409)
  2. Wrong label structure. What I'm sending in the labels field is a list of dictionaries, just with the labelId. (... 'labels': [{'id': Label_id}], ...)
  3. Wrong method. MutateJobServive,mutate or AdGroupAdService.mutate should work fine as well. Just don't use  AdGroupAdService.mutateLabel, because as you've realised, that's for existing ads.

Let me know if you get it working.
Cheers!
Message has been deleted

Alan Coleman

unread,
Oct 28, 2014, 9:18:40 AM10/28/14
to adwor...@googlegroups.com
Hi Martin,

Thanks for making me stick with this one, I finally got it working. The issue was down to my code rather than your explanation.

I was attempting to add the label ID to the TextAd Object rather than creating a Label Object of its own.

This is what is required when using the PHP Library

$textAdLabel = new Label();
$textAdLabel->id = $val['labelid'];

Simple!

Thanks again for your help and explanation.

Dan Hai

unread,
Mar 3, 2017, 12:59:15 PM3/3/17
to AdWords API Forum
Do you guys know if this is still the case?

Shwetha Vastrad (AdWords API Team)

unread,
Mar 6, 2017, 10:42:11 AM3/6/17
to AdWords API Forum
Hi Dan,

Yes, you'll need to use two separate operations; one to create a Label and another one to apply the Label to your AdGroupAds. To associate an existing Label to an existing AdGroupAd, you need to use AdGroupAdService.mutateLabel with ADD operator. You can also associate an existing label during Ad creation by specifying the Label in the labels field of the AdGroupAd.

Regards,
Shwetha, AdWords API Team.
Reply all
Reply to author
Forward
0 new messages