Retrieve global email statistics from SendGrid's Stats API.
Purpose
This skill is for reading aggregate SendGrid email activity metrics by calling GET /v3/stats.
Inputs:
start_dateinYYYY-MM-DDformat- optional
end_dateinYYYY-MM-DDformat - optional aggregation level:
day,week, ormonth - optional
limitandoffset - SendGrid API key from
--api-key,SENDGRID_API_KEY, or the locally saved SendGrid key
Output:
- raw SendGrid JSON statistics by default
- optional saved JSON file when
--outputis provided - dry-run request metadata when
--dry-runis used
This is a read-only statistics lookup. It does not send email and does not query per-message Email Logs.
What This Skill Needs
start_date- a SendGrid API key, usually
SENDGRID_API_KEY curlbashpython3
API key resolution order:
--api-keyfor the current runSENDGRID_API_KEY- locally saved key at
~/.config/sendgrid-send-email/api_key
The saved key path intentionally matches sendgrid-send-email so users who configured the SendGrid send skill can reuse the same key. If no API key is available and the script is running interactively, prompt once and save it locally for future runs. If no API key is available in a non-interactive run, guide the user to read the SendGrid integration guide: https://frevana.gitbook.io/frevana-docs/email-integrations/sendgrid-integration.
Users can update the saved API key with:
bash <skill-path>/scripts/retrieve_global_email_stats.sh --api-key "SG..." --save-api-key
or clear it with:
bash <skill-path>/scripts/retrieve_global_email_stats.sh --clear-api-key
Execution Order
- Extract
start_date, optionalend_date, optionalaggregated_by, optional pagination, optionalon_behalf_of, and optional region. - Prefer
scripts/retrieve_global_email_stats.shover ad hoccurl. - Use
--dry-runwhen the user wants to inspect the URL before calling SendGrid. - Let the script use
--api-key,SENDGRID_API_KEY, or the locally saved key. - In non-interactive agent runs, fail fast if the API key is missing from all supported sources.
- Return either the raw JSON payload or summarize metrics such as
requests,processed,delivered,bounces,opens,unique_opens,clicks,unique_clicks,spam_reports, andunsubscribes, depending on what the user asked for.
Commands
Retrieve daily stats
bash <skill-path>/scripts/retrieve_global_email_stats.sh \
--start-date "2026-06-01" \
--end-date "2026-06-30" \
--aggregated-by day
Retrieve monthly stats
bash <skill-path>/scripts/retrieve_global_email_stats.sh \
--start-date "2026-01-01" \
--end-date "2026-06-30" \
--aggregated-by month
Parent account querying a subuser
bash <skill-path>/scripts/retrieve_global_email_stats.sh \
--start-date "2026-06-01" \
--end-date "2026-06-30" \
--on-behalf-of "subuser-username"
For customer accounts, pass the full header value, such as:
--on-behalf-of "account-id 123456"
Dry-run request metadata
bash <skill-path>/scripts/retrieve_global_email_stats.sh \
--start-date "2026-06-01" \
--aggregated-by week \
--dry-run
Fixed Request Shape
The script sends a GET request to:
- global region:
https://api.sendgrid.com/v3/stats - EU region:
https://api.eu.sendgrid.com/v3/stats
Supported query parameters:
start_date; required,YYYY-MM-DDend_date; optional,YYYY-MM-DD, defaults to today in SendGrid when omittedaggregated_by; optional, one ofday,week,monthlimit; optional integeroffset; optional integer
Supported headers:
Authorization: Bearer <SENDGRID_API_KEY>- optional
on-behalf-of: <subuser-username>oron-behalf-of: account-id <account-id>
Do not invent or pass unsupported query parameters.
Script Options
--start-date YYYY-MM-DD; required for stats retrieval--end-date YYYY-MM-DD; optional--aggregated-by day|week|month; optional--limit N; optional positive integer--offset N; optional non-negative integer--on-behalf-of VALUE; optional SendGrid parent-account header value--region global|eu; defaultglobal--api-key KEYfor a one-time override--save-api-keyto save the--api-keyvalue for future runs--configure-api-keyto prompt for and save the key--clear-api-keyto remove the locally saved key--output PATHto save JSON--dry-runto print request metadata without calling SendGrid
Notes
- Never echo or store the API key in user-visible output.
- The script can save the API key locally at
~/.config/sendgrid-send-email/api_keywith file permission600; do not print the key value back to the user. - Use
--api-key <key> --save-api-keyor--configure-api-keywhen the user wants to update the saved key. Use--clear-api-keywhen the user wants to remove it. start_dateandend_datemust useYYYY-MM-DD.aggregated_bymust beday,week, ormonth.- Category statistics have a documented thirteen-month availability window, but this global stats endpoint is for account-level global statistics, not category stats.
- Parent accounts can use
--on-behalf-ofto query a subuser or customer account with the parent account API key. - If
--api-key,SENDGRID_API_KEY, and the locally saved key are all missing, tell the user to read https://frevana.gitbook.io/frevana-docs/email-integrations/sendgrid-integration to get the required configuration. - If a user shares an API key in chat, advise them to rotate it.
Example Prompts
Chinese
- "Look up SendGrid's global email stats for each day this month"
- "Use the SendGrid Stats API to query delivered and bounces for 2026-06"
- "Help me dry-run the GET /v3/stats request"
English
- "Retrieve SendGrid global email stats for June 2026"
- "Get daily SendGrid stats from 2026-06-01 to 2026-06-30"
- "Check monthly SendGrid global email statistics for this year"