{"openapi":"3.1.0","info":{"title":"POST /api/v1/oauth2/exchange","version":"1.0.0","description":"Exchange Code"},"servers":[{"url":"https://api.ondayzero.com","description":"Production"}],"paths":{"/api/v1/oauth2/exchange":{"post":{"tags":["oauth"],"summary":"Exchange Code","description":"Exchange a single-use code or refresh token for access + refresh tokens.\n\nCalled from the SPA — no client credentials required.\nThe code was already authenticated when created via POST /oauth2/token.\n\n**Code exchange:** Provide ``code`` from the /token response.\n**Token refresh:** Provide ``refresh_token`` from a previous exchange.","operationId":"exchange_code","requestBody":{"content":{"application/x-www-form-urlencoded":{"schema":{"$ref":"#/components/schemas/Body_exchange_code_api_v1_oauth2_exchange_post"}}}},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/OAuthTokenResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"},"example":{"error":"validation_error","message":"Validation failed: amount: Input should be a valid integer","errors":{"amount":"Input should be a valid integer"},"code":"GEN_002","request_id":"3f0e7c2a-9b4d-4e1a-8c6f-2d5b7a1e9c30"}}}}},"x-fastapi-operation-id":"exchange_code_api_v1_oauth2_exchange_post"}}},"components":{"schemas":{"Body_exchange_code_api_v1_oauth2_exchange_post":{"properties":{"code":{"type":"string","title":"Code","description":"Single-use authorization code"},"refresh_token":{"type":"string","title":"Refresh Token","description":"Refresh token for renewal"},"client_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Client Id","description":"OAuth client identifier. Required when refreshing a client-bound refresh token (tokens minted via /oauth2/token); omit for legacy or SPA-issued tokens."}},"type":"object","title":"Body_exchange_code_api_v1_oauth2_exchange_post"},"OAuthTokenResponse":{"properties":{"access_token":{"type":"string","title":"Access Token","description":"The access token (JWT)"},"token_type":{"type":"string","title":"Token Type","description":"Token type (always 'Bearer')","default":"Bearer"},"expires_in":{"type":"integer","title":"Expires In","description":"Access token lifetime in seconds"},"refresh_token":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Refresh Token","description":"Refresh token for obtaining new access tokens"},"scope":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Scope","description":"Granted scope (may differ from requested)"},"business_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Business Id","description":"MCP grants bound to one business: that business's id. Absent when the grant reaches every business the user can."},"business_name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Business Name","description":"MCP grants bound to one business: that business's name"}},"type":"object","required":["access_token","expires_in"],"title":"OAuthTokenResponse","description":"Token Response.\n\nReturned after successful token or refresh request."},"ErrorResponse":{"title":"ErrorResponse","type":"object","description":"Envelope returned by every non-2xx response. Branch on `code` (stable) rather than `message` (human-readable, may change).","required":["error","message","code"],"properties":{"error":{"type":"string","description":"Error category: `validation_error`, `unauthorized`, `forbidden`, `not_found`, `conflict`, `rate_limited`, `server_error`, or `service_unavailable`."},"message":{"type":"string","description":"Human-readable explanation, safe to show to end users."},"code":{"type":"string","description":"Stable machine-readable code in `CATEGORY_NNN` form (e.g. `NOT_FOUND_006`, `AUTH_010`, `GEN_002`)."},"request_id":{"type":"string","description":"Correlation id for support requests. Echoes the `x-request-id` request header when one was supplied."},"errors":{"type":"object","additionalProperties":{"type":"string"},"description":"Field-level validation messages keyed by field name. Present on 400/422 validation failures only."}}}},"securitySchemes":{"BearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"API Token","description":"API token authentication. Format: `Bearer dz_...`"}}},"security":[{"BearerAuth":[]}]}