> ## Documentation Index
> Fetch the complete documentation index at: https://docs.taxrock.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Get a token

> POST /oauth/token

Fill in your `client_id` and `client_secret`, then **Run** it. The `access_token` you receive is the Bearer
credential for every other endpoint.

Cache the access token and reuse it until it expires. `expires_in` gives its lifetime in seconds. Request a new
token when the cached one expires or the API answers `401`, not once per call.


## OpenAPI

````yaml api-reference/oauth-token-direct.json POST /oauth/token
openapi: 3.1.0
info:
  title: TaxRock API token (direct access)
  version: 1.0.0
  description: >-
    Get an access token with the client credentials grant. Lives on the login
    domain.
servers:
  - url: https://login-demo.taxrock.com
    description: Sandbox
security: []
paths:
  /oauth/token:
    post:
      tags:
        - Authentication
      summary: Get a token
      description: >-
        Exchange your client ID and client secret for an access token. Cache the
        token and reuse it until it expires.
      operationId: oauthTokenClientCredentials
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TokenRequest'
            example:
              grant_type: client_credentials
              client_id: YOUR_CLIENT_ID
              client_secret: YOUR_CLIENT_SECRET
              audience: https://api.taxrock.com
      responses:
        '200':
          description: Token issued.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TokenResponse'
              example:
                access_token: eyJhbGciOiJSUzI1NiIsInR5c...
                expires_in: 86400
                token_type: Bearer
        '401':
          description: Client authentication failed (bad `client_id`/`client_secret`).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OAuthError'
              examples:
                invalidClient:
                  summary: Bad client credentials
                  value:
                    error: access_denied
                    error_description: Unauthorized
        '403':
          description: >-
            The client is not allowed to request a token for the `audience`, for
            example when the audience is misspelled.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OAuthError'
              examples:
                unauthorizedClient:
                  summary: Client not authorized for the audience
                  value:
                    error: access_denied
                    error_description: >-
                      Client is not authorized to access
                      "https://api.taxrock.com".
      security: []
components:
  schemas:
    TokenRequest:
      type: object
      required:
        - grant_type
        - client_id
        - client_secret
        - audience
      description: Client credentials token request.
      properties:
        grant_type:
          type: string
          enum:
            - client_credentials
          description: Must be `client_credentials`.
        client_id:
          type: string
          description: Your client ID for the environment.
        client_secret:
          type: string
          description: Your client secret for the environment.
        audience:
          type: string
          enum:
            - https://api.taxrock.com
          description: '`https://api.taxrock.com` (the same in both environments).'
    TokenResponse:
      type: object
      required:
        - access_token
        - expires_in
        - token_type
      properties:
        access_token:
          type: string
          description: Send as a Bearer credential to the API.
        expires_in:
          type: integer
          description: Access token lifetime in seconds. Reuse the token until it expires.
        token_type:
          type: string
          enum:
            - Bearer
    OAuthError:
      type: object
      required:
        - error
      properties:
        error:
          type: string
          description: OAuth error code, e.g. `access_denied`.
        error_description:
          type: string
          description: Human-readable explanation.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.