Skip to main content
The Node.js quickstart covers the calls themselves: create a user, send a notification, route it, start a journey. This page is the Astro wiring around them. How to read the API key as a runtime secret, how an endpoint sends, and how to render an in-app inbox as a React island without the key ever reaching the browser. It follows the Astro quickstart repo, which you can clone and run in about five minutes. What you need
  • The Node.js quickstart done, or at least a Courier API key and a user in Courier.
  • An Astro app on Node 20.9 or newer with a server adapter, plus @trycourier/courier. Add @astrojs/react and @trycourier/courier-react for the inbox.

1. Declare the key as a server secret

Read the key through astro:env, not import.meta.env. access: "secret" reads the environment on every request; import.meta.env.COURIER_API_KEY compiles to the build-time value as a string literal and bakes the key into the bundle you deploy. Do not prefix it with PUBLIC_, which Astro inlines into the browser build.

2. Send from an endpoint

Endpoints run on the server, so this is where a Courier call belongs. Set prerender = false so the route runs per request instead of being built once. The template lives in Design Studio, so copy and channel routing change without a deploy.

3. Add the inbox: token endpoint plus island

The inbox runs in the browser, so it gets a JWT scoped to one user and expiring, signed by your key on the server. The repo mints it in src/pages/api/courier/token.ts and reads the user id from the session, never from the request, because a caller who can name any user can read that user’s inbox.
The React island fetches that token and signs in inside an effect, guarded because React runs effects twice in development.
Mount it with client:only="react". The inbox renders as a custom element, so a server pass would render nothing and then throw it away.

Next steps