Create a new label using Ads API

65 views
Skip to first unread message

Peter Vanek

unread,
Oct 1, 2020, 1:57:03 PM10/1/20
to AdWords API and Google Ads API Forum
Hi,
I am trying to create a new label using Ads API in PHP using the official php library. According to the specification the right way how to create a label is

"
  1. Create a TextLabel instance.
  2. Set the desired background color for this TextLabel.
  3. Enter text for this TextLabel using the description field.
  4. Wrap the TextLabel in a LabelOperation and send it to LabelService.MutateLabels.

    "
How exactly should I do that? When I try to do

$labelOperation = new LabelOperation();
$labelOperation->setCreate($lbl);
$operations = [$labelOperation];

it ends with an error - the setCreate() method throws an exception "
Expect Google\Ads\GoogleAds\V5\Resources\Label.
"

Any idea what to do with it? Thanks

Google Ads API Forum Advisor Prod

unread,
Oct 1, 2020, 11:23:57 PM10/1/20
to pit...@gmail.com, adwor...@googlegroups.com
Hi Peter,

Thanks for raising your concern.

You need to create also the instances of the resources and operation needed in LabelService.MutateLabels. You will need to create TextLabel instance first and supply values to the background_color and description field. Then, wrap the TextLabel, together with the other required fields mentioned on the label resource, in a LabelOperation (create), and lastly send it to LabelService.MutateLabels.

Let me know if you have further questions.

Regards,
Google Logo
Ernie John Blanca Tacata
Google Ads API Team
 


ref:_00D1U1174p._5004Q25YTnD:ref

Peter Vanek

unread,
Oct 2, 2020, 6:58:34 AM10/2/20
to AdWords API and Google Ads API Forum
Thank you VERY much. So the documentation is not very well, written, it suggests that you should wrap the TextLabel in a LabelOperation DIRECTLY, but the actual way is to wrap the TextLabel in a Label and the Label should be wrapped in the LabelOperation.
Thanks again.
Reply all
Reply to author
Forward
0 new messages