0
votes

My code is stated as below:

DIMENSIONS = ['ga:pagePath']

def get_report(analytics,job_slug):
    job_page_url = create_page_path_url(job_slug)

    return analytics.reports().batchGet(
      body={
        'reportRequests': [
        {
          'viewId': VIEW_ID,
          'dateRanges': [{'startDate': '7daysAgo', 'endDate': 'today'}],
          'metrics': [{'expression':i} for i in METRICS],
          'dimensions': [{'name':j} for j in DIMENSIONS],
          'dimensionFilterClauses':[{"filters": [{'dimensionName': DIMENSIONS, 'operator': "IN_LIST", "expressions":[k for k in job_page_url]}]}]
        }]
      }
    ).execute()

The error is stated as below:

<ipython-input-6-0c0cf9ca35af> in get_report(analytics, job_slug) 10 'metrics': [{'expression':i} for i in METRICS], 11 'dimensions': [{'name':j} for j in DIMENSIONS], ---> 12 'dimensionFilterClauses':[{"filters": [{'dimensionName': DIMENSIONS, 'operator': "IN_LIST", "expressions":[k for k in job_page_url]}]}] 13 }] 14 }

HttpError: https://analyticsreporting.googleapis.com/v4/reports:batchGet?alt=json returned "Invalid JSON payload received. Unknown name "dimensionName" at 'report_requests[0].dimension_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].dimension_filter_clauses[0].filters[0]', 'description': 'Invalid JSON payload received. Unknown name "dimensionName" at \'report_requests[0].dimension_filter_clauses[0].filters[0]\': Proto field is not repeating, cannot start list.'}]}]">

I'm able to successfully pull data from GA if the 'dimensionName': DIMENSIONS is replaced with 'dimensionName': 'ga:pagePath'.

I'm wondering what's happening here as both are the same meaning right?

1

1 Answers

0
votes

Just found out the problem! 'dimensionName' doesn't accept list, so have to pass in as a single string