AnalyticsReporting v4: Difference between real usage and documentation
See original GitHub issueHi, I started to use the analyticsreporting module v4 to batch the data. I write this issue to notify you the difference between real usage and documentation. Following the sample in your documentation to do a batchGet doesn’t work.
analyticsreporting.reports.batchGet( {
"reportRequests":[
{
"viewId":"XXXX",
"dateRanges":[
{
"startDate":"2015-06-15",
"endDate":"2015-06-30"
}],
"metrics":[
{
"expression":"ga:sessions"
}],
"dimensions": [
{
"name":"ga:browser"
}]
}]
} ).execute(handleReportingResults)
When I do the call, I have this response message : “Error: Invalid JSON payload received. Unknown name “reportRequests”: Cannot bind query parameter. 'reportRequests' is a message type. Parameters can only be bound to primitive types.”
I was investigating and I discover that the object of the request has an empty json property.
I put some debugger
on v4.js module and I discover that in the batchGet method.
batchGet: function(params, callback) {
var parameters = {
options: {
url: 'https://analyticsreporting.googleapis.com/v4/reports:batchGet',
method: 'POST'
},
params: params,
requiredParams: [],
pathParams: [],
context: self
};
return createAPIRequest(parameters, callback);
}
there is no reference related to “resource” (At line 82 of apirequest.js) property which is assign to options.json property (At line 164 of apirequest.js). I have changed the params object of my module without edit v4.js and apirequest.js and it works. This following snippet shows what I changed.
analytics.reports.batchGet({
"headers": {
"Content-Type": "application/json"
},
"auth": options.auth,
"resource": {
"reportRequests": req // req is an array of objects (like in documentation)
},
}, callback);
Does it make sense ? Is there another way to face this issue ? Any concers let me know.
Thanks! Have fun coding 😃
Issue Analytics
- State:
- Created 7 years ago
- Reactions:22
- Comments:12 (1 by maintainers)
Top GitHub Comments
Simply putting a {resource: YourRequestObj } will do the trick:
Sorry but I thought that the usage was the same of the browser-based. Anyway, I thought that was good write this issue to notify other devs how to use the batchGet with this version. Thanks man 😃