Documentation

Change a Membership

Cancel, resume, renew, move, end and restore a membership, as the holder or as the organization.

This page covers changing a membership after it starts. Two parties can act on it: the holder, with their own token, and the organization, with an org-scoped token. They use different paths and have different powers.

All paths are under https://api.davi.social/api/v1.

Check access with the dates, not the status

status is active, cancelled, expired or revoked. It records how a membership ended, not whether it is running. Two nullable dates answer that:

FieldSet byMeans
valid_untilthe termWhen access ends. null never expires
cancelled_atthe holderThe holder gave notice. The membership will not continue past valid_until

status lags behind both dates:

  • A membership under notice stays active until its term ends, then becomes cancelled shortly afterwards. cancelled_at is the notice; status is the outcome.
  • A membership whose term runs out without notice stays active for two weeks after valid_until, while it can still be renewed, and only then becomes expired.

Gate access on valid_until, not on status == "active". Davi grants membership entitlements by the same rule: a membership past valid_until grants nothing, whatever its status says. Gating on the status lets a lapsed membership through for two weeks, and locks out a holder who cancelled but has paid time left.

status records how a membership ended, not who ended it. An organization ending one with revoke_immediately leaves it cancelled, the same as a holder's notice.

Notice does not withdraw anything. The tier, the membership entitlements and the membership wallet all stay in place until valid_until.

As the holder

These act on the caller's own membership with the caller's own token. There is no user_uuid in the path; the token identifies the holder.

MethodPathScope
GET/membershipsuser:read
GET/memberships/{organization_slug}/tiersmembership:read
GET/memberships/{organization_slug}/historymembership:read
GET/memberships/{organization_slug}/cardsmembership:read
PATCH/memberships/{organization_slug}membership:tier:update
POST/memberships/{organization_slug}/renewmembership:renew
POST/memberships/{organization_slug}/resumemembership:renew
DELETE/memberships/{organization_slug}membership:leave

A caller with no membership in the organization and an organization that does not exist both answer 404.

Cancel, and resume

curl -X DELETE \
  "https://api.davi.social/api/v1/memberships/ORG_SLUG" \
  -H "Authorization: Bearer ACCESS_TOKEN"

The response carries cancelled_at and the valid_until on which access ends. Two kinds of membership end immediately instead: a one-time membership, which has no valid_until, and one that had already lapsed. Either answers with status: "cancelled", and the organization receives membership.left.

POST /memberships/{organization_slug}/resume withdraws the notice and changes nothing else. It works only on a membership that is still running. A lapsed membership cannot be resumed; the holder joins again instead.

Cancelling twice, or resuming a membership that was never cancelled, answers 409.

Renew

curl -X POST \
  "https://api.davi.social/api/v1/memberships/ORG_SLUG/renew" \
  -H "Authorization: Bearer ACCESS_TOKEN"

The new term is added to the end of the current one, not to the moment of renewal, so renewing early keeps the time left. Renewing also withdraws a cancellation.

A membership stays renewable until renewable_until: two weeks after valid_until, or exactly valid_until if the holder gave notice. Renewing inside that window continues the same membership and history. Renewing after the term has ended starts the new term from now rather than from the old end. After the window, the membership is retired, and coming back is joining again on a fresh term, with the old history left behind.

GET /memberships lists only memberships still inside their term, so a holder in the two-week window does not see that membership there. Read GET /memberships/{organization_slug}/history to find it.

Only a free membership can be renewed with this call. A membership with a price, whether the tier's or a custom price set for that holder, answers 402 with the amount and currency owed. Send the holder through checkout instead; the new term follows the settled payment.

Move to another tier

Send PATCH /memberships/{organization_slug} with a tier the organization offers openly. The remaining term carries over, converted into the new tier's days by value: it buys fewer days on a more expensive tier and more on a cheaper one. No money moves. The join date, history and membership stay the same.

A tier the organization keeps closed, a tier belonging to another organization, and a tier that does not exist all answer 404. A holder can also be refused:

StatusWhen
409The membership has lapsed: renew or join again instead. Or it is already on that tier
402The membership is free and the new tier has a price. The body carries the amount and currency
400The move crosses between a one-time and a recurring tier, or between priced tiers in different currencies

As the organization

These take a staff member's user token or an org-scoped token, and name the holder by user_uuid.

MethodPathScope
POST/organizations/{organization_slug}/membershipsmembership:join
PATCH/organizations/{organization_slug}/memberships/{user_uuid}membership:tier:update
POST/organizations/{organization_slug}/memberships/{user_uuid}/renewmembership:renew
DELETE/organizations/{organization_slug}/memberships/{user_uuid}membership:leave
DELETE/organizations/{organization_slug}/memberships/{user_uuid}/revocationmembership:join
POST/organizations/{organization_slug}/memberships/{user_uuid}/restoremembership:join

Change a holder's tier, or renew

PATCH /organizations/{organization_slug}/memberships/{user_uuid} moves the holder to membership_tier_slug and leaves the term as it is: the same valid_until, with no conversion by value. It also sets the holder's agreed price from the request. A request without custom_tier_price_cents and custom_tier_payment_interval clears any agreed price, so send them again to keep one.

POST /organizations/{organization_slug}/memberships/{user_uuid}/renew adds a term without payment, whatever the tier costs. It never answers 402.

End a membership

DELETE /organizations/{organization_slug}/memberships/{user_uuid} gives a week's notice. The membership keeps granting everything it granted until the week runs out, then it is retired. Pass revoke_immediately to skip the notice.

To call it off within the week, send DELETE /organizations/{organization_slug}/memberships/{user_uuid}/revocation. Nothing was taken away, so nothing needs to be put back.

A pending revocation is visible to the organization only. The organization's membership list carries revoke_at. The holder's GET /memberships has no such field, and no email or event is sent. On a holder-facing page, the only ending you can show is a cancellation the holder made themselves.

Restore an ended membership

After the notice has run out, revocation no longer applies. Use POST /organizations/{organization_slug}/memberships/{user_uuid}/restore instead. It brings back the most recently ended membership as it stood: the term resumes with the time it had left rather than restarting, and a term that expired in the meantime comes back expired.

  • Notice the holder had given stays in place. Withdrawing it is the holder's action.
  • If the holder has rejoined in the meantime, the restore answers 409. An organization cannot have two live memberships for the same person.

Enrolling the person again instead starts a term from today, and the history shows them leaving and coming back.

Read the history

GET /memberships/{organization_slug}/history for the holder, or GET /organizations/{organization_slug}/memberships/{user_uuid}/history for the organization. Entries are newest first and cover earlier memberships too: a membership that lapsed and was later rejoined is a separate record. Each entry names the tier it was on, so tier moves appear in sequence.

A pending revocation does not appear in the history, because the membership is still live.

Next