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

# Upload documents for doc scan

> Uploading documents for doc scan is a three-step flow:
  1. Request upload slots with `PUT /doc-scan/presign`, providing each
     PDF file name (and optional external identifier). The response
     includes `presigned_url` and `path` values for every requested
     file.
  2. Upload the PDF content to every `presigned_url` using an HTTP
     `PUT` request with `Content-Type: application/octet-stream`.
  3. Call this endpoint with the `path` (and optional
     `external_document_id`) of every uploaded file so Teal can
     extract the document data.

`type` (`p45`, `p60` or `universal_credit`) is required and tells
Teal which document type to extract.

Each `path` must start with `{client_name}/{user_id}/`. A maximum of
12 files can be submitted at once and each file must be 10 MB or
smaller. The uploaded files are deleted from storage after
processing. The relevant scan flag (`p45_scan_enabled`,
`p60_scan_enabled` or `universal_credit_scan_enabled`) must be
enabled for the user and for the requested `type`.




## OpenAPI

````yaml POST /doc-scan
openapi: 3.0.1
info:
  title: Payroll API
  description: A full flagged payroll api provided by Teal
  version: 1.0.0
servers:
  - url: https://api.sandbox.goteal.co
    description: Sandbox server for experiments
  - url: https://api.goteal.co
    description: Production server
security:
  - ApiKeyAuth: []
  - MemberBearerAuth: []
paths:
  /doc-scan:
    post:
      summary: Submit previously uploaded documents for scanning and extraction
      description: |
        Uploading documents for doc scan is a three-step flow:
          1. Request upload slots with `PUT /doc-scan/presign`, providing each
             PDF file name (and optional external identifier). The response
             includes `presigned_url` and `path` values for every requested
             file.
          2. Upload the PDF content to every `presigned_url` using an HTTP
             `PUT` request with `Content-Type: application/octet-stream`.
          3. Call this endpoint with the `path` (and optional
             `external_document_id`) of every uploaded file so Teal can
             extract the document data.

        `type` (`p45`, `p60` or `universal_credit`) is required and tells
        Teal which document type to extract.

        Each `path` must start with `{client_name}/{user_id}/`. A maximum of
        12 files can be submitted at once and each file must be 10 MB or
        smaller. The uploaded files are deleted from storage after
        processing. The relevant scan flag (`p45_scan_enabled`,
        `p60_scan_enabled` or `universal_credit_scan_enabled`) must be
        enabled for the user and for the requested `type`.
      parameters:
        - $ref: '#/components/parameters/XAuthorisationId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/DocScanUploadRequest'
      responses:
        '200':
          description: OK — no files were extracted; see `errors` for details
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DocScanUploadResponse'
        '201':
          description: Created — document(s) extracted and saved
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DocScanUploadResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/UnauthorizedBearer'
        '403':
          description: Forbidden — the user has no valid authorisation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - BearerAuth: []
