I'm trying to fetch traffic stats by date for a domain through gmailpostmastertools over OAuth2, I'm able to retrieve postmaster.domains.list and traffic stats for a domain without any date parameters, when any of the endDate or startDate parameters included in the request, it throws the following,
Error: Request contains an invalid argument.
at Gaxios._request (C:\projects\postmaster-api\node_modules\gaxios\src\gaxios.ts:158:15)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at OAuth2Client.requestAsync (C:\projects\postmaster-api\node_modules\google-auth-library\build\src\auth\oauth2client.js:345:18)
Here's the condensed bit that tries to fetch the data,
import { google } from 'googleapis';
oauth2Client = new google.auth.OAuth2(
'client_placeholder',
'secret_placeholder',
'/oauth2callback'
);
postmaster = google.gmailpostmastertools({
version: 'v1',
auth: oauth2Client
});
await this.postmaster.domains.trafficStats.list({
'startDate.day' : 1,
'startDate.month' : 7,
'startDate.year' : 2021,
parent : `domains/${domain_name}`
});
It works fine to fetch the data directly with access_token.
let access_token = 'my_access_token';
let domain_name = 'mydomain.com';
let date = '20210701';
await fetch(`https://gmailpostmastertools.googleapis.com/v1/domains/${domain_name}/trafficStats/${date}?access_token=${access_token}`, {
method: 'GET'
});
Any thoughts?
You need to specify both startDate and endDate in the request.
From https://developers.google.com/gmail/postmaster/reference/rest/v1/domains.trafficStats/list