AMS Docs

API Authentication

The AMS API uses Laravel Sanctum token-based authentication. All API requests must include a valid Bearer token in the Authorization header. Tokens are tenant-scoped — a token issued for one tenant cannot be used to access another tenant's data.

ℹ️ Base URLAll API requests target https://yourdomain.ams.hkus1.s4s.host/api/v1. Replace yourdomain with your organisation's subdomain. The demo instance uses ams.hkus1.s4s.host.

Getting an Access Token

Obtain a token by posting your credentials to the login endpoint. On success, the response contains your access token, a refresh token, and the authenticated user's details including their role and available permissions.

bash
curl -X POST https://yourdomain.ams.hkus1.s4s.host/api/v1/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email":"admin@pasha.org","password":"Demo@2024!"}'

Response Structure

json — success response
{
  "success": true,
  "token": "1|eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "refresh_token": "rt_9f3a2b1c4d5e6f7a8b9c0d1e2f3a4b5c",
  "expires_at": "2026-04-14T10:00:00Z",
  "user": {
    "id": "usr_01HXYZ",
    "name": "Pasha Admin",
    "email": "admin@pasha.org",
    "role": "admin",
    "tenant_id": "ten_pasha",
    "permissions": ["members.read", "members.write", "events.manage"]
  },
  "wizard_redirect": false
}

The wizard_redirect field is true for new tenants who have not yet completed the setup wizard. In that case, redirect the user to /onboarding/wizard before allowing access to the main application.

Using the Token in Requests

Include the token in every API request using the Authorization header with the Bearer scheme:

bash
curl -X GET https://yourdomain.ams.hkus1.s4s.host/api/v1/members \
  -H "Authorization: Bearer 1|eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -H "Accept: application/json"

JavaScript / Fetch

javascript
const response = await fetch('https://yourdomain.ams.hkus1.s4s.host/api/v1/members', {
  method: 'GET',
  headers: {
    'Authorization': `Bearer ${token}`,
    'Content-Type': 'application/json',
    'Accept': 'application/json'
  }
});
const data = await response.json();

Python

python
import requests

BASE_URL = "https://yourdomain.ams.hkus1.s4s.host/api/v1"
TOKEN = "1|eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

headers = {
    "Authorization": f"Bearer {TOKEN}",
    "Accept": "application/json"
}

response = requests.get(f"{BASE_URL}/members", headers=headers)
members = response.json()

Token Refresh

Access tokens expire after 30 days by default. Use the refresh token to obtain a new access token without requiring the user to re-authenticate:

bash
curl -X POST https://yourdomain.ams.hkus1.s4s.host/api/v1/auth/refresh \
  -H "Content-Type: application/json" \
  -d '{"refresh_token":"rt_9f3a2b1c4d5e6f7a8b9c0d1e2f3a4b5c"}'

Logout

Revoke the current token by calling the logout endpoint. This immediately invalidates the token server-side:

bash
curl -X POST https://yourdomain.ams.hkus1.s4s.host/api/v1/auth/logout \
  -H "Authorization: Bearer $TOKEN"

CSRF for Web Sessions

If you are building a browser-based application using cookie sessions (rather than Bearer tokens), you must first fetch a CSRF cookie before making any state-changing requests:

bash
# Fetch CSRF cookie (sets XSRF-TOKEN cookie)
curl -c cookies.txt https://yourdomain.ams.hkus1.s4s.host/sanctum/csrf-cookie

# All subsequent POST/PUT/DELETE must include X-XSRF-TOKEN header

Multi-Tenant Authentication

The AMS API resolves the tenant context from the request in two ways:

⚠️ Cross-Tenant RequestsTokens are strictly scoped to their issuing tenant. Attempting to use a token from Tenant A to access Tenant B's data will return 403 Forbidden. There is no cross-tenant API access.

Token Scopes

When creating API tokens programmatically, you can restrict them to specific permission scopes:

bash — create scoped API token
curl -X POST https://yourdomain.ams.hkus1.s4s.host/api/v1/auth/tokens \
  -H "Authorization: Bearer $ADMIN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Zapier Integration",
    "scopes": ["members:read", "events:read", "webhooks:write"]
  }'

Rate Limits

The login endpoint is rate-limited to prevent brute-force attacks:

EndpointLimitWindow
POST /auth/login5 attemptsper minute, per IP
POST /auth/refresh10 requestsper minute, per token
All other API endpoints60 requestsper minute, per user

Error Codes

HTTP CodeErrorCause
401UnauthorizedMissing, invalid, or expired token
403ForbiddenValid token but insufficient permissions or cross-tenant access
422Unprocessable EntityValidation error — missing or malformed request body fields
429Too Many RequestsRate limit exceeded — check Retry-After header