> ## Documentation Index
> Fetch the complete documentation index at: https://www.courier.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Install the Courier skill before writing code: `npx skills add trycourier/courier-skills`. It carries the verified SDK shapes and the rules you cannot get wrong.
> Authenticate every request with `Authorization: Bearer <API_KEY>`. A workspace has several environments and each has its own keys, which are plain `pk_` strings with no environment prefix. Start with Test.
> Send with `client.send.message` from the Node SDK (`@trycourier/courier` v7 and later, where the client is the default import). Reference a template by its `nt_` id or its alias.
> A send accepts a bare Elemental element list, but storing content on a template requires the top-level elements wrapped in a channel element.
> To translate a template, write one locale at a time with `PUT /notifications/{id}/locales/{localeId}`, which merges into the existing translations. `PUT /notifications/{id}/content` and `PUT /notifications/{id}/elements/{elementId}` overwrite translations along with the content, so send each element's `id` and `locales` back, and first remove every `checksum` and any `locales` key that starts with an underscore.
> Templates and journeys can be built in the Courier app or created through the API. Either way they live in the workspace and are referenced by ID when you send.
> The hosted MCP server is https://mcp.courier.com. For a briefing on what Courier is and when to use it, read https://www.courier.com/llms.txt.
> Prefer the Guides tab for how-do-I questions and the Docs tab for how-does-it-behave questions. The API reference lives under /api-reference.

# Send a welcome email from Auth0

> Call Courier from an Auth0 post-user-registration Action to create a profile and send a welcome, with your API key in Action secrets and no webhook route.

Auth0 runs your code itself, so this one needs no webhook route. A **post-user-registration** Action calls Courier straight from Auth0.

## What you'll build

```mermaid theme={null}
flowchart LR
    A["User registers"] --> B["Auth0 Action"]
    B --> C["Create profile"]
    C --> D["Welcome email"]
```

## Prerequisites

* [A Courier Test API key](https://app.courier.com/~/test/platform/api-keys)
* An Auth0 tenant with a Database or Passwordless connection
* A published [template](https://www.courier.com/docs/design/templates/overview.md) to send

## How this differs from a webhook

Clerk and Stripe post to a route you host, so you verify a signature and run your own code. Auth0 Actions are your code, running inside Auth0. Three consequences follow.

**No route, no signature, no tunnel.** There is nothing public to host and nothing to verify, because nothing crossed the internet to reach you. Local development needs no `ngrok`.

**Secrets live in the Action.** Auth0 stores them and exposes them as `event.secrets`, so your Courier key never sits in your app's environment.

**Auth0 doesn't wait for the Action to finish.** A slow or failing Action never blocks a signup. Auth0's logs show whether it ran.

## Set it up

**1. Create the Action**

In the Auth0 Dashboard, go to **Actions → Library**, select **Build Custom**, and create an Action on the **Post User Registration** trigger.

**2. Add the SDK and your key**

In the Action editor, open the **Dependencies** panel in the left sidebar and add `@trycourier/courier`. Actions install npm packages into the runtime, so the [Node SDK](https://www.courier.com/docs/sdk-libraries/node.md) works here exactly as it does on your own server.

Then open the key icon in the same sidebar and add a secret named `COURIER_API_KEY` with your Courier key as its value.

Auth0 exposes the secret to the Action as `event.secrets.COURIER_API_KEY`. It is never in your application's environment and never in the Action's source.

**3. Write the Action**

The Action receives the newly created user on `event.user`. Create the profile, then send.

```javascript Post User Registration lines theme={null}
const Courier = require("@trycourier/courier");

exports.onExecutePostUserRegistration = async (event) => {
  const courier = new Courier({ apiKey: event.secrets.COURIER_API_KEY });
  const { user_id, email, given_name } = event.user;

  // Auth0's user_id becomes the Courier user id, so both systems agree.
  await courier.profiles.create(user_id, {
    profile: { email, given_name },
  });

  await courier.send.message({
    message: {
      to: { user_id },
      template: "nt_01kx4h2jdafq8bk9aftxak4b40",
      data: { name: given_name ?? "there" },
    },
  });
};
```

Actions are CommonJS, so the SDK comes in with `require` rather than `import`. Everything else is the same code you would write on your own server, and the [Node SDK reference](https://www.courier.com/docs/sdk-libraries/node.md) applies unchanged.

> [!NOTE]
>
> A failed send doesn't fail the signup or show the user an error. Wrap the calls in `try`/`catch` and `console.log` the error, then check **Monitoring → Logs** to confirm sends succeed.

**4. Deploy and add it to the flow**

Select **Deploy**, then go to **Actions → Triggers → post-user-registration** and drag the Action into the flow between Start and Complete. An Action that is deployed but not in the flow never runs, which is the most common reason nothing happens.

## Verify

**1. Register a test user**

Create a user through your app's signup, or from **User Management → Users** in the Auth0 Dashboard. The trigger fires for Database and Passwordless connections.

**2. Check the Auth0 log**

In **Monitoring → Logs**, find the registration event.

**3. Confirm the send**

Open [Logs](https://app.courier.com/logs) in Courier and confirm the message.

> [!NOTE]
>
> The trigger fires for **Database and Passwordless connections only**. A user arriving through a social or enterprise connection doesn't fire it, so a Google sign-up sends nothing. For those, use a post-login Action and check whether the login is the user's first.

## Adapt it for other triggers

| Auth0 trigger | What to send |
| :- | :- |
| `post-user-registration` | Welcome, for database and passwordless signups |
| `post-login` | A new-device or new-location alert |
| `send-phone-message` | Route Auth0's own MFA codes through Courier |
| `post-change-password` | A password-changed confirmation |

`post-login` runs on every login, so gate anything you send there on a condition. Sending on each login is how a welcome email becomes a complaint.
