API Reference

Contacts

Create, read, update, and delete contacts in your workspace. All endpoints require a Bearer token — see Authentication for details.

Overview

MethodPathDescription
GET/api/v1/contactsList contacts (paginated)
POST/api/v1/contactsCreate a contact
GET/api/v1/contacts/:idGet a single contact
PATCH/api/v1/contacts/:idUpdate a contact (partial)
DELETE/api/v1/contacts/:idDelete a contact

List contacts

GET/api/v1/contacts

Returns a cursor-paginated list of contacts for the authenticated workspace, newest first. The response includes has_more and next_cursor; to fetch the next page, pass next_cursor back as the cursor query parameter.

Pass segment_id to restrict the list to members of a segment (a UUID that must belong to your workspace). An unknown or foreign id returns 404 not_found, and a malformed (non-UUID) value returns 400 invalid_field. It combines with the other filters and with pagination.

Query parameters

FieldTypeRequiredDescription
limitnumberoptionalMax contacts to return. Default 50, max 100 (over-large values are clamped).
cursorstringoptionalOpaque pagination cursor from a previous response's next_cursor. Omit for the first page; a malformed cursor returns 400 invalid_field.
statusstringoptional'subscribed', 'unsubscribed', 'not_subscribed', 'bounced' or 'complained'. Omit for all.
searchstringoptionalFilter contacts whose email contains this substring.
segment_idstringoptionalFilter to members of a segment (UUID). The segment must belong to your workspace; an unknown or foreign id returns 404 not_found; a malformed (non-UUID) value returns 400 invalid_field.

Response

import { PristineSend } from "pristinesend"

const ps = new PristineSend(process.env.PRISTINESEND_API_KEY!)

// The returned page auto-paginates — iterate across every page transparently.
for await (const contact of await ps.contacts.list({ limit: 100, status: "subscribed" })) {
  console.log(contact.email)
}

Filter to one segment's members:

# Only contacts that belong to a segment
curl "https://pristinesend.com/api/v1/contacts?segment_id=8e4f2b1c-1a2b-4c3d-9e8f-0a1b2c3d4e5f" \
  -H "Authorization: Bearer ps_live_YOUR_API_KEY"

Create a contact

POST/api/v1/contacts

Creates a new contact. Returns 409 Conflict if the email already exists in the workspace. To add someone only once they confirm by email, send double_opt_in (see Double opt-in).

Request body

FieldTypeRequiredDescription
emailstringrequiredContact email address. Must be unique per workspace.
first_namestringoptionalContact's first name.
last_namestringoptionalContact's last name.
statusstringoptional'subscribed', 'unsubscribed' or 'not_subscribed'. Defaults to 'subscribed'. A not_subscribed contact is not on your mailing list (they get no campaigns or automation emails) and does not count toward your contact limit.
propertiesobjectoptionalArbitrary key/value metadata. Must be a JSON object. A key that matches a custom property you have defined as a number or a date must carry a value of that shape — a date is YYYY-MM-DD — or the call is refused with invalid_field. Keys with no definition are stored as-is.
double_opt_inbooleanoptionaltrue: email the person a confirmation and add them only once they confirm (see Double opt-in below). Off by default.
languagestringoptionalWith double_opt_in only: the language of the confirmation email and its page. One of en, de, es, fr, pt, sv, da, nb, fi; English when left out.

Response

import { PristineSend } from "pristinesend"

const ps = new PristineSend(process.env.PRISTINESEND_API_KEY!)

const contact = await ps.contacts.create({
  email: "jane@example.com",
  first_name: "Jane",
  last_name: "Doe",
  properties: { city: "Seattle" },
})
console.log("Created:", contact.id)

Double opt-in

POST/api/v1/contacts

With "double_opt_in": true, the contact is not added yet. The person is emailed a confirmation, and the answer is 202 Accepted with the pending signup. They are added when they press Confirm in the email; the signup.confirmed event then names the signup's id and the new contact. Nothing else is needed: the email is the one a signup form sends, from your default sender, with your organisation's name, logo and mailing address, and its link opens a page on your page address with Confirm and This wasn't me. The link works for 7 days.

import { PristineSend } from "pristinesend"

const ps = new PristineSend(process.env.PRISTINESEND_API_KEY!)

const signup = await ps.contacts.create({
  email: "ana@example.com",
  first_name: "Ana",
  properties: { plan: "trial" },
  double_opt_in: true,
  language: "es",
})
// signup.status is "pending": Ana is added when she presses Confirm.
console.log("Waiting for:", signup.id)

When they confirm

The contact is made subscribed, with the names and properties you sent; a property whose value no longer fits its type by then is left out. Someone who had unsubscribed by their own choice is subscribed again, and only their empty fields are filled. "How this contact joined" on the contact's page shows the confirmation, and the contact reads "Added through the API, after they confirmed by email". If your plan's contact limit is reached, the signup waits for room (up to 90 days) and the event comes once it is added.

Calling again

The same address while its signup still waits answers 200 with that signup and sends nothing, so a retry is safe.

