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

# Get or refresh a token

> Exchange the user's credentials for an ID token.

Send either a username and a Base64-encoded password, or a refresh token.

Only the API key is required on this call.




## OpenAPI

````yaml POST /token
openapi: 3.1.0
info:
  title: Codaclean API
  version: '1.0'
  description: >
    The Codaclean external API lets partner software (accounting tools, practice
    management software, sync agents) integrate with Codaclean on behalf of an
    accounting firm: manage its customers, request CODA and CODB mandates, and
    retrieve the CODA and CODB files Codaclean receives for them.
servers:
  - url: https://api.codaclean.io/v1
    description: Production
  - url: https://api.test.codaclean.io/v1
    description: Staging
security:
  - apiKeyAuth: []
    bearerAuth: []
tags:
  - name: Authentication
    description: Obtain and refresh the ID token sent with every other call.
  - name: Utilities
    description: Connectivity check.
  - name: Customers
    description: The customers (client companies) managed by the accounting firm.
  - name: Bank accounts
    description: Bank accounts (IBANs) linked to a customer.
  - name: Customer payroll providers
    description: Payroll providers (social secretariats) linked to a customer.
  - name: Mandates
    description: CODA mandates (per bank account) and CODB mandates (per payroll provider).
  - name: Reference data
    description: Banks and payroll providers known to Codaclean.
  - name: CODA files
    description: Bank statement files in CODA format.
  - name: CODB files
    description: Payroll files in CODB format, delivered by payroll providers.
paths:
  /token:
    post:
      tags:
        - Authentication
      summary: Get or refresh a token
      description: >
        Exchange the user's credentials for an ID token.


        Send either a username and a Base64-encoded password, or a refresh
        token.


        Only the API key is required on this call.
      operationId: getToken
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TokenRequest'
            examples:
              login:
                summary: Username and password
                value:
                  username: user@example.com
                  password: TXlQQHNzdzByZA==
              refresh:
                summary: Refresh token
                value:
                  refreshToken: >-
                    eyJjdHkiOiJKV1QiLCJlbmMiOiJBMjU2R0NNIiwiYWxnIjoiUlNBLU9BRVAifQ.EXAMPLE_REFRESH_TOKEN
      responses:
        '200':
          description: Token issued.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TokenResponse'
              examples:
                login:
                  summary: Login
                  value:
                    idToken: >-
                      eyJraWQiOiJFWEFNUExFIiwiYWxnIjoiUlMyNTYifQ.eyJzdWIiOiIwMDAwMDAwMC0wMDAwLTQwMDAtODAwMC0wMDAwMDAwMDAwMDEifQ.EXAMPLE_SIGNATURE
                    refreshToken: >-
                      eyJjdHkiOiJKV1QiLCJlbmMiOiJBMjU2R0NNIiwiYWxnIjoiUlNBLU9BRVAifQ.EXAMPLE_REFRESH_TOKEN
                refresh:
                  summary: Refresh (no new refresh token)
                  value:
                    idToken: >-
                      eyJraWQiOiJFWEFNUExFIiwiYWxnIjoiUlMyNTYifQ.eyJzdWIiOiIwMDAwMDAwMC0wMDAwLTQwMDAtODAwMC0wMDAwMDAwMDAwMDEifQ.EXAMPLE_SIGNATURE
        '400':
          description: Neither username/password nor refresh token provided.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Message'
              examples:
                missingCredentials:
                  summary: No credentials
                  value:
                    message: Username/password or refresh token are required
        '403':
          description: Missing or invalid API key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Message'
              examples:
                invalidApiKey:
                  summary: Missing or invalid API key
                  value:
                    message: Forbidden
                noApiKey:
                  summary: No API key
                  value:
                    message: Forbidden
        '429':
          $ref: '#/components/responses/TooManyRequests'
        '500':
          description: >-
            Authentication failed (wrong credentials, invalid refresh token…),
            or malformed request body.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TokenError'
              examples:
                wrongPassword:
                  summary: Wrong username or password
                  value:
                    message: Authentication failed
                    error: Incorrect username or password.
      security:
        - apiKeyAuth: []
components:
  schemas:
    TokenRequest:
      oneOf:
        - title: Username and password
          type: object
          required:
            - username
            - password
          properties:
            username:
              type: string
              description: The user's Codaclean login.
            password:
              type: string
              description: The user's password, **Base64-encoded**.
        - title: Refresh token
          type: object
          required:
            - refreshToken
          properties:
            refreshToken:
              type: string
              description: A refresh token previously returned by `POST /token`.
    TokenResponse:
      type: object
      properties:
        idToken:
          type: string
          description: >-
            Send it as `Authorization: Bearer <idToken>` on every other call.
            Valid for 1 hour.
        refreshToken:
          type: string
          description: >-
            Valid for 30 days. Returned on a username/password login only;
            absent from the response to a refresh.
    Message:
      type: object
      description: Confirmation returned by actions that do not return a resource.
      required:
        - message
      properties:
        message:
          type: string
    TokenError:
      type: object
      properties:
        message:
          type: string
        error:
          type: string
          description: Reason reported by the identity provider.
  responses:
    TooManyRequests:
      description: Rate limit or quota exceeded for this API key.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Message'
          examples:
            tooManyRequests:
              summary: Rate limit exceeded
              value:
                message: Too Many Requests
  securitySchemes:
    apiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: >-
        Identifies the partner software. Issued by Codaclean. Required on every
        call, including `POST /token`.
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT (Cognito ID token)
      description: >-
        Identifies the user and their accounting firm. Send the `idToken`
        returned by `POST /token` as `Authorization: Bearer <idToken>`. Valid
        for 1 hour.

````