components:
  parameters:
    XAuthorisationId:
      name: x-teal-authorisation-id
      in: header
      required: false
      description: >-
        Optional authorisation ID to associate with this request. If not
        provided, the system will attempt to resolve a valid authorisation for
        the user automatically.
      schema:
        type: string
        format: uuid
        example: 7f3b8c2a-1d4e-4f6a-8b8c-9a0b1c2d3e4f
  schemas:
    DocScanUploadRequest:
      type: object
      required:
        - files
        - type
      properties:
        files:
          type: array
          description: Previously uploaded documents to extract.
          minItems: 1
          maxItems: 12
          items:
            $ref: '#/components/schemas/DocScanUploadRequestFile'
        type:
          type: string
          description: Target document type. Required.
          enum:
            - p45
            - p60
            - universal_credit
    DocScanUploadResponse:
      type: object
      required:
        - documents
        - errors
      properties:
        documents:
          type: array
          description: Successfully extracted documents
          items:
            $ref: '#/components/schemas/DocScanDocument'
        errors:
          type: array
          description: Files that failed extraction
          items:
            $ref: '#/components/schemas/DocScanError'
    Error:
      required:
        - errors
      type: object
      properties:
        errors:
          type: array
          items:
            type: string
          description: An array of messages describing the errors
          example:
            - The request is missing the required field `name`
    DocScanUploadRequestFile:
      type: object
      required:
        - path
      properties:
        path:
          type: string
          description: >-
            Storage path returned by the presign endpoint. Must start with
            `{client_name}/{user_id}/`.
          example: client/acct123/users/user456/p45.pdf
        external_document_id:
          type: string
          description: Optional identifier shown in the response documents when present.
          example: ext-p45-2024-05
    DocScanDocument:
      type: object
      required:
        - id
        - type
        - created_at
        - document_id
        - extract
        - probability
      properties:
        id:
          type: string
          format: uuid
          description: Unique doc scan extract identifier
          example: 95a0e70b-fe02-4f47-aef9-2efff279df71
        type:
          type: string
          description: The requested document type
          enum:
            - p45
            - p60
            - universal_credit
          example: p45
        created_at:
          $ref: '#/components/schemas/Date'
        document_id:
          type: string
          format: uuid
          description: ID of the linked raw document
        document_external_id:
          type: string
          description: External ID provided during upload, if any
          nullable: true
        document_filename:
          type: string
          description: File name of the uploaded document
          nullable: true
        extract:
          type: object
          description: >-
            Extracted fields for the document type (see DocScanP45Extract,
            DocScanP60Extract or DocScanUniversalCreditExtract)
          oneOf:
            - $ref: '#/components/schemas/DocScanP45Extract'
            - $ref: '#/components/schemas/DocScanP60Extract'
            - $ref: '#/components/schemas/DocScanUniversalCreditExtract'
        probability:
          type: number
          format: float
          description: Confidence score (0-1) of the extraction
          example: 0.95
        provenance:
          type: object
          description: >-
            Which pipeline produced the extract and the fraud-scan verdict on
            the source PDF. Omitted when no provenance was recorded.
          nullable: true
          required:
            - source
            - trust_score
          properties:
            source:
              type: string
              description: The extraction pipeline that produced this document
              enum:
                - DOC_SCAN
              example: DOC_SCAN
            trust_score:
              $ref: '#/components/schemas/TrustScore'
    DocScanError:
      type: object
      required:
        - error
      properties:
        file_name:
          type: string
          description: File name of the document that failed, if known
          nullable: true
          example: p45.pdf
        error:
          type: string
          description: Why the document failed extraction
          example: P45 could not be extracted
    UnauthorizedBarer:
      type: object
      properties:
        errors:
          type: array
          items:
            type: string
          description: An array of messages describing the errors
          example:
            - 'Not Authorization: Bearer <token> provided or wrong value'
    Date:
      type: string
      format: date-time
      example: '2019-05-17T00:00:00.000Z'
    DocScanP45Extract:
      type: object
      description: Fields extracted from a P45
      properties:
        employer_name:
          type: string
          nullable: true
          example: Acme Corporation
        paye_reference:
          type: string
          nullable: true
          example: 123/AB456
        employee_name:
          type: string
          nullable: true
          example: John Smith
        national_insurance_number:
          type: string
          nullable: true
          example: QQ123456C
        leave_date:
          type: string
          description: Date in YYYY-MM-DD format
          nullable: true
          example: '2024-05-31'
        tax_code:
          type: string
          nullable: true
          example: 1257L
        tax_year:
          type: string
          description: >-
            Start year of the UK tax year the leave date falls in (`2024` for
            2024-25). Derived from `leave_date`; `null` when the leave date is
            missing.
          nullable: true
          example: '2024'
        gross_pay:
          type: string
          description: Monetary value as a string with 2 decimals
          nullable: true
          example: '1500.00'
        income_tax:
          type: string
          description: Monetary value as a string with 2 decimals
          nullable: true
          example: '250.00'
    DocScanP60Extract:
      type: object
      description: Fields extracted from a P60
      properties:
        employer_name:
          type: string
          nullable: true
          example: Acme Corporation
        paye_reference:
          type: string
          nullable: true
          example: 123/AB456
        employee_name:
          type: string
          nullable: true
          example: John Smith
        national_insurance_number:
          type: string
          nullable: true
          example: QQ123456C
        tax_year:
          type: string
          description: >-
            Start year of the UK tax year (`2025` for 2025-26, the year ending 5
            April 2026).
          example: '2025'
        tax_code:
          type: string
          nullable: true
          example: 1257L
        gross_pay:
          type: string
          description: >-
            Total pay for the year across all employments, as a string with 2
            decimals
          example: '32000.00'
        income_tax:
          type: string
          description: >-
            Total tax for the year across all employments, as a string with 2
            decimals
          nullable: true
          example: '5000.00'
        employee_ni:
          type: string
          description: Monetary value as a string with 2 decimals
          nullable: true
          example: '2500.00'
    DocScanUniversalCreditExtract:
      type: object
      description: Fields extracted from a Universal Credit statement
      properties:
        claimant_name:
          type: string
          nullable: true
          example: John Smith
        monthly_amount:
          type: string
          description: Monetary value as a string with 2 decimals
          nullable: true
          example: '1200.00'
        assessment_period:
          type: string
          description: Assessment period in YYYY-MM-DD to YYYY-MM-DD format
          nullable: true
          example: 2024-05-06 to 2024-06-05
    TrustScore:
      type: string
      description: >-
        The document trust score assessment. Trust score will be present if the
        payroll data is coming from a payslip source
      enum:
        - Low
        - Medium
        - High
      example: High
  responses:
    BadRequest:
      description: Bad request if one of the required parameters is missing
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    UnauthorizedBearer:
      description: Unauthorized if the X-API-KEY is not provided or is wrong
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/UnauthorizedBarer'
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-KEY
    MemberBearerAuth:
      type: http
      scheme: bearer
      description: >-
        Bearer token for authentication. The token should be the one returned by
        the "/members/signin"
    BearerAuth:
      type: http
      scheme: bearer
      description: >-
        Bearer token for authentication. The token should be the one returned by
        the /user-tokens endpoint.

````

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