Set a membership's end date

PATCH /fapi/v1/organizations/{org_id}/memberships/{membership_id} · called from the environment's sign-in host

Sets or clears the date a membership ends (expires_at), for an organization profile screen. When the date passes, the membership is removed and the member's sessions and tokens in this organization's context are revoked. A membership_expiry_warned event is published seven days before. Roles change through Set a member's roles; this endpoint changes only the end date.

Requires the authenticated user's __Host-idp_session cookie with an exact Origin, or a first-party app's front API access token (Authorization: DPoP <token> with a DPoP proof; see Front API access token). The user must be an active member of the organization with both the idp_members:update_roles and idp_members:remove permissions. A user who is not a member gets 404 not_found; a member without both permissions gets 403 insufficient_permissions. You cannot change your own membership here (403 insufficient_permissions), and only a member who holds the admin role can change a member who holds a privileged role (403 role_not_assignable).

With @keenauth/js: await keenauth.organizations.setMemberExpiry(orgId, membershipId, "2027-03-31T00:00:00Z", { expectedVersion: 3 }); pass null to clear the date.

Request

Headers:

Header Required Description
Idp-Client yes SDK identifier.
Origin yes, with the cookie https://<sign-in host>.
If-Match no One version, "<version>", from the member list. A version that does not match, or more than one version, returns 412 precondition_failed.

org_id: the organization identifier (org_…). membership_id: the membership identifier (mem_…).

Body: {"expires_at": "<RFC 3339 time>"} or {"expires_at": null} to clear the date. expires_at is required. The time must be in the future and at most 365 days after the membership was created.

Response

200 OK with the membership (the same fields as an item of the member list) and ETag: "<version>".

Errors

Status Code When
400 unknown_field The body has a field other than expires_at.
400 malformed_request If-Match is malformed.
401 unauthenticated No valid session cookie or token.
403 insufficient_permissions The user lacks idp_members:update_roles or idp_members:remove, or the membership is the user's own.
403 role_not_assignable The member holds a privileged role and the user does not hold the admin role.
403 origin_not_allowed The Origin does not match.
404 not_found No such organization or membership for this user; an unknown, malformed or foreign identifier answers the same.
409 organization_disabled The organization is disabled or pending deletion (organization_pending_deletion).
412 precondition_failed If-Match does not name the membership's current version.
422 validation_failed expires_at is missing, not an RFC 3339 time, in the past, or more than 365 days after the membership was created.
503 service_unavailable Temporarily unavailable; retry after Retry-After.

Example

curl -X PATCH "https://example.keenauth.app/fapi/v1/organizations/org_01jbz6x8kq3m2n4p5r6s7t8v9a/memberships/mem_01jbz6x8kq3m2n4p5r6s7t8v9b" \
  -H "Idp-Client: my-app/1.0.0 (node/22.0.0)" \
  -H "Origin: https://example.keenauth.app" \
  -H 'If-Match: "3"' \
  -H "Content-Type: application/json" \
  -b cookies.txt \
  -d '{"expires_at": "2027-03-31T00:00:00Z"}'
{
  "id": "mem_01jbz6x8kq3m2n4p5r6s7t8v9b",
  "user_id": "usr_01jbz6x8kq3m2n4p5r6s7t8v9c",
  "status": "active",
  "roles": [{ "role_id": "rol_01jbz6x8kq3m2n4p5r6s7t8v9w", "source": "admin_api" }],
  "created_at": "2026-11-03T09:00:00Z",
  "activated_at": "2026-11-03T09:00:00Z",
  "updated_at": "2026-11-03T11:00:00Z",
  "version": 4
}

Personal data

This endpoint carries personal data: organization memberships and invitations. Personal data in the KeenAuth APIs describes what is stored, how long it is kept and how it is deleted. Do not send special categories of personal data (health, biometric data, religion, political opinions, sexual orientation) in any field.