### [Getting Started With the SendLayer API](https://sendlayer.com/docs/getting-started-with-the-sendlayer-api/)

**Published:** March 24, 2022
**Author:** David Ozokoye

**Content:**

### 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](https://sendlayer.com/blog/what-is-transactional-email/ "What Is Transactional Email?").

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

Table of Contents- [Base URL](#base-url)
- [Authentication](#authentication)
- [Sending a Single Email](#sending-a-single-email)
    - [Endpoint](#endpoint)
    - [JSON Message Format](#json-message-format)
    - [Sending a Request With cURL](#sending-a-request-with-curl)
    - [Success Message](#success-message)
    - [Error Codes](#error-codes)
    - [Recipient Limits for Single Emails](#limit)

Before getting started, be sure to:

- [Authorize your domain](https://sendlayer.com/docs/authorizing-your-domain/ "Authorizing Your Domain")
- [Access your SendLayer API key](https://sendlayer.com/docs/managing-api-keys/ "Managing API Keys")

**Note:** Check out [SendLayer’s API reference](https://sendlayer.com/api-docs/) for details on the HTTP requests available through the SendLayer REST API.

## 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)
```

**Note:** Not sure where to find your SendLayer API key? Check out our tutorial on [managing API keys](https://sendlayer.com/docs/managing-api-keys/ "Managing API Keys") for all the details.

## 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:** Both the API and SMTP server allow for a large email size. This includes both content and attachments, with a limit 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](https://www.postman.com "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](https://sendlayer.com/docs/authorizing-your-domain/). For example, if you’ve registered **`example.com`**, you’ll need to use **`your-email@example.com`**.

**Example JSON payload:**

```

{
  "From": {
    "name": "Paulie Paloma",
    "email": "paulie@example.com"
  },
  "To": [
    {
      "name": "Pattie Paloma",
      "email": "pattie@example.com"
    }
  ],
  "Subject": "This is the email subject",
  "ContentType": "HTML",
  "HTMLContent": "This is a test email sent with the SendLayer API!",
  "PlainContent": "This is the plain text email.",
  "Tags": [
    "tag-name",
    "daily"
  ],
  "Headers": {
    "X-Mailer": "Test mailer",
    "X-Test": "test header"
  }
}
```

**Note:** The `/email` endpoint also supports attachment, CC, BCC, and reply-to parameters. Check out [SendLayer’s API reference](https://sendlayer.com/api-docs/) for information on adding these parameters.

### Sending a Request With cURL

If you have [cURL](https://curl.se/ "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": "paulie@sl.example.com"
  },
  "To": [
    {
      "name": "Pattie Paloma",
      "email": "pattie@example.com"
    }
  ],
  "Subject": "This is the email subject",
  "ContentType": "HTML",
  "HTMLContent": "This is a test email sent with the SendLayer API!",
  "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:

CodeMessage1Missing SenderAPIKey2Missing FromName3Missing FromEmail4Missing ReplyToName5Missing ReplyToEmail6Missing ToName7Missing ToEmail8Missing Subject9Missing ContentType10Missing HTMLContent11Missing PlainContent12Invalid user13Invalid sender API key14Recipient email is suppressed15Invalid TemplateID16Invalid TargetListID17Email quota reached18Recipient name or email address is missing19Recipient email address is invalid20There is no recipient set for the email **OR** The number of recipients exceeds the allowed recipient email address count21CC name or email address is missing22CC email address is invalid23Invalid from email address format24BCC email addresses must be set as an array25BCC name or email address is missing26BCC email address is invalid27The number of BCC email addresses exceed the allowed email address count28Reply-To email addresses must be set as an array29Reply-To name or email address is missing30Reply-To email address is invalid31The number of Reply-To email addresses exceed the allowed email address count32Domain is not activated429Too 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**.

Ready to learn more about integrating SendLayer to your custom web application? Check out our [API documentation](https://developers.sendlayer.com/api-reference/introduction) for detailed guides on using the SendLayer API with popular programming languages.

**Categories:** SendLayer API

---

