Organization Invitations API

Learn how to invite users to join your organizations using the REST API.

Overview

The Organization Invitations API allows you to invite users to join an organization by email. The system sends an invitation with a unique token that recipients can use to accept the invitation and join the organization.

Base Endpoint

/organizations-users-invites

Invitation Object

The invitation object represents a pending or accepted invitation to join an organization.

Invitation Object
{
  "id": 456,
  "organization_id": 123,
  "email": "user@example.com",
  "created_by_user_id": 101,
  "role": "member",
  "status": "pending",
  "token": "abc123def456",
  "expires_at": "2023-01-02T00:00:00.000Z",
  "created_at": "2023-01-01T00:00:00.000Z",
  "updated_at": "2023-01-01T00:00:00.000Z",
  "organization": {
    "id": 123,
    "name": "Acme Inc"
  },
  "created_by_user": {
    "id": 101,
    "email": "admin@example.com",
    "first_name": "Admin",
    "last_name": "User"
  }
}

Create an Invitation

Send an invitation to a user by email to join your organization. The system will generate a unique token and send an email with a link that the recipient can use to accept the invitation.

Request
POST /organizations-users-invites

curl -X POST https://api.achieveapex.com/organizations-users-invites \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "email": "user@example.com",
    "organization_id": 123,
    "role": "member"
  }'
Response
{
  "id": 456,
  "organization_id": 123,
  "email": "user@example.com",
  "created_by_user_id": 101,
  "role": "member",
  "status": "pending",
  "token": "abc123def456",
  "expires_at": "2023-01-02T00:00:00.000Z",
  "created_at": "2023-01-01T00:00:00.000Z",
  "updated_at": "2023-01-01T00:00:00.000Z"
}

Request Parameters

ParameterTypeRequiredDescription
emailStringYesEmail address of the user to invite
organization_idNumberYesID of the organization to invite the user to
roleStringYesRole to assign to the user (e.g., "owner", "admin", "member")

List Invitations

Retrieve a list of invitations for a specific organization, optionally filtered by status.

Request
GET /organizations-users-invites

curl -X GET https://api.achieveapex.com/organizations-users-invites \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "query": {
      "organization_id": 123,
      "status": "pending",
      "$limit": 100,
      "$sort": { "created_at": -1 }
    }
  }'
Response
{
  "total": 2,
  "limit": 100,
  "skip": 0,
  "data": [
    {
      "id": 456,
      "organization_id": 123,
      "email": "user1@example.com",
      "created_by_user_id": 101,
      "role": "member",
      "status": "pending",
      "token": "abc123def456",
      "expires_at": "2023-01-02T00:00:00.000Z",
      "created_at": "2023-01-01T00:00:00.000Z",
      "updated_at": "2023-01-01T00:00:00.000Z"
    },
    {
      "id": 457,
      "organization_id": 123,
      "email": "user2@example.com",
      "created_by_user_id": 101,
      "role": "admin",
      "status": "pending",
      "token": "ghi789jkl012",
      "expires_at": "2023-01-02T00:00:00.000Z",
      "created_at": "2023-01-01T00:00:00.000Z",
      "updated_at": "2023-01-01T00:00:00.000Z"
    }
  ]
}

Query Parameters

ParameterTypeRequiredDescription
organization_idNumberYesID of the organization to fetch invitations for
statusStringNoFilter invitations by status (e.g., "pending", "accepted")
emailStringNoFilter invitations by email address
tokenStringNoFilter by specific invitation token
$limitNumberNoMaximum number of invitations to return (default: 10)
$skipNumberNoNumber of invitations to skip (for pagination)
$sortObjectNoSort criteria (e.g., { "created_at": -1 } for newest first)

Get an Invitation

Retrieve a single invitation by its ID or token.

Request by ID
GET /organizations-users-invites/:id

curl -X GET https://api.achieveapex.com/organizations-users-invites/456 \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json"
Request by Token
GET /organizations-users-invites

curl -X GET https://api.achieveapex.com/organizations-users-invites \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "query": {
      "token": "abc123def456",
      "$limit": 1
    }
  }'

Accept an Invitation

When a user follows the invitation link, they'll be taken to a page where they can accept the invitation. The system handles this process automatically, creating a new user account if necessary.

For API access, you can use the following endpoint to accept an invitation:

Request
PATCH /organizations-users-invites/:id

curl -X PATCH https://api.achieveapex.com/organizations-users-invites/456 \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "status": "accepted"
  }'
Response
{
  "id": 456,
  "organization_id": 123,
  "email": "user@example.com",
  "created_by_user_id": 101,
  "role": "member",
  "status": "accepted",
  "token": "abc123def456",
  "expires_at": "2023-01-02T00:00:00.000Z",
  "created_at": "2023-01-01T00:00:00.000Z",
  "updated_at": "2023-01-01T12:34:56.789Z"
}

Note: Invitations expire after 24 hours. Each invitation link can only be used once. When an invitation is accepted, the user is automatically added to the organization with the specified role.

Error Handling

The Organization Invitations API returns standard HTTP status codes and error messages.

Error Response
{
  "name": "BadRequest",
  "message": "Invalid token or invitation has expired",
  "code": 400,
  "className": "bad-request"
}
Status CodeDescription
400 Bad RequestInvalid parameters, expired invitation, or already used token
401 UnauthorizedMissing or invalid authentication
403 ForbiddenNot authorized to manage invitations for this organization
404 Not FoundInvitation not found
500 Internal Server ErrorServer error

Report an issue with this documentation

Please log in to report issues with our documentation.