Learn business growth with Google Analytics 4 Forums Google Analytics 4 Invalid JSON payload error when using Google Analytics 4

  • Invalid JSON payload error when using Google Analytics 4

    Posted by Mia on 25 June 2023 at 2:10 pm

    “Hey guys, need a bit of help here. So I’m playing around with Google Analytics API 4 and trying to get some data out. I’ve been doing this via Postman and here’s what I’ve done so far:

    URL I’ve hit up: https://analyticsreporting.googleapis.com/v4/reports:batchGet and I’ve used the POST method. The body of the request looks like this:

    `
    {
    “reportRequests”: [
    {
    “viewId”: “376027054”,
    “dateRanges”: [
    {
    “startDate”: “2023-01-03”,
    “endDate”: “2023-01-0”
    }
    ],
    “pageSize”: 1,
    “metrics”: [
    {
    “expression”: “ga:hits”
    }
    ],
    “dimensions”: [
    {
    “name”: “ga:date”
    }
    ],
    “segments”: [],
    “filtersExpression”: “”
    }
    ]
    }
    `

    The response I got wasn’t what I was hoping for though. Received the “Invalid JSON payload received. Unexpected end of string. Expected an object key or} error. Here it is in all its glory:

    `
    {
    “error”: {
    “code”: 400,
    “message”: “Invalid JSON payload received. Unexpected end of string. Expected an object key or }.nn^”,
    “status”: “INVALID_ARGUMENT”
    }
    }
    `

    A little stuck on this one. Anyone have any idea what’s going wrong?”

    Noah replied 1 year ago 3 Members · 2 Replies
  • 2 Replies
  • Nam

    Member
    6 July 2023 at 11:25 am

    So the thing is, the analytics reporting API is only going to let you pull out data from Universal Analytics accounts. What you should be doing is using the data API to get info from your GA4 accounts.

  • Noah

    Member
    9 July 2023 at 6:20 pm

    The issue likely originates from the format of the date in the “endDate” field of your request. Where it currently reads “2023-01-0”, it should probably be a valid date like “2023-01-30” or another date in the ‘YYYY-MM-DD’ format. JSON payload errors typically mean there’s something wrong with the format or structure of your JSON data, and in this case, it’s the formatting of your date that’s the likely culprit. So, correct the date and it should solve your problem.

Log in to reply.