Skip to main content

Organizations API

Base URL: /api/organization

All organization endpoints require authentication via JWT token in the Authorization: Bearer <token> header.


GET /api/organization

Get current organization details.

Authentication: Required (All roles)

Response (200 OK)

{
"success": true,
"organization": {
"id": "507f191e810c19729de860ea",
"name": "Acme Corp",
"slug": "acme-corp",
"plan": "free",
"limits": {
"maxProjects": 1,
"maxTestRuns": 100,
"maxUsers": 3,
"maxConcurrentRuns": 1,
"maxStorage": 10737418240
},
"userCount": 2,
"userLimit": 3,
"aiAnalysisEnabled": true,
"createdAt": "2026-01-15T10:00:00.000Z",
"updatedAt": "2026-02-08T14:30:00.000Z"
}
}

Error Responses

StatusErrorDescription
401Authentication requiredNo valid JWT token provided
404Organization not foundOrganization doesn't exist
500Failed to fetch organizationInternal server error

PATCH /api/organization

Update organization settings.

Authentication: Required
Authorization: Admin role only

Request Body

{
"name": "New Organization Name",
"aiAnalysisEnabled": false
}
FieldTypeRequiredDescription
namestringNoOrganization name (2-100 characters)
aiAnalysisEnabledbooleanNoEnable/disable AI failure analysis

Note: At least one field must be provided.

Response (200 OK)

{
"success": true,
"message": "Organization settings updated successfully",
"organization": {
"id": "507f191e810c19729de860ea",
"name": "New Organization Name",
"aiAnalysisEnabled": false
}
}

Error Responses

StatusErrorDescription
400Missing fieldsNo fields provided
400Invalid nameName empty, too short, or too long
400Invalid aiAnalysisEnabledMust be boolean
401Authentication requiredNo valid JWT token
403ForbiddenUser is not an admin
404Organization not foundOrganization doesn't exist
500Failed to update organizationInternal server error

Audit Logging

All settings changes are logged to the audit_logs collection:

{
"action": "org.settings_updated",
"targetType": "organization",
"details": {
"changes": { "name": "New Name", "aiAnalysisEnabled": false }
}
}

GET /api/organization/usage

Get organization usage statistics for the current billing period.

Authentication: Required (All roles)

Response (200 OK)

{
"success": true,
"usage": {
"currentPeriod": {
"startDate": "2026-02-01T00:00:00.000Z",
"endDate": "2026-02-28T23:59:59.999Z"
},
"testRuns": {
"used": 45,
"limit": 100,
"percentUsed": 45
},
"users": {
"active": 2,
"limit": 3
},
"storage": {
"usedBytes": 524288000,
"limitBytes": 10737418240
}
},
"alerts": [
{
"type": "warning",
"resource": "testRuns",
"message": "You've used 80% of your monthly test runs",
"percentUsed": 80
}
]
}

Usage Calculation

  • Test Runs: Counted from executions collection for current calendar month
  • Storage: Calculated by scanning reports/<organizationId>/ directory
  • Users: Count of active users in organization

Plan Limits

PlanTest Runs/MonthUsersStorage
Free100310 GB
Team1,00020100 GB
Enterprise10,000Unlimited1 TB

GET /api/organization/usage/alerts

Get usage alerts (warnings when approaching limits).

Authentication: Required (All roles)

Response (200 OK)

{
"success": true,
"alerts": [
{
"type": "warning",
"resource": "testRuns",
"message": "You've used 80% of your monthly test runs",
"percentUsed": 80
},
{
"type": "critical",
"resource": "users",
"message": "You've reached your user limit",
"percentUsed": 100
}
]
}

Alert Types

TypeTrigger
info50-79% of limit used
warning80-99% of limit used
critical100% of limit reached

Rate Limiting

EndpointLimitWindow
All organization endpoints100 requests1 minute per organization