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

# Create Document Draft

> Create a document in DRAFT state without reserving a sequential.



## OpenAPI

````yaml /openapi.json post /documents/drafts
openapi: 3.1.0
info:
  title: Factio SRI API
  description: >-
    Plataforma headless, multi-tenant, API-first para emitir comprobantes
    electrónicos válidos ante el SRI de Ecuador.


    ## Autenticación


    Soporta tres métodos:

    - **JWT Bearer por Google OAuth**: `/auth/google/callback`

    - **JWT Bearer por email/password**: `/auth/login`

    - **API Key**: header `X-API-Key` con clave generada en `/auth/api-keys`


    ## Multi-tenant


    El aislamiento por tenant combina PostgreSQL RLS y validaciones explícitas
    en backend. El `tenant_id` se resuelve desde el contexto de autenticación.


    ## Flujo de Emisión


    1. `POST /documents` — reserva secuencial y encola el documento (responde
    202)

    2. `GET /documents/{id}` — consulta el estado actual por polling

    3. Cuando `status = AUTHORIZED`, el campo `authorization_number` contiene la
    clave de autorización del SRI


    Documentación completa en https://docs.factioapp.com
  version: 0.1.0
servers:
  - url: http://localhost:8000
    description: Local
  - url: https://api.factioapp.com
    description: Producción
  - url: https://api.staging.factioapp.com
    description: Sandbox (datos de prueba, sin efecto fiscal real)