When the email may not go

The call has answered 202 by then, and the address gets no email when: it is on your do-not-send list by then; the address check finds it undeliverable, risky, disposable or misspelt; it was sent a confirmation from your account in the last 24 hours (30 days after the person's own opt-out); it was sent 3 today from all accounts together; your account has sent 50 today to its domain, outside the large mailbox providers; or the person said This wasn't me to one of your confirmations, or marked one as spam, in the last 90 days. None of these is said to the caller: they protect the person, not the call.

The breaker

When your API confirmations of the last 24 hours show 50 or more sent with 10% or more bounced, or 2 or more marked as spam, new calls are refused with double_opt_in_unavailable (the message gives the numbers) and confirmations not yet sent wait. Your account gets a notice in PristineSend, and we are told. It lifts by itself once those emails are 24 hours old. Either usually means the addresses were not typed in by the people themselves.

What can be refused

Each is said before anything is written:

StatuscodeWhen
400invalid_fielddouble_opt_in is not true or false; language is not one of the nine, or is sent without double_opt_in; status is anything but subscribed; a name is over 100 characters; properties are too large to keep with the signup
403live_key_requiredA test key: a confirmation is real email
403recipient_suppressedThe address is on your do-not-send list for something the person cannot lift themselves: a bounce, a spam complaint, or a block you or we set
409conflictThe contact is already subscribed (nothing to confirm), or you set it to unsubscribed and they did not opt out themselves
403double_opt_in_unavailableYour account cannot send confirmations now: signup forms are turned off for it, no mailing address is set, or the breaker below is tripped (the message gives the numbers)
403sending_pausedSending is paused on your account
403sender_not_verifiedNo default sender on a verified domain: confirmations come from it
403domain_not_verifiedNo verified sending domain, or the default sender's domain cannot send from us right now
429rate_limitedYour account's double opt-in and form signups for the day are taken. Retry-After counts to midnight UTC
503service_unavailableSomething could not be checked just now, or double opt-in is paused for every account. Nothing was written; try again after Retry-After

The daily limit is the one your account's signup forms share: your plan's contact limit divided by 20 (5,000 a day on an unlimited plan), at most 50 a day in the 14 days after your first form goes live.

Get a contact

GET/api/v1/contacts/:id

Returns a single contact by UUID. Returns 404 if the contact doesn't exist or belongs to a different workspace.

import { PristineSend } from "pristinesend"

const ps = new PristineSend(process.env.PRISTINESEND_API_KEY!)

const contact = await ps.contacts.get("8e4f2b1c-1a2b-4c3d-9e8f-0a1b2c3d4e5f")
console.log(contact.email, contact.status)

Update a contact

PATCH/api/v1/contacts/:id

Partially updates a contact. Only include the fields you want to change. The properties field is merged with existing properties rather than replaced. Email cannot be changed after creation.

Request body

FieldTypeRequiredDescription
first_namestringoptionalNew first name.
last_namestringoptionalNew last name.
statusstringoptional'subscribed', 'unsubscribed' or 'not_subscribed'. Moving a contact to subscribed counts toward your contact limit, so it can answer 403 plan_limit_reached.
propertiesobjectoptionalProperties to merge into existing properties. Email cannot be changed. The same typed-value rule as on create applies: a number or date property must carry a value of that shape.

Response

import { PristineSend } from "pristinesend"

const ps = new PristineSend(process.env.PRISTINESEND_API_KEY!)

// properties is merged, not replaced; only include what changes.
const contact = await ps.contacts.update("8e4f2b1c-1a2b-4c3d-9e8f-0a1b2c3d4e5f", {
  status: "unsubscribed",
  properties: { tier: "pro" },
})
console.log(contact.status, contact.properties)

Delete a contact

DELETE/api/v1/contacts/:id

Permanently deletes a contact. Returns 204 No Content on success with no response body. Returns 404 if the contact doesn't exist.

import { PristineSend } from "pristinesend"

const ps = new PristineSend(process.env.PRISTINESEND_API_KEY!)

await ps.contacts.delete("8e4f2b1c-1a2b-4c3d-9e8f-0a1b2c3d4e5f")
// Resolves on 204 No Content; throws NotFoundError if the contact is gone.

Error codes

All errors return the standard envelope — a code, message, optional param (field-validation only), and a request_id (also the X-Request-Id header):

{
  "error": {
    "code": "invalid_field",
    "message": "Email is not a valid email address.",
    "param": "email",
    "request_id": "req_8f3c9a1b2d4e5f6071829304"
  }
}
StatuscodeWhen
400invalid_requestMalformed or unparseable JSON body
400missing_fieldA required field (e.g. email) is absent
400invalid_fieldA field is present but invalid, e.g. a bad email, a non-object properties, or a malformed cursor
401unauthorizedMissing or invalid API key
404not_foundContact doesn't exist in this workspace
409conflictEmail already exists in this workspace
500internal_errorUnexpected server error — safe to retry

See the full Error codes reference for general API errors.