Skip to main content

Manage consent purposes and grants through the API

DEVELOPER GUIDE

Create consent purposes, record grants and withdrawals, and gate a collection rule on consent.

Who this guide is for

Developers and org staff who record what a person agreed to, on which wording, and who gave it.

Why it matters

Consent records are the proof of consent and of its withdrawal. A guardian must consent for a minor. Marketing consent can never be granted for a minor.

What you will do, in one sentence

Define a purpose, let people grant or withdraw through the routes, record paper consent as staff, and read the history.

Screens are captured from a seeded test system. Every name, address and number on the screens is invented. Prepared 15 November 2026.

1. The three collections​

All three are hidden system collections. The records API cannot write to them. The routes below write them.

CollectionWhat it holds
_consentPurposesWhat a person can consent to: key, name, text, version, lawfulBasis, minAge, requiresGuardian, marketing, org, status.
_consentsThe state: one row per person and purpose.
_consentEventsThe evidence: one append-only row per grant or withdrawal, with the full text that was shown.

A purpose is stored by its key, for example newsletter. Keys are lowercase, unique across all organizations and cannot change.

Questions for a lawyer

Which purposes need consent, and how long evidence must be kept, depends on your country and congregation. Have a lawyer review the purposes and the texts. This guide is not legal advice.

2. Create a purpose​

Superusers write global purposes. Owners, admins and registrars of an organization write that organization's purposes.

curl -X POST https://auth.example.org/api/orgs/$ORG_ID/consent-purposes \
-H "Authorization: $TOKEN" -H "Content-Type: application/json" \
-d '{"key": "riverside-newsletter", "name": "Newsletter", "text": "We email you the monthly newsletter.", "lawfulBasis": "consent"}'

In the admin UI, open Consents and select New purpose. The form has the fields Key, Name, Lawful basis, Minimum age, a marketing flag and Text shown to the person.

The Consents page in the admin UI.The Consents page in the admin UI.
The Consents page in the admin UI.

Rules to know:

  • Changing the text raises the version. Existing consents show as outdated until the person consents again.
  • Only the basis consent needs a grant.
  • A marketing purpose gets a minimum age of 18 when none is set. It can never be granted for a minor.
  • A purpose with consent records cannot be deleted (409). Set status to archived instead.

3. Grant and withdraw​

API keys are refused on every consent route.

RouteWho
GET /api/me/consentsA signed-in user. Shows each purpose and status: granted, withdrawn or none.
POST /api/me/consents/{purpose}/grantA signed-in user. Add {"member": "<id>"} for a minor of the household.
POST /api/me/consents/{purpose}/withdrawThe same.
POST /api/orgs/{id}/consentsOrg staff: {purpose, member or user, action, method, evidenceRef, givenBy}.
GET /api/orgs/{id}/consents?member=IDOrg staff. A person's consents and history.
GET /api/consents/history?subject=IDA superuser.
SubjectWho may grant or withdraw
An adult userThe user, signed in
A minor (a household member flagged isMinor)An active adult guardian of the same household
An adult, on paper or in personOrg staff, with an evidenceRef

Staff means owners, admins and registrars of the org. For a minor, staff must name the guardian in givenBy. Withdrawal is never harder than granting. Granting what is already granted writes no event.

Add the sign-in check you want, then the consent test:

@request.auth.id != "" &&
@collection._consents:c.subject ?= member &&
@collection._consents:c.purpose ?= "newsletter" &&
@collection._consents:c.withdrawnAt ?= ""

member is a relation to _householdMembers on your collection. For a user, compare with @request.auth.id. A consent that was never given has no row, so the rule denies. A withdrawn one has a date, so it denies.

5. History and erasure​

_consentEvents accepts new rows only. A model hook refuses every update and delete. Raw SQL is outside that guarantee. Each event keeps the action, purpose, version, text shown, time, who gave it, who did it, the method and the evidence reference.

The data map treats consent rows as retain. When a person is erased, the rows stay with the person replaced by a pseudonym. See the erasure guide.

A person's own consents are in their data export. Consents given for a child are not.

6. Quick reference card​

  1. POST /api/orgs/{id}/consents.
  2. Set action to grant and method to paper.
  3. Give an evidenceRef. For a minor, add givenBy.

Retire a purpose​

  1. PATCH the purpose with status: archived.
  2. Do not delete it. The evidence stays.

Hosted pages for people to manage their own consents are not built yet. The routes exist.