Skip to main content

Prerequisites

Installation

Install the SDK in your project root.

Storing your API key

Nuxt reads private values through runtimeConfig. Declare the key at the top level of the config object so it stays on the server.
nuxt.config.ts
Add the matching environment variable to .env. Nuxt maps NUXT_SENDLAYER_API_KEY onto runtimeConfig.sendlayerApiKey automatically.
.env
Keys placed under runtimeConfig.public ship to the browser. Only the top-level section stays private to the server.

Sending an email from a server route

Create a server route in server/api/send-email.post.js. The .post suffix restricts the handler to POST requests.
server/api/send-email.post.js
readBody() parses the incoming JSON payload, and useRuntimeConfig(event) reads the private key at request time.
Use a from address on a domain you authorized in SendLayer. Requests from an unauthorized domain fail.

Reusing the client across routes

Create the client once in a server utility. Nitro auto-imports anything under server/utils, so the helper is available in every route without an import statement.
server/utils/sendlayer.js
Call the helper from any server route:
server/api/welcome.post.js

Calling the route from a Vue page

Use $fetch to post the form data. Nuxt sets the JSON content type when the body is an object.
pages/contact.vue
Use $fetch for user-triggered actions such as form submissions. Reserve useFetch for data you load when the page renders.

Testing the route

Start the development development server.
Then post a request from another terminal using cURL.
A successful request returns the message ID:
Open the Email logs page in your SendLayer dashboard to confirm delivery.

Next Steps

Node.js SDK Reference

Review every method and parameter in the Node.js SDK.

Managing Webhooks

Track opens, clicks, and bounces with webhooks.

Retrieving Events

Query delivery events for any message.

Rate Limits

Understand recipient and request limits.