The Template Engine is the first feature available on SendGrid’s new API architecture. As a result, interacting with the endpoints described here is different than the other existing 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
GET https://api.sendgrid.com/v3/resource HTTP/1.1
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ===

If you want to use the API via curl, it has support for base64-encoded authentication built-in. For example:

1
$curl -H "Content-Type: application/json" -u sendgrid_username -X POST -d '{"name":"example_name"}' https://api.sendgrid.com/v3/templates

Host

The host for API requests is

1
https://api.sendgrid.com/v3/

All requests must be made over HTTPS. HTTP is not supported.

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
GET https://api.sendgrid.com/v3/endpoint HTTP/1.1
Accept: application/json

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
POST https://api.sendgrid.com/v3/templates/ HTTP/1.1
Content-Type: application/json

{
  "name": "new template name"
}

Rate Limits

All calls within the Web API are allotted a specific number of requests per refresh period.

Each Web API requests 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
GET https://api.sendgrid.com/v3/resource HTTP/1.1

Example Response

1
2
3
4
5
6
7
8
9
HTTP/1.1 200 OK 
Content-Type: application/json 
X-RateLimit-Limit: 500
X-RateLimit-Remaining: 499 
X-RateLimit-Reset: 1392815263

{
  "foo": "bar"
}

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
GET https://api.sendgrid.com/v3/resource/ HTTP/1.1

Example Response

1
2
3
4
5
6
7
8
9
10
11
12
13
14
HTTP/1.1 429 TOO MANY REQUESTS
Content-Type: application/json
X-RateLimit-Limit: 150
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1392815263

{
  "errors": [
    {
      "field": null,
       "message": "too many requests"
    },
  ]
}

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.

In this example, we will display an example paginated example. In the resource documentation, we will only provide the bolded list of available parameters.

1
GET https://api.sendgrid.com/v3/resource?limit=300&offset=10 HTTP/1.1
Parameter Description
limit The number of records to return
offset The number of records to skip

Search & Parameters

Some resources allow 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
GET https://api.sendgrid.com/v3/resource?email=foo&foo=bar HTTP/1.1

Responses

Content-Type Header

All responses are returned in JSON format. We specify this by sending the Content-Type header.

1
GET https://api.sendgrid.com/v3/resource HTTP/1.1
1
2
3
4
5
6
HTTP/1.1 200 OK
Content-Type: application/json

{
    "foo": "bar",
}

Status Codes

Below is a table description of the various status codes we corrently support against resources.

Status Code Description
200No error
201Successfully created
204Successfully deleted
400Bad request
401Requires authentication
500Internal server error

Successful Requests

Below is a general overview of what resource objects are returned on successful Web API requests.

VerbResource object returned
GETA single resource object or array of resource objects
PATCHThe updated resource object is returned
DELETENo content is returned
POSTThe newly created resource object is returned

Failed Requests

The general format guidelines are displayed with the accompanying status code is returned.

1
GET https://api.sendgrid.com/v3/resource HTTP/1.1
1
2
3
4
5
6
7
8
9
10
HTTP/1.1 400 BAD REQUEST
Content-Type: application/json

{
    "errors": [
      {"field": "identifier1", "message": "error message explained"},
      {"field": "identifier2", "message": "error message explained"},
      {"field": "identifier3", "message": "error message explained"},
    ]
}

Pagination

When a request is made with 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
GET https://api.sendgrid.com/v3/resource?limit=5&offset=0 HTTP/1.1
1
2
3
4
5
6
7
HTTP/1.1 200 OK
Content-Type: application/json

Link: <http://api.sendgrid.com/v3/resource?limit=5&offset=5>; rel="next"; title="2",
      <http://api.sendgrid.com/v3/resource?limit=5&offset=0>; rel="prev"; title="1",
      <http://api.sendgrid.com/v3/resource?limit=5&offset=10>; rel="last"; title="3",
      <http://api.sendgrid.com/v3/resource?limit=5&offset=0>; rel="first"; title="1"