Skip to content

Latest commit

 

History

History
37 lines (33 loc) · 894 Bytes

view-email-stats.md

File metadata and controls

37 lines (33 loc) · 894 Bytes

How to View Email Statistics

You can find documentation for how to view your email statistics via the UI here. To view Email Statistics via the API:

package main

import (
	"fmt"
	"log"
	"os"

	"github.com/sendgrid/sendgrid-go"
)

func main() {
	apiKey := os.Getenv("SENDGRID_API_KEY")
	host := "https://api.sendgrid.com"
	request := sendgrid.GetRequest(apiKey, "/v3/stats", host)
	request.Method = "GET"
	queryParams := make(map[string]string)
	queryParams["aggregated_by"] = "day"
	queryParams["limit"] = "1"
	queryParams["start_date"] = "2017-01-01"
	queryParams["end_date"] = "2017-10-12"
	queryParams["offset"] = "1"
	request.QueryParams = queryParams
	response, err := sendgrid.API(request)
	if err != nil {
		log.Println(err)
	} else {
		fmt.Println(response.StatusCode)
		fmt.Println(response.Body)
		fmt.Println(response.Headers)
	}
}