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.
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.
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
{
"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:
curl -X GET https://yourdomain.ams.hkus1.s4s.host/api/v1/members \ -H "Authorization: Bearer 1|eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \ -H "Accept: application/json"
JavaScript / Fetch
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
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:
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:
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:
# 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:
- Subdomain resolution — Requests to
yourdomain.ams.hkus1.s4s.hostautomatically scope to theyourdomaintenant. - X-Tenant-ID header — For API integrations calling the central domain, pass
X-Tenant-ID: ten_pashain the request headers.
403 Forbidden. There is no cross-tenant API access.Token Scopes
When creating API tokens programmatically, you can restrict them to specific permission scopes:
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:
| Endpoint | Limit | Window |
|---|---|---|
POST /auth/login | 5 attempts | per minute, per IP |
POST /auth/refresh | 10 requests | per minute, per token |
| All other API endpoints | 60 requests | per minute, per user |
Error Codes
| HTTP Code | Error | Cause |
|---|---|---|
| 401 | Unauthorized | Missing, invalid, or expired token |
| 403 | Forbidden | Valid token but insufficient permissions or cross-tenant access |
| 422 | Unprocessable Entity | Validation error — missing or malformed request body fields |
| 429 | Too Many Requests | Rate limit exceeded — check Retry-After header |