SendLayer Node.js SDK installation and usage
.js
file or edit an existing one. Then import the SendLayer
module. Once done, you’ll need to initialize the module with your SendLayer API key.
html
parameter to the send()
method.
text
parameter to have a plain text and HTML version of your email message"Cc"
and "BCC"
email addresses.
name
and email
as objects.
attachments
parameter to the email payload.
path
parameter with the path to the attachment file you wish to attach and specify the correct type
.
SendLayer SDK supports both local and remote file attachments and allows you to add multiple attachment files. See our tutorial to learn more about attaching files to emails.
Parameter | Type | Required | Description |
---|---|---|---|
to | string or array | Yes | Email address(es) of the recipient(s). Can be a single email string or an array of objects with ‘email’ and ‘name’ keys |
from | string or object | Yes | Email address of the sender. Can be a single email string or an object with ‘email’ and ‘name’ keys |
subject | string | Yes | Subject line of the email |
text | string | No | Plain text version of the email content |
html | string | No | HTML version of the email content |
cc | string or array | No | CC email address(es). Can be a single email string or an array of objects containing CC recipient email addresses and names |
bcc | string or array | No | BCC email address(es). Can be a single email string or an array of objects containing BCC recipient email addresses and names |
replyTo | string or array | No | ReplyTo email address. Can be a single email string or an object containing reply-to email address and name |
tags | array | No | Array of strings for tagging emails |
headers | object | No | Object containing custom headers |
attachments | array | No | Array of objects containing file paths and MIME types for attachments |
Webhooks.create()
method and specify the required parameters. This method requires the url
and event
parameters.
event
parameter is constrained to the following options:
Webhooks.get()
method.
Webhooks.delete()
method. This method accepts one required parameter webhookId
that needs to be a number.
Webhooks
module.
Parameter | Type | Required | Description |
---|---|---|---|
url | string | Yes | The webhook endpoint URL where events will be sent |
event | string | Yes | The type of event to listen for. Options: bounce, click, open, unsubscribe, complaint, delivery |
webhookId | number | Yes | Unique identifier for the webhook (used in delete operation) |
Events.get()
method to retrieve all events.
Events.get()
method retrieves the top 5 events in your account if no filter parameter is specified.Events.get()
method in the SendLayer
module accepts some optional parameters. These parameters can be used to filter the API response. Here is an example:
Events
module.
Parameter | Type | Required | Description |
---|---|---|---|
startDate | Date | No | Start date for filtering events |
endDate | Date | No | End date for filtering events |
event | string | No | Filter the API request by the type of event. Supported events include: accepted , rejected , delivered , opened , clicked , unsubscribed , complained , failed |
messageId | string | No | Filter by the email MessageId |
startFrom | number | No | Specify a starting number for the email filter |
retrieveCount | number | No | This parameter controls the number of event records that’ll be displayed. It defaults to 5 if none is specified |
SendLayerError
, SendLayerAPIError
) for better error handling. You can use try/catch blocks to handle errors when sending emails: