How to get the id of the root product partition [python]

49 views
Skip to first unread message

Matthias Baader

unread,
Oct 26, 2018, 11:22:54 AM10/26/18
to AdWords API and Google Ads API Forum
Hi, 

if I understand that correctly, you can find the root product group id by searching for the product group that does not have a parent product id. Right?

But how exactly does the AWQL query in Python have to look like?

Is the following code correct?

  report_query = (adwords.ReportQueryBuilder()
                  .Select('CampaignId', 'AdGroupId', 'Id', 'ParentCriterionId')
                  .From('PRODUCT_PARTITION_REPORT')
                  .Where('ParentCriterionId').In(0)#<is this line correct?
                  .Build())

It seems to work, but I'm struggling with the .In(0) - part, because the service reference states "Undefined for the root partition": 


...whereas the report reference does not mention the root at all:

.Where('ParentCriterionId').In(None)

...throws an error.

Or would you recommend using the AdGroupCriterionService for this task?

Best regards
Matthias

Kevin Weitzner

unread,
Oct 26, 2018, 1:13:40 PM10/26/18
to AdWords API and Google Ads API Forum
Hi Matthias,

I went to check this out, as I think I need to do this for my issue.

I was able to get the parent criterion id using the AdGroupCriterionService get selector

Looks like something like this would work - but I've not put it in practice other than a quick test.

def main(client, adgroup_id):
"""Runs the example."""
adgroup_criterion_service = client.GetService(
'AdGroupCriterionService', version='v201806')

selector = {
'fields':['ParentCriterionId'],
'predicates':[
{
'field':'AdGroupId',
'operator': 'EQUALS',
'values': adgroup_id
}
]
}
page = adgroup_criterion_service.get(selector)

print page['entries'][0]['criterion']['id']

It appears that the root partition is the first entry in the list so you can grab it using [0].  You should be able to confirm it - as the page['entries'][0]['criterion']['idparentcriterionId] should be None.

Luis Xander Talag (AdWords API Team)

unread,
Oct 26, 2018, 6:14:35 PM10/26/18
to AdWords API and Google Ads API Forum
Hi Matthias,

Yes, I would recommend to use AdGroupCriterionService.get() to get the ParentCriterionId just like Kevin have suggested. It is currently not possible to filter the ParentCriterionId using the value of 0 or None via Product Partition Report.

Let me know if you have further concerns.

Thanks,
Luis
AdWords API Team
Reply all
Reply to author
Forward
0 new messages