Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analytics Report with Multiple Date Ranges #1085

Closed
camarrone opened this issue Mar 24, 2018 · 2 comments
Closed

Analytics Report with Multiple Date Ranges #1085

camarrone opened this issue Mar 24, 2018 · 2 comments
Assignees

Comments

@camarrone
Copy link

camarrone commented Mar 24, 2018

Hello,

I'm trying to get a report using multiple date ranges with the following code:


analyticsreporting = google.analyticsreporting({
   version: 'v4',
   auth: oauth2Client
});

analyticsreporting.reports.batchGet({
    "reportRequests": [
        {
            "viewId": req.params.profileId,
            "dateRanges": [
                {
                    "startDate": "2018-03-17",
                    "endDate": "2018-03-24"
                },
                {
                    "startDate": "14daysAgo",
                    "endDate": "7daysAgo"
                }
            ],
            "metrics": [
                {
                    "expression": "ga:users"
                }
            ]
        }
    ]
}, function (err, results) {
    if (err){
        console.log('ERROR: ');
        console.log(err.errors);
        res.status(500).send(err.errors);
    }

    console.log(JSON.stringify(results));
    res.send({results: results});
});        

But I'm getting the following error message:

[ { message: 'Invalid JSON payload received. Unknown name "reportRequests[dateRanges][endDate]": Cannot bind query parameter. Field \'reportRequests[dateRanges][endDate]\' could not be found in request message.\nInvalid JSON payload received. Unknown name "reportRequests[dateRanges][startDate]": Cannot bind query parameter. Field \'reportRequests[dateRanges][startDate]\' could not be found in request message.\nInvalid JSON payload received. Unknown name "reportRequests[viewId]": Cannot bind query parameter. Field \'reportRequests[viewId]\' could not be found in request message.\nInvalid JSON payload received. Unknown name "reportRequests[metrics][expression]": Cannot bind query parameter. Field \'reportRequests[metrics][expression]\' could not be found in request message.',
    domain: 'global',
    reason: 'badRequest' } ]

What am I missing here?

The same payload works when I try the API on https://developers.google.com/analytics/devguides/reporting/core/v4/rest/v4/reports/batchGet

Thanks very much!

@camarrone camarrone changed the title Analytics Report with Date Multiple Ranges Analytics Report with Multiple Date Ranges Mar 24, 2018
@JustinBeckwith
Copy link
Contributor

Greetings! The reportsRequest object here needs to be inside of a resource object, as it's part of the post body. I wrote up a complete working sample in #1086. Hope this helps!

@camarrone
Copy link
Author

@JustinBeckwith Thanks very much for the help! It worked like a charm :-)

@JustinBeckwith JustinBeckwith self-assigned this Feb 1, 2021
gcf-owl-bot bot added a commit that referenced this issue Jan 13, 2022
Source-Link: googleapis/synthtool@4dfd20a
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-nodejs:latest@sha256:2d850512335d7adca3a4b08e02f8e63192978aea88c042dacb3e382aa996ae7c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants