Hi!
This is my first meeting with the Google Ads API and I'm attempting to
achieve labeling of ads in my Python application.
Case:
1. The app fetches all ads marked with a specific label (e.g. "LabelName":
"X") for a given *AccountA*->Campaign->Adgroup structure
2. A user agent clicks a button
3. On click, the app has to:
3a) Look for a label "Y"
3b) If one exists, get the ID of that label, if not, create a label "Y" and
get its ID
3c) Remove the label "X" from said ads
3d) Apply the label "Y" to said ads
So here's my problem:
I'm finding label "Y" (using LabelService), but in trying to add it to an
ad (using the AdGroupAdService),
I get this error:
[EntityNotFound.INVALID_ID @ operations[0].operand.labelId; trigger:'LabelId:
yyyyyyyyyy'] #Redacted id
I have but one theory as to why this happens:
The label "Y" doesn't exist for the *AccountA* in the structure, so it is
not available to link to these ads when looking at the adgroup in the
Google Ads GUI, but my
find_or_create(c, "Y") method still finds (doesn't create) a label "Y" and
returns its ID. I believe this label "Y" to be owned by *AccountB, *which
I'm also able to manage through my Google Ads user.
This is a slightly flawed theory, because find_or_create(c, "X") does finds
one label "X" every time, even though I have several labels "X" across
different accounts, and I'm able to remove the "X" label from the ads.
I know that the find_or_create() and add_label_to_ad() methods are able to
create a new label and link it to the ads of interest.
If I try to find_or_create() a label "Stupid Labels" and use it to label
the ads, it works. I believe this is because there exists no such label in
any other accounts,
so the methods are able to create and link it with no trouble of finding
the Entity.
*TLDR*:
How do I make sure that the label I'm finding belongs to the account
*(AccountA)* that owns the ads I want to change?
Which service/selector/predicate combination would I need to use?
Is there any way to find the Label IDs in the Google Ads GUI to verify my
finds?
Here's my code:
def find_or_create_label(client, label_name):
service = client.GetService("LabelService", version=API_VERSION)
selector = {
"fields": ["LabelId", "LabelName"],
"predicates": [
{"field": "LabelName", "operator": "EQUALS", "values": [
label_name]}
]
}
label = service.get(selector)
for entry in label.entries:
if entry["name"] == label_name:
return entry["id"]
operation = {
"operator": "ADD",
"operand": {"name": label_name, "xsi_type": "TextLabel"}
result = service.mutate(operation)
return result["value"][0].id
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to the Google Groups
"AdWords API and Google Ads API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/adwords-api/1b8d1c0c-0250-43d0-a846-5f4648e25819%40googlegroups.com.