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

# Token

> Generate an access token for API authentication

## Notes

* Tokens are valid for 6 hours from the time of issuance
* Always use user\_id of the user making the request
* You can only request scopes that have been approved for your organization
* The token must be included in the `Authorization` header as a Bearer token for all authenticated API requests


## OpenAPI

````yaml POST /v1/token
openapi: 3.0.1
info:
  title: Parchment APIs
  description: >-
    Parchments API documentation for partner integrations, enabling secure
    e-prescription services
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://api.sandbox.parchmenthealth.io/external
  - url: https://api.parchmenthealth.io/external
security:
  - bearerAuth: []
paths:
  /v1/token:
    post:
      description: Generate an access token for API authentication
      parameters:
        - name: x-partner-id
          in: header
          required: true
          description: Partner ID for authentication - provided by Parchment
          schema:
            type: string
            example: tacklit
        - name: x-partner-secret
          in: header
          required: true
          description: Partner secret for authentication - provided by Parchment
          schema:
            type: string
        - name: x-organization-id
          in: header
          required: true
          description: >-
            Organization ID for authentication - provided by User from Parchment
            Portal
          schema:
            type: string
        - name: x-organization-secret
          in: header
          required: true
          description: >-
            Organization secret for authentication - provided by User from
            Parchment Portal
          schema:
            type: string
        - name: x-user-id
          in: header
          required: true
          description: >-
            Use the user_id of the user making the request to ensure actions are
            correctly attributed. Do not use the user_id of the user who
            originally set up the integration.
          schema:
            type: string
      requestBody:
        description: Token request parameters
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TokenRequest'
      responses:
        '200':
          description: Token generation successful
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TokenResponse'
              example:
                success: true
                statusCode: 200
                message: Token generated successfully
                data:
                  accessToken: eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtleTEifQ...
                  expiresIn: 3600
                  tokenType: Bearer
                  scope:
                    - create:patient
                    - read:patient_prescription
                timestamp: '2024-01-15T10:30:00.000Z'
                requestId: req_1705312200000_pqr678
                meta:
                  apiVersion: '1.0'
                  responseTime: 125
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                success: false
                statusCode: 422
                error:
                  type: https://parchment.health/errors/validation-error
                  title: Validation failed
                  detail: There were some problems with your input.
                  validation:
                    - field: scope
                      message: >-
                        Invalid enum value. Expected 'create:patient' |
                        'read:patient' | 'update:patient' | 'delete:patient' |
                        'read:patient_prescription' | 'create:user' |
                        'read:user' | 'read:users' | 'update:user' |
                        'delete:user', received 'remove:patient'
                      code: VALIDATION_ERROR
                timestamp: '2025-08-19T10:11:57.268Z'
                requestId: 1-68a44ded-5c4fdd75455250d518c3bab2
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                success: false
                statusCode: 401
                error:
                  type: https://parchment.health/errors/authentication-required
                  title: Unauthorized
                  detail: Invalid partner credentials provided.
                timestamp: '2024-01-15T10:30:00.000Z'
                requestId: req_1705312200000_vwx234
                meta:
                  apiVersion: '1.0'
      security: []
components:
  schemas:
    TokenRequest:
      type: object
      required:
        - grantType
        - scope
      properties:
        grantType:
          type: string
          description: Type of grant for OAuth2 authentication
          example: client_credentials
          default: client_credentials
          enum:
            - client_credentials
        scope:
          type: array
          description: List of permission scopes being requested
          items:
            type: string
            enum:
              - create:patient
              - read:patient
              - update:patient
              - read:patient_prescription
              - create:user
              - read:user
              - read:users
              - read:custom_drug
              - create:custom_drug
              - update:custom_drug
              - delete:custom_drug
              - update:user
              - delete:user
          example:
            - create:patient
            - read:patient_prescription
    TokenResponse:
      allOf:
        - $ref: '#/components/schemas/ExternalApiResponse'
        - type: object
          properties:
            statusCode:
              example: 200
            message:
              example: Token generated successfully
            data:
              $ref: '#/components/schemas/TokenData'
    Error:
      $ref: '#/components/schemas/ExternalApiErrorResponse'
    ExternalApiResponse:
      type: object
      required:
        - success
        - statusCode
        - message
        - data
        - timestamp
        - requestId
      properties:
        success:
          type: boolean
          description: Indicates if the request was successful
          example: true
        statusCode:
          type: integer
          description: HTTP status code
          example: 200
        message:
          type: string
          description: Human-readable success message
          example: Success
        code:
          type: string
          description: Machine-readable operation code
          example: SUCCESS
        data:
          type: object
          description: Response payload data
        timestamp:
          type: string
          format: date-time
          description: ISO 8601 timestamp of the response
          example: '2024-01-15T10:30:00.000Z'
        requestId:
          type: string
          description: Unique identifier for request tracing
          example: req_1705312200000_abc123
        pagination:
          type: object
          description: Pagination information for list operations
          properties:
            count:
              type: integer
              description: Number of items in current response
            hasNext:
              type: boolean
              description: Whether more items are available
            limit:
              type: integer
              description: Maximum items per page
            offset:
              type: integer
              description: Starting position of current page
            lastKey:
              type: string
              nullable: true
              description: >-
                Opaque cursor for fetching the next page. Use this value as the
                lastKey query parameter for the next request. If null, no more
                pages are available
    TokenData:
      type: object
      description: Authentication token data
      required:
        - accessToken
        - expiresIn
        - tokenType
        - scope
      properties:
        accessToken:
          type: string
          description: JWT token for API authentication
          example: eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtleTEifQ...
        expiresIn:
          type: integer
          description: Token validity in seconds
          example: 3600
        tokenType:
          type: string
          description: Type of the token
          example: Bearer
        scope:
          type: array
          description: List of granted permission scopes
          items:
            type: string
          example:
            - create:patient
            - read:patient_prescription
    ExternalApiErrorResponse:
      type: object
      required:
        - success
        - statusCode
        - error
        - timestamp
        - requestId
      properties:
        success:
          type: boolean
          description: Indicates if the request was successful
          example: false
        statusCode:
          type: integer
          description: HTTP status code
          example: 400
        code:
          type: string
          description: Machine-readable operation code identifying the error
          example: RESOURCE_NOT_FOUND
        error:
          type: object
          description: RFC 7807 compliant error details
          required:
            - type
            - title
            - detail
          properties:
            type:
              type: string
              format: uri
              description: URI identifying the problem type
              example: https://parchment.health/errors/validation-error
            title:
              type: string
              description: Human-readable summary of the problem
              example: Validation failed
            detail:
              type: string
              description: Human-readable explanation of the problem
              example: There were some problems with your input.
            instance:
              type: string
              format: uri
              description: URI reference to the specific occurrence
              example: /patients/123
            validation:
              type: array
              description: Field-level validation errors (for 422 responses)
              items:
                type: object
                properties:
                  field:
                    type: string
                    description: Field name that failed validation
                  message:
                    type: string
                    description: Validation error message
                  code:
                    type: string
                    description: Error code for programmatic handling
        timestamp:
          type: string
          format: date-time
          description: ISO 8601 timestamp of the response
          example: '2024-01-15T10:30:00.000Z'
        requestId:
          type: string
          description: Unique identifier for request tracing
          example: req_1705312200000_def456
        meta:
          type: object
          description: Additional response metadata
          properties:
            apiVersion:
              type: string
              description: API version used
              example: '1.0'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````