Tags
Tags are { name, value } pairs attached to an email. They are stored with the email, returned by GET /emails/{id} and echoed in every webhook payload for that email (as an object, "tags": { "category": "welcome" }). Use them to tie events back to your own records without storing the SpacePost id.
import { SpacePost } from "@spacepost/node";
const spacepost = new SpacePost(process.env.SPACEPOST_API_KEY);
await spacepost.emails.send({ from: "Acme <hello@acme.com>", to: "user@example.com", subject: "Welcome", html: "<p>Hi</p>", tags: [ { name: "category", value: "welcome" }, { name: "user_id", value: "u_1042" }, ],});curl -X POST https://api.spacepost.dev/emails \ -H "Authorization: Bearer $SPACEPOST_API_KEY" -H "Content-Type: application/json" \ -d '{ "from": "Acme <hello@acme.com>", "to": ["user@example.com"], "subject": "Welcome", "html": "<p>Hi</p>", "tags": [{ "name": "category", "value": "welcome" }, { "name": "user_id", "value": "u_1042" }] }'X-SpacePost-Tags: category=welcome, user_id=u_1042- Up to 50 tags per email.
nameandvalueare each 1 to 256 characters and may contain only ASCII letters, numbers, underscores and dashes (A-Z a-z 0-9 _ -).- Spaces, dots,
@and non-ASCII characters are rejected with a422. Hash or slug values such as email addresses first, for exampleuser_1042or a SHA-256 hex digest.