Make your first Product API request in three steps: get credentials, exchange your API key for a bearer token, and call an endpoint. The examples use Sandbox; see Base URLs & environments for Staging and Production.
Ask api-support@aiwyn.ai for:
| Credential | What it is | Needed on |
|---|---|---|
| JWT API key | Identifies your integration and your firm, for example dev:eyJ.... Long-lived; store it like a password. | Every environment (each has its own key) |
| Cloudflare Access client ID and secret | Get requests past Cloudflare to the API. | Sandbox and Staging only |
The roles provisioned for the key decide which endpoints it can call; see Authentication & authorization.
Keep all of them server-side. The examples read them from environment variables:
export AIWYN_BASE_URL=https://api.sandbox.aiwyn.app
export AIWYN_API_KEY='<your-jwt-api-key>'
export CF_ACCESS_CLIENT_ID='<cf-access-client-id>'
export CF_ACCESS_CLIENT_SECRET='<cf-access-client-secret>'POST /v1/auth/token takes the API key in the body and returns a bearer token that lasts up to an hour. The exchange can hand back a token it issued earlier, with only minutes left, so request a new token whenever a call answers 401 rather than refreshing on a timer.
curl --request POST "$AIWYN_BASE_URL/v1/auth/token" \
--header "CF-Access-Client-Id: $CF_ACCESS_CLIENT_ID" \
--header "CF-Access-Client-Secret: $CF_ACCESS_CLIENT_SECRET" \
--header 'Content-Type: application/json' \
--data "{ \"jwtApiKey\": \"$AIWYN_API_KEY\" }"The response is the token alone:
{ "token": "eyJhbGciOiJIUzUxMiJ9..." }A 401 with "code": "UNAUTHORIZED" means the key is wrong, deactivated, or from another environment. A response that is not JSON comes from Cloudflare: the CF-Access-* headers are missing or wrong.
Production (https://api.aiwyn.ai) does not use Cloudflare Access: leave out the two CF-Access-* headers there. The Python and JavaScript examples send them only when CF_ACCESS_CLIENT_ID is set, so unset both variables when you point AIWYN_BASE_URL at Production.
List the first five clients of your firm. Send the token in the Authorization header (plus the Cloudflare headers on Sandbox and Staging):
curl --request POST "$AIWYN_BASE_URL/gql/v1/clients" \
--header "CF-Access-Client-Id: $CF_ACCESS_CLIENT_ID" \
--header "CF-Access-Client-Secret: $CF_ACCESS_CLIENT_SECRET" \
--header "Authorization: Bearer $TOKEN" \
--header 'Content-Type: application/json' \
--data '{ "pageSize": 5, "page": 0 }'The response holds the page of clients and the total number of clients in your firm:
{
"clients": [
{ "id": 122, "pmsRef": "1155", "clientRef": "41664", "name": "Acme Bread Co.", "active": true }
],
"total": { "aggregate": { "count": 13697 } }
}For the cURL example, set TOKEN to the token from step 2 first (export TOKEN='<token>').
- Pagination: read the next page by advancing
pagebypageSize. - Base URLs & environments: what the
/gql/v1,/api/v1and/v1/authprefixes mean. - Errors: the error bodies and what to retry.
- Webhooks in the API reference: receive signed events instead of polling, after creating a subscription with
POST /api/v1/event-subscriptions. - The API reference's Try it panel sends any request from your browser once you enter your token and, for Sandbox or Staging, the Cloudflare credentials.