-
Troubleshooting 404 Error when Implementing GA4 in ColdFusion without Client Library
Hey there, I’m working with ColdFusion and trying to switch our code to use data from GA4 instead of UA. Problem is, I can’t figure out how to give you a simplified example without sharing sensitive info.
Here’s what my JSON looks like:
{"DATERANGES":[{"endDate":"2023-02-20","startDate":"2023-01-01"}],"METRICS":[{"name":"activeUsers"}],"DIMENSIONS":[{"name":"country"}]}
I’m trying to POST this:
<cfhttp url="https://analyticsdata.googleapis.com/v1beta/properties/XXXXX:runReport" method="post" timeout="15"> <cfhttpparam type="header" name="Authorization" value="Bearer #access_token#"> <cfhttpparam type="header" name="Content-type" value="application/json"> <cfhttpparam type="formfield" name="reportRequests" value="#jsonText#"> </cfhttp>`
To get my access_token, I’m posting to https://accounts.google.com/o/oauth2/token like this:
<cfhttp method="post" url="https://accounts.google.com/o/oauth2/token" Result="call2data"> <cfhttpparam type="formfield" name="refresh_token" value="#get_token.refresh_token#"> <cfhttpparam type="formfield" name="client_id" value="#oauth_client_id#"> <cfhttpparam type="formfield" name="client_secret" value="#oauth_client_secret#"> <cfhttpparam type="formfield" name="grant_type" value="refresh_token"> </cfhttp>
The code to get a new access_token seems to be working fine. But when I send the POST request, I get a 404 error with this message: “The requested URL /v1beta/properties/XXXXXXX%3ArunReport was not found on this server. That’s all we know.”
Even I try “123456” as the access_token in the header, but the same error pops up. So, it looks like the POST is failing on the URL, not on Authorization.
Weird thing is, the code works perfectly when posting to the API Explorer at https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport. I enter properties/XXXXXX as the property and include the following request body:
{ "metrics": [ { "name": "activeUsers" } ], "dimensions": [ { "name": "country" } ], "dateRanges": [ { "startDate": "2023-01-01", "endDate": "2023-02-20" } ] }
Results are returned correctly. But when I try to POST to this URL, the same error comes up.
I’m sure I’m overlooking something super obvious. Any ideas or advice? Anyone got an example of accessing GA4 without a client library? That would be so cool!
Log in to reply.