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

# Login

> This endpoint takes a username or email, and a password, and returns an access token, refresh token, expiry time,
token type, and a sub which is used with the refresh token to get a new access token by calling the refresh
endpoint.

The access token is to be used for all endpoints except for /token and /refresh.



## OpenAPI

````yaml openapi_2024-03-26 post /token
openapi: 3.1.0
info:
  title: FastAPI
  version: '2024-03-26'
servers:
  - url: https://api.pathstack.io
    description: PathStack production environment
security: []
paths:
  /token:
    post:
      tags:
        - Auth
      summary: Login
      description: >-
        This endpoint takes a username or email, and a password, and returns an
        access token, refresh token, expiry time,

        token type, and a sub which is used with the refresh token to get a new
        access token by calling the refresh

        endpoint.


        The access token is to be used for all endpoints except for /token and
        /refresh.
      operationId: login_token_post
      parameters:
        - name: x-api-version
          in: header
          required: false
          schema:
            type: string
            format: date
            default: '2024-03-26'
            title: X-Api-Version
          examples:
            default:
              value: '2024-03-26'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UsernamePassword'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Success_AuthenticationResult_'
        '400':
          content:
            application/json:
              schema:
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: integer
                        example: 400
                        title: Error code
                      message:
                        type: string
                        example: Invalid JWT format
                        title: Error message
          description: Bad Request
        '401':
          content:
            application/json:
              schema:
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: integer
                        example: 401
                        title: Error code
                      message:
                        type: string
                        example: >-
                          Authentication header is missing, or token is
                          invalid/expired.
                        title: Error message
          description: Unauthorized
        '403':
          content:
            application/json:
              schema:
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: integer
                        example: 403
                        title: Error code
                      message:
                        type: string
                        example: You do not have access to this resource
                        title: Error message
          description: Forbidden
        '422':
          content:
            application/json:
              schema:
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: integer
                        example: 422
                        title: Error code
                      message:
                        type: string
                        example: Field required
                        title: Error message
                      loc:
                        items:
                          anyOf:
                            - type: string
                            - type: integer
                        type: array
                        title: Location
                      msg:
                        type: string
                        title: Message
                      type:
                        type: string
                        title: Error Type
          description: Unprocessable Entity
components:
  schemas:
    UsernamePassword:
      properties:
        username:
          type: string
          title: Username
          description: The username / email of the user
        password:
          type: string
          title: Password
      type: object
      required:
        - username
        - password
      title: UsernamePassword
    Success_AuthenticationResult_:
      properties:
        data:
          $ref: '#/components/schemas/AuthenticationResult'
          description: Successful response payload
      type: object
      required:
        - data
      title: Success[AuthenticationResult]
    AuthenticationResult:
      properties:
        token_type:
          type: string
          title: Token Type
        expires_in:
          type: integer
          title: Expires In
        access_token:
          type: string
          title: Access Token
        refresh_token:
          type: string
          title: Refresh Token
        sub:
          type: string
          title: Sub
        refresh_token_expires_in:
          type: integer
          title: Refresh Token Expires In
      type: object
      required:
        - token_type
        - expires_in
        - access_token
        - refresh_token
        - sub
        - refresh_token_expires_in
      title: AuthenticationResult

````