{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":[]},"type":"markdown"},"seo":{"title":"Authentication","description":"Reference, guides, and webhooks for the Aiwyn API: clients, contacts, engagements, projects, billing, payments, time, and files.","llmstxt":{"title":"Aiwyn API","description":"Aiwyn Product API documentation. Start with reference/quickstart.md; the API reference lists every endpoint, its required role, its request and response schemas, and the webhook payload."}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"authentication","__idx":0},"children":["Authentication"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Every Product API request must be authenticated with a short-lived ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["bearer token"]},"."]},{"$$mdtype":"Tag","name":"blockquote","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Sandbox and Staging:"]}," every request, including the token exchange below, must also"," ","send the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["CF-Access-Client-Id"]}," and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["CF-Access-Client-Secret"]}," headers. See"," ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/reference/base-urls#cloudflare-access-sandbox-and-staging"},"children":["Cloudflare Access"]},". Production does not"," ","use them."]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["For the whole flow with Python and JavaScript examples, see the ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/reference/quickstart"},"children":["Quickstart"]},"."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"1-exchange-your-api-key-for-a-token","__idx":1},"children":["1. Exchange your API key for a token"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Send your JWT API key to the token endpoint:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"curl --location 'https://api.sandbox.aiwyn.app/v1/auth/token' \\\n  --header 'CF-Access-Client-Id: <cf-access-client-id>' \\\n  --header 'CF-Access-Client-Secret: <cf-access-client-secret>' \\\n  --header 'Content-Type: application/json' \\\n  --data '{ \"jwtApiKey\": \"<your-jwt-api-key>\" }'\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The response is the bearer token alone: ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["{ \"token\": \"eyJ...\" }"]},"."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"2-send-the-token-on-every-request","__idx":2},"children":["2. Send the token on every request"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"Authorization: Bearer <token>\n"},"children":[]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"curl --request POST 'https://api.sandbox.aiwyn.app/gql/v1/clients' \\\n  --header 'CF-Access-Client-Id: <cf-access-client-id>' \\\n  --header 'CF-Access-Client-Secret: <cf-access-client-secret>' \\\n  --header 'Authorization: Bearer <token>' \\\n  --header 'Content-Type: application/json' \\\n  --data '{ \"pageSize\": 5, \"page\": 0 }'\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"token-lifetime","__idx":3},"children":["Token lifetime"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Tokens are short-lived and last ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["up to an hour"]},". The exchange can return a token it issued"," ","earlier, so a token you have just received may have only minutes left."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Don't schedule refreshes by the clock: when a call answers ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["401"]},", request a new token from"," ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["POST /v1/auth/token"]}," and retry the call once."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["A ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["401 Unauthorized"]}," response means the token is missing, malformed, or expired."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"what-a-token-can-do","__idx":4},"children":["What a token can do"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The operations a token is allowed to perform are determined by the ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["roles"]}," ","provisioned for your API key. See ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/reference/authorization"},"children":["Authentication & authorization"]}," ","for the full list of roles and the endpoints each one grants, and"," ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/reference/errors"},"children":["Errors"]}," for the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["401"]}," / ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["403"]}," response shapes."]}]},"headings":[{"value":"Authentication","id":"authentication","depth":1},{"value":"1. Exchange your API key for a token","id":"1-exchange-your-api-key-for-a-token","depth":2},{"value":"2. Send the token on every request","id":"2-send-the-token-on-every-request","depth":2},{"value":"Token lifetime","id":"token-lifetime","depth":2},{"value":"What a token can do","id":"what-a-token-can-do","depth":2}],"frontmatter":{"seo":{"title":"Authentication"}},"lastModified":"2026-11-05T23:35:13.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/reference/authentication","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}