Reputation: 11
I am trying to filter my GA api V4 in python by removing pageviews under 200 in my request... surprisingly, as i follow exactly the syntax of the documentation, i get an error message :
> "Invalid JSON payload received. Unknown name "comparisonValue" at 'report_req
uests[0].metric_filter_clauses[0].filters[0]': Proto field is not repeating, cannot start list.". Details: "[{'
@type': 'type.googleapis.com/google.rpc.BadRequest', 'fieldViolations': [{'field': 'report_requests[0].metric_f
ilter_clauses[0].filters[0]', 'description': 'Invalid JSON payload received. Unknown name "comparisonValue" at
\'report_requests[0].metric_filter_clauses[0].filters[0]\': Proto field is not repeating, cannot start list.'}]
}]"
obviously there is a problem in my coding, but I cannot understand what it is : it is a copy paste of the documentation in https://developers.google.com/analytics/devguides/reporting/core/v4/basics#filtering... is there a difference between the JSON POST from documentation and the one in the batch get from python? here is the part where I build my request the problematic filter is at the end...:
return analytics.reports().batchGet(
body={
'reportRequests': [
{
'viewId': VIEW_ID,
'dateRanges': [{'startDate': '2021-07-20', 'endDate': '2021-07-27'}],
'metrics': [
{
'expression': 'ga:sessions',
'expression': 'ga:pageviews'
}],
'dimensions': [
{
'name': 'ga:pagePath'
}],
'orderBys': [
{
'orderType': 'VALUE',
'sortOrder': "DESCENDING",
'fieldName': 'ga:pageviews'
}],
'dimensionFilterClauses': [
{
'filters': [
{
'dimensionName':'ga:country',
'operator':'BEGINS_WITH',
'expressions':['fra']
}],
}],
'metricFilterClauses': [
{
'filters': [
{
'metricName':'ga:pageviews',
'operator':'GREATER_THAN',
'comparisonValue':['200']
}]
}]
}]
}
).execute()
any idea why it don't work? thanks :)
Upvotes: 1
Views: 151
Reputation: 584
Jacques,
comparisonValue
field value should be a string, not a list, e.g. '200'
instead of ['200']
.
A good way to eliminate possible coding issues is to test your query directly using the Google Analytics API Explorer.
Upvotes: 1