How to use searchParameters filter by Location?

246 views
Skip to first unread message

Bruno Provenzano

unread,
Jun 7, 2018, 6:01:34 PM6/7/18
to AdWords API and Google Ads API Forum
Hi group! 

I'm having problems arming the selector to TargetingIdeaService. I need to make this selector using searchParameters and filter it by location, but I can't. 
In another hand, I need to filter this location by COUNTRY, and I don't find the way to do this, so the location_criterion_service returns all locations types (cities, neighborhoods, countries)

This is part of my code:

selector = {
'fields': ['Id', 'LocationName', 'DisplayType', 'CanonicalName', 'ParentLocations', 'Reach', 'TargetingStatus'],
'predicates': [{'field': 'LocationName', 'operator': 'IN', 'values': 'South Africa'},
{'field': 'Locale', 'operator': 'EQUALS', 'values': 'en'}]}
location_criteria = location_criterion_service.get(selector)

targeting_idea_service = client.GetService('TargetingIdeaService', version='v201802')
offset = 0
selector = {'ideaType': 'KEYWORD', 'requestType': 'IDEAS',
'requestedAttributeTypes': ['KEYWORD_TEXT', 'SEARCH_VOLUME'],
'paging': {'startIndex': str(offset), 'numberResults': str(PAGE_SIZE)},
'searchParameters': [{'xsi_type': 'RelatedToQuerySearchParameter', 'queries': ['bla bla']},
{'xsi_type': 'LocationSearchParameter', 'locations': [
{'Criterion.type': 'LOCATION',
'locationName': location_criteria['Location']['parentLocations']['locationName']}]}]}

Vincent Racaza (AdWords API Team)

unread,
Jun 8, 2018, 2:30:02 AM6/8/18
to AdWords API and Google Ads API Forum
Hi Bruno,

In setting the LocationSearchParameter, the required field of the Location object is the id, therefore, you need to set this, and not the location name. To get the location criterion ID that you can use, you can refer to the geo targets guide on which you can open the geo targets table. For example, for South Africa, the criterion ID is 2710. With this, you can add the line of codes below in this Python example:

  # Location setting (optional).
  selector
['searchParameters'].append({
     
'xsi_type': 'LocationSearchParameter',
     
'locations': [{'id': '2710'}]
 
})

Let me know how it goes after trying this on your end.

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