ConsentLayer
API Reference

Errors

The API returns errors in a consistent JSON format:

{
  "error": {
    "code": "NOT_FOUND",
    "message": "Site not found"
  }
}

Error codes

CodeHTTP StatusDescription
UNAUTHORIZED401Missing or invalid API key
FORBIDDEN403Not authorized to access this resource
NOT_FOUND404Resource not found
VALIDATION_ERROR400Invalid request body or parameters
PLAN_LIMIT_REACHED403Account plan limit exceeded
CONFLICT409Resource already exists
INTERNAL_ERROR500Unexpected 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']}")