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

> ## Agent Instructions
> Melso MCP: https://mcp.melso.ai/mcp (OAuth; one company per connection). Documentation-search MCP: https://docs.melso.ai/mcp; it does not act on customer accounts. Melso API: https://api.melso.ai/v1, with a company API key or a partner key (early access); invoicing is live and the other operations are marked beta.
>
> Use the live tool list and respect company membership. Ask the person to approve the exact invoice or tax return version in the signed-in app. Melso's professionals prepare and file included returns after approval; an AI assistant does not file. A prepared file or an approval is not evidence of filing: only the AEAT's reference and receipt are. Keep credentials out of chat and logs.

# Import a VAT book

> Imports the VAT book a company kept in another program: its received invoices as expenses, or its issued invoices as income.

> [!WARNING]
>
> **Beta.** Melso does not serve this operation yet, and its fields can still change. See [what is live](https://docs.melso.ai/api/overview.md#what-is-live).

Permission: `books:write`. Send an `Idempotency-Key` to retry safely. Send a row for each VAT rate of each invoice, as the libro registro de facturas recibidas or expedidas has them: rows with the same invoice number and counterparty NIF are one invoice. At most 50,000 rows: split a larger book by quarter.

Each invoice is created, skipped or refused. `skipped` are the invoices Melso already has, by counterparty NIF and invoice number, with the record that has them. `refused` names each row and why, such as `invalid_date`, `missing_number`, `vat_mismatch` or `conflicting_invoice` (the same invoice with another date or NIF); fix them in your program and import those rows again. The rest are created, and the tax returns count them.


## OpenAPI

````yaml api/openapi.yaml POST /companies/{company_id}/book-imports
openapi: 3.1.0
info:
  title: Melso API
  version: 1.0.0
  summary: Everything a Melso company does, from your own system.
  description: |
    The Melso API works in a Melso company: its invoices and customers, its
    books, its fiscal profile and digital certificate, its tax returns and its
    payroll.

    A company API key, which the company's owner creates in the Melso app,
    works in that one company. A partner key works in every company of its
    firm, with the company's `id` in the path. See
    [Authentication](/api/authentication).

    Invoicing is live. The other operations are in beta: each page says so,
    and their fields can still change until they are served.
  contact:
    name: Melso
    email: hello@melso.ai
    url: https://docs.melso.ai/api/overview
servers:
  - url: https://api.melso.ai/v1
security:
  - companyApiKey: []
  - partnerApiKey: []
tags:
  - name: Companies
    description: The companies the key works in.
  - name: Fiscal profile
    description: What decides which returns a company files.
  - name: Digital certificate
    description: >-
      The certificate Melso files with, which your system uploads or the owner
      uploads on a Melso page.
  - name: Customers
    description: The company's invoice customers.
  - name: Invoices
    description: >-
      Drafts, issuing through VERI*FACTU, corrections, voiding, payment and the
      PDF.
  - name: Expenses
    description: Received invoices and receipts, recorded in the company's books.
  - name: Income
    description: Invoices the company issued outside Melso, recorded in its books.
  - name: Documents
    description: Invoices and receipts that Melso reads and records for you.
  - name: VAT book imports
    description: The VAT books a company kept in another program, imported whole.
  - name: Tax returns
    description: >-
      The tax calendar, the returns Melso calculates, their approval and their
      receipts.
  - name: Payroll settings
    description: The company's labour data, and payslip simulations.
  - name: Employees
    description: Employees, their contract terms, modelo 145 and documents.
  - name: Contracts
    description: >-
      Contracts, extensions and conversions, and their communication to
      Contrat@.
  - name: Payroll runs
    description: Each month's payroll, from draft to approved and paid.
  - name: Payslips
    description: >-
      One employee's payslip in a month, its incidents and the official payroll
      files.
  - name: Social Security
    description: Liquidations with the TGSS, the SILTRA files and the TGSS's answers.
  - name: Leaves and strikes
    description: Sick leaves from the INSS's FIE files, and strikes.
paths:
  /companies/{company_id}/book-imports:
    parameters:
      - $ref: '#/components/parameters/CompanyId'
    post:
      tags:
        - VAT book imports
      summary: Import a VAT book
      description: >
        Imports the VAT book a company kept in another program: its received
        invoices as expenses, or its issued invoices as income.


        Permission: `books:write`. Send an `Idempotency-Key` to retry safely.
        Send a row for each VAT rate of each invoice, as the libro registro de
        facturas recibidas or expedidas has them: rows with the same invoice
        number and counterparty NIF are one invoice. At most 50,000 rows: split
        a larger book by quarter.


        Each invoice is created, skipped or refused. `skipped` are the invoices
        Melso already has, by counterparty NIF and invoice number, with the
        record that has them. `refused` names each row and why, such as
        `invalid_date`, `missing_number`, `vat_mismatch` or
        `conflicting_invoice` (the same invoice with another date or NIF); fix
        them in your program and import those rows again. The rest are created,
        and the tax returns count them.
      operationId: createBookImport
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/BookImportInput'
            example:
              book: received
              rows:
                - invoice_number: FD-2026-0418
                  date: '2026-10-21'
                  counterparty_tax_id: B12345674
                  counterparty_name: Papelería Delta S.L.
                  base: '200.00'
                  vat_rate: '21'
                  vat_amount: '42.00'
                  total: '242.00'
                - invoice_number: 2026/311
                  date: '2026-10-28'
                  counterparty_tax_id: 00000000T
                  counterparty_name: Lucía Martín Pérez
                  base: '450.00'
                  vat_rate: '21'
                  vat_amount: '94.50'
                  total: '544.50'
      responses:
        '201':
          description: The import, with each invoice created, skipped or refused.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BookImport'
              example:
                id: 9e8d7c6b-5a4f-4e3d-8c2b-1a0f9e8d7c6b
                book: received
                period:
                  from: '2026-10-21'
                  to: '2026-10-28'
                rows: 2
                created:
                  - row: 2
                    invoice_number: 2026/311
                    expense_id: 3d2c1b0a-9f8e-4d7c-8b6a-5f4e3d2c1b0a
                    income_id: null
                skipped:
                  - row: 1
                    invoice_number: FD-2026-0418
                    reason: duplicate
                    expense_id: 7b1e4c2a-9d3f-4e6a-8b5c-1f2e3d4c5b6a
                    income_id: null
                refused: []
                created_at: '2026-11-03T12:00:05Z'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          $ref: '#/components/responses/PaymentRequired'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
        '422':
          $ref: '#/components/responses/IdempotencyKeyReused'
        '429':
          $ref: '#/components/responses/RateLimited'
components:
  parameters:
    CompanyId:
      name: company_id
      in: path
      required: true
      description: >-
        The company's ID. Every company-scoped call works in exactly this
        company.
      schema:
        type: string
        format: uuid
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      description: >
        A unique key of yours, such as a UUID, that makes a retried create

        safe. For 24 hours a retry with the same key and body gets the first

        answer again, with `Idempotent-Replayed: true`. The same key with

        another body answers `422` `idempotency_key_reused`; while the first

        request runs, `409` `idempotency_key_in_use`. A `5xx` answer is not

        kept, so its retry runs again. See
        [Conventions](/api/conventions#idempotency).
      schema:
        type: string
        maxLength: 255
  schemas:
    BookImportInput:
      type: object
      required:
        - book
        - rows
      properties:
        book:
          type: string
          enum:
            - received
            - issued
          description: >-
            `received`: the libro de facturas recibidas, saved as expenses.
            `issued`: the libro de facturas expedidas, saved as income.
        rows:
          type: array
          minItems: 1
          maxItems: 50000
          items:
            $ref: '#/components/schemas/BookImportRow'
    BookImport:
      type: object
      required:
        - id
        - book
        - rows
        - created
        - skipped
        - refused
        - created_at
      properties:
        id:
          type: string
          format: uuid
        book:
          type: string
          enum:
            - received
            - issued
        period:
          type: object
          description: The dates of the first and the last invoice.
          properties:
            from:
              type: string
              format: date
            to:
              type: string
              format: date
        rows:
          type: integer
          description: The rows received.
        created:
          type: array
          items:
            $ref: '#/components/schemas/BookImportResult'
          description: The invoices recorded.
        skipped:
          type: array
          description: >-
            The invoices Melso already had, by counterparty NIF and invoice
            number.
          items:
            allOf:
              - $ref: '#/components/schemas/BookImportResult'
              - type: object
                properties:
                  reason:
                    type: string
                    const: duplicate
        refused:
          type: array
          description: >-
            The rows that cannot be recorded, and why. Nothing of their invoice
            was saved.
          items:
            type: object
            required:
              - row
              - code
              - reason
            properties:
              row:
                type: integer
              invoice_number:
                type:
                  - string
                  - 'null'
              code:
                type: string
                description: >-
                  Such as `invalid_date`, `invalid_amount`, `missing_number`,
                  `invalid_country`, `vat_mismatch`, `conflicting_invoice`,
                  `vat_treatment_conflict`, `mixed_treatments` or
                  `period_filed`.
              reason:
                type: string
                description: Why, for a person to read.
        created_at:
          type: string
          format: date-time
    BookImportRow:
      type: object
      required:
        - invoice_number
        - date
        - counterparty_tax_id
        - counterparty_name
        - base
        - vat_rate
        - vat_amount
        - total
      description: One VAT rate of one invoice, as the VAT book has it.
      properties:
        invoice_number:
          type: string
          description: >-
            The invoice's series and number; on the received book, the
            supplier's.
        date:
          type: string
          format: date
          description: The invoice's date, which places it in a return.
        operation_date:
          type: string
          format: date
          description: >-
            The day of the operation, when the book gives one other than the
            date.
        counterparty_tax_id:
          type: string
          description: >-
            The supplier's NIF on the received book, the customer's on the
            issued one.
        counterparty_name:
          type: string
        counterparty_country:
          type: string
          description: Two letters. `ES` unless the book or the tax ID says otherwise.
        base:
          $ref: '#/components/schemas/Decimal'
        vat_rate:
          $ref: '#/components/schemas/Decimal'
          description: >-
            The VAT rate as a percentage, `"0"` for an exempt or not subject
            line.
        vat_amount:
          $ref: '#/components/schemas/Decimal'
        total:
          $ref: '#/components/schemas/Decimal'
          description: The base plus the VAT of this row.
        vat_treatment:
          $ref: '#/components/schemas/BookVatTreatment'
        irpf_amount:
          $ref: '#/components/schemas/Decimal'
          description: The IRPF withheld on the invoice, when the book gives it.
        account:
          $ref: '#/components/schemas/PgcAccount'
          description: >-
            For a company, the account your program booked the invoice to, when
            the book gives it.
    BookImportResult:
      type: object
      required:
        - row
        - invoice_number
      properties:
        row:
          type: integer
          description: >-
            The row's position in `rows`, from 1. An invoice of several rows
            names its first.
        invoice_number:
          type: string
        expense_id:
          type:
            - string
            - 'null'
          format: uuid
          description: The expense created, or on a skipped row the one already there.
        income_id:
          type:
            - string
            - 'null'
          format: uuid
          description: The income created, or on a skipped row the one already there.
    Error:
      type: object
      required:
        - error
        - code
        - request_id
      properties:
        error:
          type: string
          description: What went wrong, for a person to read.
        code:
          type: string
          description: >-
            A stable code to branch on, such as `invoicing_not_ready` or
            `version_conflict`.
        request_id:
          type: string
          description: >-
            The same value as the `X-Request-Id` header. Quote it when you
            contact Melso.
        field:
          type: string
          description: The field, query parameter or header at fault, when there is one.
        next_action:
          type: string
          description: >-
            A stable hint of what to do next, such as `review_plan`, when the
            operation gives one.
        payment_url:
          type: string
          format: uri
          description: >-
            Where the company's owner pays its plan, on `plan_required` when its
            plan is unpaid.
        current_version:
          type: string
          description: On `version_changed`, the object's current `version`.
    Decimal:
      type: string
      pattern: ^-?[0-9]{1,10}(\.[0-9]{1,6})?$
      description: A decimal number as a string, such as `"21"` or `"0.5"`.
    BookVatTreatment:
      type: string
      enum:
        - taxable
        - exempt
        - reverse_charge
        - not_subject
      description: >-
        `taxable` by default. `exempt`, `reverse_charge` and `not_subject` lines
        carry rate `0` and no VAT.
    PgcAccount:
      type: string
      pattern: ^[67][0-9]{2,11}$
      description: >-
        An account of the Plan General de Contabilidad, or a subaccount the
        company keeps of one, up to 12 digits.
  responses:
    BadRequest:
      description: |
        The request is malformed or a field is invalid. Unknown body fields and
        query parameters are refused too, with `field` naming them where it can.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          examples:
            invalid_invoice:
              summary: A field the invoice cannot take
              value:
                error: vat_rate must be 21, 10, 4 or 0 (exempt)
                code: invalid_invoice
                next_action: review_request
                request_id: req_8f14e45fceea167a5a36dedd
            unknown_field:
              summary: A field the operation does not take
              value:
                error: Unknown field iban
                code: invalid_arguments
                field: iban
                request_id: req_8f14e45fceea167a5a36dedd
    Unauthorized:
      description: |
        The key is missing, revoked or invalid (`invalid_api_key`), or it is a
        test key, which Melso does not issue (`test_keys_unavailable`).
      headers:
        WWW-Authenticate:
          description: '`Bearer realm="api.melso.ai"` on `invalid_api_key`.'
          schema:
            type: string
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: The API key is missing, revoked or invalid
            code: invalid_api_key
            request_id: req_8f14e45fceea167a5a36dedd
    PaymentRequired:
      description: >
        The company's plan does not cover this write (`plan_required`): its plan

        is unpaid, and `payment_url` is where its owner pays it, or the plan's

        invoice allowance is used up. A self-employed person whose plan lacks
        Melso's

        tools gets `paid_manual_tools_required`. Reads keep working.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: >-
              invoices issue needs the company's plan, which is not paid: its
              records stay readable, and the owner pays the plan at
              https://app.melso.ai/setup?workspace_id=00000000-0000-4000-8000-000000000001.
            code: plan_required
            next_action: review_plan
            payment_url: >-
              https://app.melso.ai/setup?workspace_id=00000000-0000-4000-8000-000000000001
            request_id: req_8f14e45fceea167a5a36dedd
    Forbidden:
      description: >
        Refused in this company: the operation is not available in it, such as

        invoices before its VERI*FACTU set-up (`tool_unavailable`); a

        self-employed person's setup in Melso is pending
        (`onboarding_required`); or the

        key's creator lacks the role the operation needs, such as the owner's

        for issuing (`forbidden`).
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: invoices is not available in this company
            code: tool_unavailable
            next_action: check_company_and_access
            request_id: req_8f14e45fceea167a5a36dedd
    NotFound:
      description: >-
        No such object in this company, or `company_id` is not the key's
        company.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: invoice not found
            code: not_found
            next_action: refresh_record
            request_id: req_8f14e45fceea167a5a36dedd
    Conflict:
      description: |
        The object changed or is not in a state that allows this: read it again
        and decide. Also the first request with this `Idempotency-Key` still
        running (`idempotency_key_in_use`, with `Retry-After: 1`).
      headers:
        Retry-After:
          description: Seconds to wait, on `idempotency_key_in_use`.
          schema:
            type: integer
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: 'invoice changed: review the current draft'
            code: version_conflict
            field: expected_version
            next_action: refresh_and_request_authorization
            request_id: req_8f14e45fceea167a5a36dedd
    IdempotencyKeyReused:
      description: >-
        This `Idempotency-Key` was sent before with another request. Use a new
        key.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: 'This Idempotency-Key was sent with another request: use a new key'
            code: idempotency_key_reused
            field: Idempotency-Key
            request_id: req_8f14e45fceea167a5a36dedd
    RateLimited:
      description: >-
        The key made more than 600 requests in a minute. Wait `Retry-After`
        seconds.
      headers:
        Retry-After:
          description: Seconds to wait, `60`.
          schema:
            type: integer
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: 'Too many requests: a key makes at most 600 a minute'
            code: rate_limited
            request_id: req_8f14e45fceea167a5a36dedd
  securitySchemes:
    companyApiKey:
      type: http
      scheme: bearer
      description: |
        A company API key, `mk_live_…`, that the company's owner creates in the
        Melso app under Settings, Connect your AI, API keys. It works in that
        one company with the owner's authority. Test keys (`mk_test_…`) are not
        issued. Keep the key on your servers. See
        [Authentication](/api/authentication).
    partnerApiKey:
      type: http
      scheme: bearer
      description: >
        A partner key of your firm, which the firm's owner or an admin creates
        in

        Melso under Settings, Developers, with the permissions it needs. It
        works in

        every company of the firm: put the company's `id` in the path. A company

        that is not your firm's answers `404`. Early access. See

        [Acting for your companies](/api/partner/acting-for-companies).

````

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