Skip to content

Instantly share code, notes, and snippets.

@zoernert
Created September 16, 2021 22:12
Show Gist options
  • Select an option

  • Save zoernert/be2f014dc412f80c4002f4a7ceb98761 to your computer and use it in GitHub Desktop.

Select an option

Save zoernert/be2f014dc412f80c4002f4a7ceb98761 to your computer and use it in GitHub Desktop.
Retrieve Sendgrid Statistics
const sendgridAPIKey = 'YOUR_SENDGRID_API_KEY';
const fromDate = new Date(new Date().getTime() - (7*87600000)).toISOString().split('T')[0]; // last 7 days
const axios = require("axios");
// Retrieve Statistics from Sendgrid
const sendgridStatsResponds = await axios.get("https://sendgrid.com/v3/stats?start_date="+fromDate,{
headers: {
'content-type': 'application/json',
'Authorization': 'Bearer '+sendgridAPIKey
}
});
const mailStats = sendgridStatsResponds.data;
console.log(mailStats);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment