API Reference
Errors
The API returns errors in a consistent JSON format:
{
"error": {
"code": "NOT_FOUND",
"message": "Site not found"
}
}Error codes
| Code | HTTP Status | Description |
|---|---|---|
UNAUTHORIZED | 401 | Missing or invalid API key |
FORBIDDEN | 403 | Not authorized to access this resource |
NOT_FOUND | 404 | Resource not found |
VALIDATION_ERROR | 400 | Invalid request body or parameters |
PLAN_LIMIT_REACHED | 403 | Account plan limit exceeded |
CONFLICT | 409 | Resource already exists |
INTERNAL_ERROR | 500 | Unexpected server error |
Handling errors
const res = await fetch(`https://api.consentlayer.com/api/v1/sites/${id}`, {
headers: { Authorization: `Bearer ${apiKey}` },
});
if (!res.ok) {
const { error } = await res.json();
console.error(`${error.code}: ${error.message}`);
}import requests
res = requests.get(
f"https://api.consentlayer.com/api/v1/sites/{site_id}",
headers={"Authorization": f"Bearer {api_key}"},
)
if not res.ok:
error = res.json()["error"]
print(f"{error['code']}: {error['message']}")