API V3 Overview
SendGrid’s new API architecture features significant changes in behavior as compared to previous endpoints, so please read carefully!
Authentication
To authenticate, add an Authorization header to your API
request that contains a base64-encoded username:password
string. Read more about basic access
authentication.
Example header:
1 2 | |
If you want to use the API via curl, it has support for base64-encoded
authentication built-in. For example:
1
| |
You then enter your password at the prompt.
V3 API also supports the use of API Keys. API Keys allow you to use another method of authentication seperate from your username and password to your account. Keys add an additional layer of secuirty for your account. API Keys can be generated in your account - visit https://app.sendgrid.com/settings/api_keys. To use keys, you must set a plain text header named “Authorizaton” with the contents of the header being “Bearer XXX” where XXX is your API Secret Key.
Example header:
1 2 | |
1
| |
Host
The host for API requests is https://api.sendgrid.com/v3/
All requests must be made over HTTPS. HTTP is not supported.
Rate Limits
All calls within the Web API are allotted a specific number of requests per refresh period.
Each Web API request returns the following header information regarding rate limits and number of requests left.
Depending on the endpoint you are trying to reach, it will have a
specific number of allowed requests per refresh period. Once this
threshold has been reached, we will return a status code 429 response.
Example Request
1
| |
Example Response
1 2 3 4 5 6 7 8 9 | |
When Limit is Reached
You will no longer be able to make requests against that endpoint for the duration of that refresh period.
Example Request
1
| |
Example Response
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
Requests
Authorization Header
You must provide an authorization header as described in Authentication.
Accept Header
The API provides JSON responses. The accept header is not currently
required, though it may be required in the future. If not set, the
API will use application/json.
1 2 | |
Arrays of Data
When you send an array of data in a GET request, you will include the parameter multiple times on the URL. We do not require that you add brackets to the parameter name.
Example Array in a GET request
1
| |
HTTP Verbs
Depending on the resource, we support the following HTTP verbs:
| Verb | Description |
|---|---|
| GET | Retrieve a resource or group of resouces |
| POST | Create a new resource |
| PUT | Update an existing resource |
| DELETE | Delete an existing resource |
| OPTIONS | View allowed verbs against a specific resources |
Request Body
When submitting data to a resource via POST or PUT, you must
submit your payload in JSON.
1 2 3 4 5 6 | |
Pagination
Some GET resources allow for retrieval of information in batches. We
will provide the query args in the resource documentation when available
to consume.
When requesting multiple items, we will default the request limit to 500 items. You can specify a different limit but cannot not exceed the default limit.
Resources documented will display a bolded list of available paginated parameters if available.
Below is a basic pagination example. In the resource documentation, we will only provide the bolded list of available parameters.
When information is batched, a Link Header will be provided in the response.
1
| |
| Parameter | Description |
|---|---|
| limit | The number of records to return |
| offset | The number of records to skip |
Search & Parameters
Some resources allow for you to search by a specific field. Other resources require you to append a parameter to the URI.
In this example, we will display a paginated uri example, searching for
resources where the email contains foo.
1
| |
Responses
Content-Type Header
All responses are returned in JSON format. We specify this by sending
the Content-Type header.
1
| |
1 2 3 4 5 6 | |
Status Codes
Below is a table description of the various status codes we currently support against resources.
| Status Code | Description |
|---|---|
| 200 | No error |
| 201 | Successfully created |
| 204 | Successfully deleted |
| 400 | Bad request |
| 401 | Requires authentication |
| 429 | Too Many Requests |
| 500 | Internal server error |
Successful Requests
Below is a general overview of what resource objects are returned on successful Web API requests.
| Verb | Resource object returned |
|---|---|
| GET | A single resource object or array of resource objects |
| PATCH | The updated resource object is returned |
| DELETE | No content is returned |
| POST | The newly created resource object is returned |
Failed Requests
The general format guidelines are displayed when the accompanying status code is returned.
1
| |
1 2 3 4 5 6 7 8 9 10 | |
Pagination
When a request is made with a pagination query, the following data is included in the header to allow for easy traversal of previous, current, first, and last page of the data set.
1
| |
1 2 3 4 5 6 7 | |
Yes
No
Feedback