> ## 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`, the default import of the v7 Node SDK. 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.
> 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.

# Automations with Segment

> Trigger an automation from a Segment track event and its properties.

## Segment Automation Trigger Example

In this example, we'll imagine an e-commerce site that sends out an email when a user successfully
checks out, or a reminder to finish checking out when they visit the page, but do not finish their
purchase.

For this, we'll need two automations. One for the reminder condition, the other for the checkout
success condition. We'll start with the reminder condition.

1. Create a new automation

2. Select the Segment trigger and choose correct `track` event. In our case, that is
   "Checkout Page Visited". Note: The track event dropdown is populated with events Courier has
   already received from Segment.

3. The reminder should be sent out a couple of hours after the checkout page was visited, so
   add a delay node with the desired delay time

4. Connect the delay node to a new send node and select the desired template. We set the userId to
   `refs.data.userId`, which is the userId sent to us by segment.

<Frame caption="UserId Referenced">
  <img src="https://mintcdn.com/courier-4f1f25dc/WNdu5qn7yJu4418-/assets/platform/automations/checkout-visited.png?fit=max&auto=format&n=WNdu5qn7yJu4418-&q=85&s=0f32b3ae405e4c24a161345ecfc7c941" alt="UserId Referenced" width="2564" height="1346" data-path="assets/platform/automations/checkout-visited.png" />
</Frame>

5. If the user successfully checks out, we won't want to send this notification. We'll add a
   cancellation token so we can cancel this run in from our next automation. Navigate to the
   settings tab and set `cancellation` to `refs.data.userId`. This way we can cancel any instance
   of this automation associated with the same user the notification would otherwise be sent to.
6. Click publish to finalize the template

The next automation will cancel the reminder automation from above, and send an invoice on
successful checkout.

1. Create a new automation.
2. Add a Segment trigger node with a track event set to "Checkout Complete"

<Frame caption="New Automation">
  <video src="https://mintcdn.com/courier-4f1f25dc/bBJgj_hJImV4Tq8h/assets/platform/automations/segment-checkout-complete.mp4?fit=max&auto=format&n=bBJgj_hJImV4Tq8h&q=85&s=8c05e8af5d7de8eedf2030ccc0438af5" poster="/assets/platform/automations/segment-checkout-complete.jpg" autoPlay loop muted playsInline aria-label="New Automation" style={{ width: "100%" }} data-path="assets/platform/automations/segment-checkout-complete.mp4" />
</Frame>

3. Add a cancel automation node and set the token to the user id. This will prevent the reminder
   to finish checking out from sending.
4. Send the Checkout Complete notification
