Documentation

Feature Gating

Read the membership entitlements a user's tier grants and use them to unlock features.

This page shows how to read the membership entitlements a user holds in your organization and gate features on them. You need a client_credentials token belonging to the organization, with scope membership:entitlements:read.

An organization's membership tiers grant membership entitlements: named keys that say what a user enrolled at that tier may do. Davi gates on the same keys. An activity, a session or a reward template can carry a required_entitlement, and only users whose tier grants that key can reach it.

Not the same as a Davi subscription. GET /users/me/subscription also returns a field called entitlements. Those are platform entitlements: Davi's own product features, such as a custom profile background or the number of profiles a user may keep. They describe the user's plan with Davi, not their membership in your organization, and cannot satisfy a membership gate.

Read a user's membership entitlements

One call returns whether the user holds a membership, at which tier, and what that tier grants.

curl "https://api.davi.social/api/v1/organizations/ORG_SLUG/memberships/USER_UUID/entitlements" \
  -H "Authorization: Bearer TOKEN"
{
  "user_uuid": "…",
  "organization_uuid": "…",
  "has_membership": true,
  "tier_uuid": "…",
  "tier_slug": "gold",
  "entitlements": { "reward.points_multiplier": 2, "activity.vip_lounge": null, "member": null }
}

A user with no membership answers 200 with has_membership: false and empty entitlements, not 404. Branch on it as an ordinary result.

Call this from the organization's own backend, with a client_credentials token issued to an application that belongs to the organization. No staff role carries membership:entitlements:read, so a user token, org-scoped or not, cannot read it.

The member key

The returned entitlements include the reserved member key, which every active membership holds. Check for it when the rule is "any tier".

GET /organizations/{organization_slug}/membership-tiers lists what each tier declares and leaves member out. If you build a user's entitlements from the tier list instead of this endpoint, add member for an active membership yourself, or every members-only gate denies everyone.

Check one key

curl "https://api.davi.social/api/v1/organizations/ORG_SLUG/memberships/USER_UUID/entitlements/activity.vip_lounge" \
  -H "Authorization: Bearer TOKEN"

Answers { "user_uuid": …, "organization_uuid": …, "key": …, "granted": true }. Use it when you need a yes or no for one gate. It applies the presence rule below for you.

Test presence, then read the value

A key with a null value is a boolean grant: its presence is the grant. A non-null value carries configuration, such as a multiplier.

Test for presence first, and read the value only for keys you know carry one. if (entitlements.foo) denies a granted boolean key, because its value is null.

How Davi evaluates a gate

A gated activity, session or reward template carries one required_entitlement:

required_entitlementWho passes
nullEveryone; there is no gate
"member"Any active membership, at any tier
any other keyOnly users whose tier grants that key

A gate names a key, not a tier. To open a gate to several tiers, grant the same key on each tier. Adding a tier later needs no change to existing gates. Gate your own features the same way and they keep working when the organization reorganizes its tiers.

Next