security: []
paths:
  /documents/drafts:
    post:
      tags:
        - documents
      summary: Create Document Draft
      description: Create a document in DRAFT state without reserving a sequential.
      operationId: create_document_draft_documents_drafts_post
      parameters:
        - name: authorization
          in: header
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: Authorization
        - name: x-api-key
          in: header
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: X-Api-Key
        - name: x-tenant-id
          in: header
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: X-Tenant-Id
        - name: factio_access_token
          in: cookie
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: Factio Access Token
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/DocumentCreate'
      responses:
        '201':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DocumentResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    DocumentCreate:
      properties:
        issuer_id:
          type: string
          format: uuid
          title: Issuer Id
        establishment_id:
          type: string
          format: uuid
          title: Establishment Id
        emission_point_id:
          type: string
          format: uuid
          title: Emission Point Id
        document_type:
          $ref: '#/components/schemas/DocumentType'
        issue_date:
          type: string
          format: date
          title: Issue Date
        subtotal:
          anyOf:
            - type: number
              minimum: 0
            - type: string
              pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d{0,2}0*$
          title: Subtotal
          description: Subtotal before taxes and discounts
        total_discount:
          anyOf:
            - type: number
              minimum: 0
            - type: string
              pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d{0,2}0*$
          title: Total Discount
          description: Total discount amount
          default: '0.00'
        total_tax:
          anyOf:
            - type: number
              minimum: 0
            - type: string
              pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d{0,2}0*$
          title: Total Tax
          description: Total tax amount
        total:
          anyOf:
            - type: number
              minimum: 0
            - type: string
              pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d{0,2}0*$
          title: Total
          description: Total amount (subtotal - discount + tax)
        buyer_id_type:
          anyOf:
            - type: string
              maxLength: 10
            - type: 'null'
          title: Buyer Id Type
          description: Buyer identification type (RUC, cedula, passport, etc.)
        buyer_id:
          anyOf:
            - type: string
              maxLength: 20
            - type: 'null'
          title: Buyer Id
          description: Buyer identification number
        buyer_name:
          anyOf:
            - type: string
              maxLength: 300
            - type: 'null'
          title: Buyer Name
          description: Buyer name
        buyer_email:
          anyOf:
            - type: string
              maxLength: 255
            - type: 'null'
          title: Buyer Email
          description: Buyer email address
        buyer_address:
          anyOf:
            - type: string
              maxLength: 500
            - type: 'null'
          title: Buyer Address
          description: Buyer address
        modified_document_id:
          anyOf:
            - type: string
              format: uuid
            - type: 'null'
          title: Modified Document Id
          description: Original document referenced by this document
        modified_document_type:
          anyOf:
            - type: string
              maxLength: 2
            - type: 'null'
          title: Modified Document Type
          description: SRI type code of the modified document
        modified_document_number:
          anyOf:
            - type: string
              maxLength: 20
            - type: 'null'
          title: Modified Document Number
          description: Formatted document number of the modified document
        modified_document_issue_date:
          anyOf:
            - type: string
              format: date
            - type: 'null'
          title: Modified Document Issue Date
          description: Issue date of the modified document
        reason:
          anyOf:
            - type: string
              maxLength: 500
            - type: 'null'
          title: Reason
          description: Reason for the document, mainly required for credit notes
        idempotency_key:
          anyOf:
            - type: string
              maxLength: 255
            - type: 'null'
          title: Idempotency Key
          description: Client-provided idempotency key to prevent duplicate submissions
        lines:
          items:
            $ref: '#/components/schemas/DocumentLineCreate'
          type: array
          minItems: 1
          title: Lines
          description: Document line items
        taxes:
          items:
            $ref: '#/components/schemas/DocumentTaxCreate'
          type: array
          minItems: 1
          title: Taxes
          description: Document tax entries
        payments:
          items:
            $ref: '#/components/schemas/DocumentPaymentCreate'
          type: array
          title: Payments
          description: SRI payment method entries
        numeric_code:
          type: string
          maxLength: 8
          minLength: 8
          pattern: ^\d{8}$
          title: Numeric Code
          description: 8-digit numeric code for access key generation
      type: object
      required:
        - issuer_id
        - establishment_id
        - emission_point_id
        - document_type
        - issue_date
        - subtotal
        - total_tax
        - total
        - lines
        - taxes
        - numeric_code
      title: DocumentCreate
      description: Schema for creating a document (invoice, credit note, etc.).
    DocumentResponse:
      properties:
        id:
          type: string
          format: uuid
          title: Id
        tenant_id:
          type: string
          format: uuid
          title: Tenant Id
        issuer_id:
          type: string
          format: uuid
          title: Issuer Id
        establishment_id:
          type: string
          format: uuid
          title: Establishment Id
        emission_point_id:
          type: string
          format: uuid
          title: Emission Point Id
        document_type:
          $ref: '#/components/schemas/DocumentType'
        sequential:
          anyOf:
            - type: integer
            - type: 'null'
          title: Sequential
        access_key:
          anyOf:
            - type: string
            - type: 'null'
          title: Access Key
        status:
          $ref: '#/components/schemas/DocumentStatus'
        idempotency_key:
          anyOf:
            - type: string
            - type: 'null'
          title: Idempotency Key
        issue_date:
          type: string
          format: date
          title: Issue Date
        subtotal:
          type: string
          pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$
          title: Subtotal
        total_discount:
          type: string
          pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$
          title: Total Discount
        total_tax:
          type: string
          pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$
          title: Total Tax
        total:
          type: string
          pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$
          title: Total
        buyer_id_type:
          anyOf:
            - type: string
            - type: 'null'
          title: Buyer Id Type
        buyer_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Buyer Id
        buyer_name:
          anyOf:
            - type: string
            - type: 'null'
          title: Buyer Name
        buyer_email:
          anyOf:
            - type: string
            - type: 'null'
          title: Buyer Email
        buyer_address:
          anyOf:
            - type: string
            - type: 'null'
          title: Buyer Address
        modified_document_id:
          anyOf:
            - type: string
              format: uuid
            - type: 'null'
          title: Modified Document Id
        modified_document_type:
          anyOf:
            - type: string
            - type: 'null'
          title: Modified Document Type
        modified_document_number:
          anyOf:
            - type: string
            - type: 'null'
          title: Modified Document Number
        modified_document_issue_date:
          anyOf:
            - type: string
              format: date
            - type: 'null'
          title: Modified Document Issue Date
        reason:
          anyOf:
            - type: string
            - type: 'null'
          title: Reason
        authorization_number:
          anyOf:
            - type: string
            - type: 'null'
          title: Authorization Number
        authorization_date:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Authorization Date
        sri_environment:
          $ref: '#/components/schemas/SRIEnvironment'
        created_at:
          type: string
          format: date-time
          title: Created At
        updated_at:
          type: string
          format: date-time
          title: Updated At
        payments:
          items:
            $ref: '#/components/schemas/DocumentPaymentResponse'
          type: array
          title: Payments
          default: []
      type: object
      required:
        - id
        - tenant_id
        - issuer_id
        - establishment_id
        - emission_point_id
        - document_type
        - sequential
        - access_key
        - status
        - idempotency_key
        - issue_date
        - subtotal
        - total_discount
        - total_tax
        - total
        - buyer_id_type
        - buyer_id
        - buyer_name
        - buyer_email
        - buyer_address
        - modified_document_id
        - modified_document_type
        - modified_document_number
        - modified_document_issue_date
        - reason
        - authorization_number
        - authorization_date
        - sri_environment
        - created_at
        - updated_at
      title: DocumentResponse
      description: Schema for Document response — current state and authorization info.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    DocumentType:
      type: string
      enum:
        - '01'
        - '04'
        - '05'
        - '06'
        - '07'
      title: DocumentType
      description: Types of fiscal documents supported by the SRI.
    DocumentLineCreate:
      properties:
        line_number:
          type: integer
          minimum: 1
          title: Line Number
          description: Line number (1-based)
        description:
          type: string
          maxLength: 1000
          minLength: 1
          title: Description
          description: Product or service description
        main_code:
          anyOf:
            - type: string
              maxLength: 25
              minLength: 1
            - type: 'null'
          title: Main Code
          description: Catalog SRI codigoPrincipal; omitted for ad-hoc lines
        aux_code:
          anyOf:
            - type: string
              maxLength: 25
            - type: 'null'
          title: Aux Code
          description: Catalog SRI codigoAuxiliar
        quantity:
          anyOf:
            - type: number
              exclusiveMinimum: 0
            - type: string
              pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d{0,6}0*$
          title: Quantity
          description: Quantity
        unit_price:
          anyOf:
            - type: number
              minimum: 0
            - type: string
              pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d{0,6}0*$
          title: Unit Price
          description: Unit price
        discount:
          anyOf:
            - type: number
              minimum: 0
            - type: string
              pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d{0,2}0*$
          title: Discount
          description: Discount amount for this line
          default: '0.00'
        subtotal:
          anyOf:
            - type: number
              minimum: 0
            - type: string
              pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d{0,2}0*$
          title: Subtotal
          description: Line subtotal (quantity * unit_price - discount)
        tax_code:
          type: string
          title: Tax Code
          description: Tax code (e.g., '2' for IVA)
          default: '2'
        tax_rate_code:
          type: string
          title: Tax Rate Code
          description: Tax rate code (e.g., '0', '2', '4')
      type: object
      required:
        - line_number
        - description
        - quantity
        - unit_price
        - subtotal
        - tax_rate_code
      title: DocumentLineCreate
      description: Schema for creating a document line item.
    DocumentTaxCreate:
      properties:
        tax_code:
          type: string
          maxLength: 10
          minLength: 1
          title: Tax Code
          description: Tax code (e.g., '2' for IVA)
        tax_rate_code:
          type: string
          maxLength: 10
          minLength: 1
          title: Tax Rate Code
          description: Tax rate code (e.g., '2' for 12%, '0' for 0%)
        taxable_base:
          anyOf:
            - type: number
              minimum: 0
            - type: string
              pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d{0,2}0*$
          title: Taxable Base
          description: Taxable base amount
        rate:
          anyOf:
            - type: number
              maximum: 1
              minimum: 0
            - type: string
              pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d{0,4}0*$
          title: Rate
          description: Tax rate as decimal (e.g., 0.12 for 12%)
        tax_amount:
          anyOf:
            - type: number
              minimum: 0
            - type: string
              pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d{0,2}0*$
          title: Tax Amount
          description: Tax amount (taxable_base * rate)
      type: object
      required:
        - tax_code
        - tax_rate_code
        - taxable_base
        - rate
        - tax_amount
      title: DocumentTaxCreate
      description: Schema for creating a document tax entry.
    DocumentPaymentCreate:
      properties:
        line_number:
          type: integer
          minimum: 1
          title: Line Number
          description: Payment line number (1-based)
        payment_method_code:
          type: string
          maxLength: 2
          minLength: 2
          title: Payment Method Code
          description: SRI Tabla 24 payment method code
        total:
          anyOf:
            - type: number
              minimum: 0
            - type: string
              pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d{0,2}0*$
          title: Total
          description: Payment amount
        term:
          anyOf:
            - type: integer
              minimum: 0
            - type: 'null'
          title: Term
          description: Payment term length
        time_unit:
          anyOf:
            - type: string
              maxLength: 20
            - type: 'null'
          title: Time Unit
          description: Payment term unit
      type: object
      required:
        - line_number
        - payment_method_code
        - total
      title: DocumentPaymentCreate
      description: Schema for creating a document payment method entry.
    DocumentStatus:
      type: string
      enum:
        - DRAFT
        - VALIDATED
        - NUMBER_RESERVED
        - XML_GENERATED
        - SIGNED
        - RECEPTION_PENDING
        - SUBMITTED_TO_SRI
        - RECEIVED_BY_SRI
        - AUTHORIZATION_PENDING
        - AUTHORIZED
        - REJECTED
        - RECEPTION_RETRY_SCHEDULED
        - AUTHORIZATION_RETRY_SCHEDULED
        - RECEPTION_UNKNOWN
        - AUTHORIZATION_UNKNOWN
        - MANUAL_REVIEW_REQUIRED
        - FAILED_PERMANENT
        - CANCELLATION_REQUESTED
        - CANCELLED
        - VOIDED_BY_NC
      title: DocumentStatus
      description: Status values for document lifecycle.
    SRIEnvironment:
      type: string
      enum:
        - TEST
        - PRODUCTION
      title: SRIEnvironment
      description: SRI environment types.
    DocumentPaymentResponse:
      properties:
        id:
          type: string
          format: uuid
          title: Id
        line_number:
          type: integer
          title: Line Number
        payment_method_code:
          type: string
          title: Payment Method Code
        total:
          type: string
          pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$
          title: Total
        term:
          anyOf:
            - type: integer
            - type: 'null'
          title: Term
        time_unit:
          anyOf:
            - type: string
            - type: 'null'
          title: Time Unit
      type: object
      required:
        - id
        - line_number
        - payment_method_code
        - total
        - term
        - time_unit
      title: DocumentPaymentResponse
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError

````