Docs SendLayer API Getting Started With the SendLayer API

Getting Started With the SendLayer API

Are you ready to start sending emails with the SendLayer API?

The SendLayer REST API is easy to integrate with, fully featured, and allows you to programmatically send transactional emails.

In this tutorial, we’ll show you how to start sending emails with the SendLayer API.

Before getting started, be sure to:

Base URL

All API calls need to start with the following base API URL:

https://console.sendlayer.com/api/v1/

Authentication

All API calls require a Bearer Token authorization header with a valid API key:

"Authorization": "Bearer XYZ" (replacing XYZ with your API key)

Sending a Single Email

In the following sections, we’ll cover how to send a single email with the SendLayer API and what to expect when your message is sent.

Note: The API allows for a larger total email size, including both content and attachments, with a limit of 25 MB. In contrast, SMTP only allows a maximum of 10 MB.

Endpoint

To send a single email with the SendLayer API, you’ll need to execute an HTTP POST request using the /email endpoint:

POST https://console.sendlayer.com/api/v1/email

JSON Message Format

SendLayer sends emails through the API based on JSON input. The JSON properties, such as Subject, HTMLContent, and PlainContent, are converted to a valid message when sent to the recipient.

Below you’ll find an example JSON payload that can be used to send an email in an API platform like Postman. Be sure to replace the example email addresses with valid email addresses in the From and To objects.

Note: The “From” email address must contain your sending domain, which is the domain you’ve registered in SendLayer. For example, if you’ve registered example.com you’ll need to use [email protected].

Example JSON payload:

{
  "From": {
    "name": "Paulie Paloma",
    "email": "[email protected]"
  },
  "To": [
    {
      "name": "Pattie Paloma",
      "email": "[email protected]"
    }
  ],
  "Subject": "This is the email subject",
  "ContentType": "HTML",
  "HTMLContent": "<html><body><p>This is a test email sent with the <a href=\"https://sendlayer.com\">SendLayer</a> API!</p></body></html>",
  "PlainContent": "This is the plain text email.",
  "Tags": [
    "tag-name",
    "daily"
  ],
  "Headers": {
    "X-Mailer": "Test mailer",
    "X-Test": "test header"
  }
}

Sending a Request With cURL

If you have cURL installed on your machine, you can send a request using the command line. You’ll need to replace XYZ in the authorization header with a valid API key. Also, be sure to replace the example email addresses with valid email addresses in the From and To objects.

curl --location --request POST 'https://console.sendlayer.com/api/v1/email' \
--header 'Authorization: Bearer XYZ' \
--header 'Content-Type: application/json' \
--data-raw '{
  "From": {
    "name": "Paulie Paloma",
    "email": "[email protected]"
  },
  "To": [
    {
      "name": "Pattie Paloma",
      "email": "[email protected]"
    }
  ],
  "Subject": "This is the email subject",
  "ContentType": "HTML",
  "HTMLContent": "<html><body><p>This is a test email sent with the <a href=\"https://sendlayer.com\">SendLayer</a> API!</p></body></html>",
  "PlainContent": "This is the plain text email.",
  "Tags": [
    "tag-name",
    "daily"
  ],
  "Headers": {
    "X-Mailer": "Test mailer",
    "X-Test": "test header"
  }

Success Message

When you successfully send an API email, you’ll receive a JSON message with the MessageID.

Example success message:

{
    "MessageID": "ab800253-4dc4-47a6-9ad6-1daa643d3d8b"
}

Error Codes

If your API call is unsuccessful, an error code and message will be returned in JSON. Below is a list of the error codes followed by an example error:

CodeMessage
1Missing SenderAPIKey
2Missing FromName
3Missing FromEmail
4Missing ReplyToName
5Missing ReplyToEmail
6Missing ToName
7Missing ToEmail
8Missing Subject
9Missing ContentType
10Missing HTMLContent
11Missing PlainContent
12Invalid user
13Invalid sender API key
14Recipient email is suppressed
15Invalid TemplateID
16Invalid TargetListID
17Email quota reached
18Recipient name or email address is missing
19Recipient email address is invalid
20There is no recipient set for the email OR The number of recipients exceeds the allowed recipient email address count
21CC name or email address is missing
22CC email address is invalid
23Invalid from email address format
24BCC email addresses must be set as an array
25BCC name or email address is missing
26BCC email address is invalid
27The number of BCC email addresses exceed the allowed email address count
28Reply-To email addresses must be set as an array
29Reply-To name or email address is missing
30Reply-To email address is invalid
31The number of Reply-To email addresses exceed the allowed email address count
32Domain is not activated
429Too many requests

Example error response:

{
    "Errors": [
        {
            "Code": 13,
            "Message": "Invalid SenderAPIKey"
        }
    ]
}

Recipient Limits for Single Emails

When sending emails, you can address multiple recipients by adding additional recipient objects in the “To,” “Cc,” and “Bcc” fields. Ensure you do not exceed 10 addresses for “To” and “Cc” and 5 for “Bcc” to avoid exceeding SendLayer’s limits.

That’s it! Now you know how to send an email with the SendLayer API.

Next, would you like to learn how to send SendLayer data to 3rd party apps? Check out our tutorial on managing webhooks for more information.