SendGrid Rate Limiting
There are limitations to delivery rates imposed by recipient mail servers. Exceeding these limitations results in a practice referred to as throttling. Throttling in terms of email means that a recipient mail server has accepted all the mail it is willing to accept from your IP for a certain period of time. Apart from throttling that can occur depending on the recipients’ server, SendGrid is also limiting the number of emails that you can send on a per month period, based on the plan that you have purchased, for more information about this you should consult the pricing page of SendGrid.
Endpoints and Available Resources
Some of the most important endpoints that SendGrid exposes are the following, you can also find the complete list of endpoints the Web API v3 exposes here:
- Operations related to your users.
- Marketing Campaigns. Campaign-related operations about loading in contacts, create segments, create and send campaigns, view your stats, and much more.
- Operations related to white label lists of domains and subdomains, IPs and URLS.
- SendGrid email statistics.
- Spam reports. Operations, related to spam reports that SendGrid generates for your emails and campaigns.
And much more can be found on the link given above.
Not all of the provided endpoints are useful for pulling out data that can be used for analytics. the most important for this job is the Stats and reports endpoints that SendGrid exposes. As an example, let’s assume that we want to fetch data from the Global Stats endpoint. To do that we need to perform a GET request to the following URL, providing a valid API key:
GET https://api.sendgrid.com/v3/stats?start_date=2015-01-01&end_date=2015-01-02 HTTP/1.1
If you pay attention to the above URL you will notice that we are also providing two parameters, the start and end dates for which we would like to fetch statistics for. The response will be in JSON format and will look like the following:
Statistics consist of the following metrics:
And there are a number of sub-endpoints that you can access for more specific metrics and statistics, these are the following:
- Advanced Stats
- Category Stats
- Global Stats
- Parse Stats
- Subuser Stats
Another way of retrieving metrics and statistics from the SendGrid API is by requesting it to push data to our system every time a new event occurs. To do that we need to use the Webhooks API which sends events to a predefined URL using POST requests. Events that are sent by the SendGrid API have a structure like the following:
These events can be stored in your BI solution like Google BigQuery for analysis or they can be used to trigger specific actions as they arrive.