openapi: 3.1.0
info:
  title: Melso Partner API
  version: 0.3.0-early-access
  summary: Open Melso companies for your customers and follow every change.
  description: |
    Early access. Your platform is a firm in Melso, and each customer business
    you serve is a company of that firm. The Partner API has only what is
    partner-specific: open the Melso account of a business that has its NIF,
    ask Melso's team to incorporate an S.L. or register a self-employed
    person, and receive webhooks for every change. Everything else, from the
    fiscal profile to books, taxes and payroll, is the Melso API, called with
    your partner key and the company's `id`. The firm's owner or an admin
    creates partner keys in Settings › Developers.
  contact:
    name: Melso
    email: hello@melso.ai
    url: https://docs.melso.ai/api/partner/overview
servers:
  - url: https://api.melso.ai/v1
security:
  - partnerApiKey: []
tags:
  - name: Companies
    description: The Melso account of a business that already has its NIF.
  - name: Incorporations
    description: Melso's team incorporates a new S.L. or registers a new self-employed person.
  - name: Webhooks
    description: Endpoints of yours that receive an event when something changes in a company of your firm.
  - name: Events
    description: Everything that changed in your firm's companies in the last 30 days, to replay and reconcile.
x-tagGroups:
  - name: Partner API
    tags: [Companies, Incorporations, Webhooks, Events]

paths:
  /partner/companies:
    post:
      operationId: createPartnerCompany
      summary: Create a company
      description: |
        Creates the Melso account of a business that already has its NIF: a self-employed person or a company.

        Permission: `companies:write`. Send an `Idempotency-Key`. The company is `active` at once, and Melso's professionals start on it. Send its fiscal details in `fiscal_profile` now, or later with the Melso API's Update the fiscal profile. The company is created even when a fiscal field is refused: `errors` names each one. A NIF another company of your firm already has answers `409` `conflict`.

        To create a business that does not exist yet, a new S.L. or a new self-employed registration, use Incorporate an S.L. or Register a self-employed person instead.
      tags: [Companies]
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/CompanyInput'}
            example:
              kind: company
              name: Brasa Norte S.L.
              company_form: sl
              external_id: ws_48213
              tax_id: B00000000
              email: admin@brasanorte.example
              fiscal_profile:
                address: Carrer de Pallars 100
                postal_code: '08018'
                activity_type: empresarial
                iae_code: '671.4'
                vat_regime: general
      responses:
        '201':
          description: The company, with the saved fiscal profile and any refused field.
          content:
            application/json:
              schema: {$ref: '#/components/schemas/CompanyCreated'}
              example:
                company:
                  id: 1b2c3d4e-5f6a-4b7c-8d9e-0f1a2b3c4d5e
                  external_id: ws_48213
                  kind: company
                  name: Brasa Norte S.L.
                  tax_id: B00000000
                  email: admin@brasanorte.example
                  phone: null
                  incorporation_id: null
                  status: active
                  missing: [certificate]
                  certificate: missing
                  created_at: '2026-12-01T09:30:00Z'
                  updated_at: '2026-12-01T09:30:00Z'
                errors: []
        '400': {$ref: '#/components/responses/BadRequest'}
        '401': {$ref: '#/components/responses/Unauthorized'}
        '403': {$ref: '#/components/responses/Forbidden'}
        '409': {$ref: '#/components/responses/Conflict'}
        '422': {$ref: '#/components/responses/IdempotencyKeyReused'}
        '429': {$ref: '#/components/responses/RateLimited'}
  /partner/incorporations/sl:
    post:
      operationId: createPartnerSlIncorporation
      summary: Incorporate an S.L.
      description: |
        Asks Melso's team to incorporate a new S.L., with the owner as its sole partner.

        Permission: `incorporations:write`. Send an `Idempotency-Key`. The answer is `202` with the incorporation, `requested`. Melso's team writes to `owner.email` for what needs the owner: the name certificate, the bank deposit of the share capital and signing the deed before a notary. Once the business has its NIF, the incorporation is `completed` and `company_id` names its new company: from then on, call the Melso API with it. Follow it with Get an incorporation.

        A business that already has its NIF does not need this: use Create a company.
      tags: [Incorporations]
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/SlIncorporationInput'}
            example:
              external_id: ws_48215
              owner: {name: Lucía Martín Pérez, email: lucia@example.com, tax_id: 00000000T}
              activity: Restaurante de cocina mediterránea
              proposed_names: [Brasa Sur, Brasa Sur Mediterránea]
              share_capital: '3000.00'
              postal_code: '08018'
      responses:
        '202':
          description: The incorporation, `requested`.
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Incorporation'}
              example:
                id: 7c6b5a4d-3e2f-4a1b-9c8d-7e6f5a4b3c2d
                external_id: ws_48215
                type: sl
                status: requested
                owner: {name: Lucía Martín Pérez, email: lucia@example.com, tax_id: 00000000T}
                activity: Restaurante de cocina mediterránea
                proposed_names: [Brasa Sur, Brasa Sur Mediterránea]
                company_id: null
                created_at: '2026-12-01T09:30:00Z'
                updated_at: '2026-12-01T09:30:00Z'
                completed_at: null
        '400': {$ref: '#/components/responses/BadRequest'}
        '401': {$ref: '#/components/responses/Unauthorized'}
        '403': {$ref: '#/components/responses/Forbidden'}
        '409': {$ref: '#/components/responses/Conflict'}
        '422': {$ref: '#/components/responses/IdempotencyKeyReused'}
        '429': {$ref: '#/components/responses/RateLimited'}
  /partner/incorporations/autonomo:
    post:
      operationId: createPartnerAutonomoRegistration
      summary: Register a self-employed person
      description: |
        Asks Melso's team to register the owner as self-employed, with the AEAT and the Social Security.

        Permission: `incorporations:write`. Send an `Idempotency-Key`. The answer is `202` with the incorporation, `requested`. Melso's team writes to `owner.email` for what needs the owner, such as their digital certificate to file the alta. Once the business has its NIF, the incorporation is `completed` and `company_id` names its new company: from then on, call the Melso API with it. Follow it with Get an incorporation.

        A business that already has its NIF does not need this: use Create a company.
      tags: [Incorporations]
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/AutonomoRegistrationInput'}
            example:
              external_id: ws_48215
              owner: {name: Lucía Martín Pérez, email: lucia@example.com, tax_id: 00000000T}
              activity: Restaurante de cocina mediterránea
              start_date: '2026-12-15'
              postal_code: '08018'
      responses:
        '202':
          description: The incorporation, `requested`.
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Incorporation'}
              example:
                id: 7c6b5a4d-3e2f-4a1b-9c8d-7e6f5a4b3c2d
                external_id: ws_48215
                type: autonomo
                status: requested
                owner: {name: Lucía Martín Pérez, email: lucia@example.com, tax_id: 00000000T}
                activity: Restaurante de cocina mediterránea
                company_id: null
                created_at: '2026-12-01T09:30:00Z'
                updated_at: '2026-12-01T09:30:00Z'
                completed_at: null
        '400': {$ref: '#/components/responses/BadRequest'}
        '401': {$ref: '#/components/responses/Unauthorized'}
        '403': {$ref: '#/components/responses/Forbidden'}
        '409': {$ref: '#/components/responses/Conflict'}
        '422': {$ref: '#/components/responses/IdempotencyKeyReused'}
        '429': {$ref: '#/components/responses/RateLimited'}
  /partner/incorporations:
    get:
      operationId: listPartnerIncorporations
      summary: List incorporations
      description: |
        Lists your firm's incorporations and self-employed registrations, newest first.

        Permission: `incorporations:read`.
      tags: [Incorporations]
      parameters:
        - {name: type, in: query, schema: {type: string, enum: [sl, autonomo]}}
        - {name: external_id, in: query, schema: {type: string}, description: Exact match on your own ID.}
        - {name: status, in: query, schema: {type: string, enum: [requested, in_progress, completed, cancelled]}}
        - $ref: '#/components/parameters/Limit'
        - $ref: '#/components/parameters/Cursor'
      responses:
        '200':
          description: A page of incorporations.
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/Page'
                  - properties:
                      data: {type: array, items: {$ref: '#/components/schemas/Incorporation'}}
        '401': {$ref: '#/components/responses/Unauthorized'}
        '403': {$ref: '#/components/responses/Forbidden'}
        '429': {$ref: '#/components/responses/RateLimited'}
  /partner/incorporations/{incorporation_id}:
    parameters:
      - $ref: '#/components/parameters/IncorporationId'
    get:
      operationId: getPartnerIncorporation
      summary: Get an incorporation
      description: |
        Returns one incorporation or registration and, once `completed`, the `company_id` of its company.

        Permission: `incorporations:read`.
      tags: [Incorporations]
      responses:
        '200':
          description: The incorporation.
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Incorporation'}
              example:
                id: 7c6b5a4d-3e2f-4a1b-9c8d-7e6f5a4b3c2d
                external_id: ws_48215
                type: sl
                status: completed
                owner: {name: Lucía Martín Pérez, email: lucia@example.com, tax_id: 00000000T}
                activity: Restaurante de cocina mediterránea
                proposed_names: [Brasa Sur, Brasa Sur Mediterránea]
                company_id: 2c3d4e5f-6a7b-4c8d-9e0f-1a2b3c4d5e6f
                created_at: '2026-12-01T09:30:00Z'
                updated_at: '2026-12-09T12:00:00Z'
                completed_at: '2026-12-09T12:00:00Z'
        '401': {$ref: '#/components/responses/Unauthorized'}
        '403': {$ref: '#/components/responses/Forbidden'}
        '404': {$ref: '#/components/responses/NotFound'}
        '429': {$ref: '#/components/responses/RateLimited'}

  /partner/incorporations/{incorporation_id}/identity-verifications:
    parameters:
      - $ref: '#/components/parameters/IncorporationId'
    post:
      operationId: createPartnerIdentityVerification
      x-melso-availability: beta
      summary: Create an identity verification
      description: |
        Starts the identity verification of one person of an incorporation, and returns the link where they show an ID document and take a selfie.

        The person is the owner of a self-employed registration, or a partner of an S.L.

        Permission: `incorporations:write`. The link works once and for 24 hours. A new verification for the same person cancels the earlier one. See [Identity verification](/api/partner/guides/identity).
      tags: [Incorporations]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [tax_id]
              properties:
                tax_id: {type: string, description: The DNI or NIE of a person listed in the incorporation's `identity_verifications`.}
            example: {tax_id: 00000000T}
      responses:
        '201':
          description: The verification, with its link.
          content:
            application/json:
              schema: {$ref: '#/components/schemas/IdentityVerification'}
              example:
                id: iv_5e2a9c1d
                tax_id: 00000000T
                name: Lucía Martín Pérez
                status: not_started
                url: https://melso.ai/verify#token
                expires_at: '2026-12-02T09:30:00Z'
        '400': {$ref: '#/components/responses/BadRequest'}
        '401': {$ref: '#/components/responses/Unauthorized'}
        '403': {$ref: '#/components/responses/Forbidden'}
        '404': {$ref: '#/components/responses/NotFound'}
        '409': {$ref: '#/components/responses/Conflict'}
        '429': {$ref: '#/components/responses/RateLimited'}
  /partner/webhook-endpoints:
    post:
      operationId: createPartnerWebhookEndpoint
      x-melso-availability: beta
      summary: Create a webhook endpoint
      description: |
        Adds an endpoint that receives the events of every company of your firm.

        Permission: `webhooks:write`. `secret` appears only in this answer: store it to verify the `Melso-Signature` header. See [Webhooks](/api/partner/webhooks).
      tags: [Webhooks]
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/WebhookEndpointInput'}
            example:
              url: https://example.com/melso/webhooks
              events: ['incorporation.*', company.ready, 'tax_return.*']
              description: Production
      responses:
        '201':
          description: The endpoint, with its secret.
          content:
            application/json:
              schema: {$ref: '#/components/schemas/WebhookEndpointCreated'}
              example:
                id: we_3f9a1c2b
                url: https://example.com/melso/webhooks
                events: ['incorporation.*', company.ready, 'tax_return.*']
                description: Production
                status: enabled
                secret: whsec_7d2f0c4e9b1a
                created_at: '2026-12-01T09:30:00Z'
        '400': {$ref: '#/components/responses/BadRequest'}
        '401': {$ref: '#/components/responses/Unauthorized'}
        '403': {$ref: '#/components/responses/Forbidden'}
        '429': {$ref: '#/components/responses/RateLimited'}
    get:
      operationId: listPartnerWebhookEndpoints
      x-melso-availability: beta
      summary: List webhook endpoints
      description: |
        Lists your firm's webhook endpoints. Secrets are never returned again.

        Permission: `webhooks:read`.
      tags: [Webhooks]
      responses:
        '200':
          description: Your endpoints.
          content:
            application/json:
              schema:
                type: object
                required: [data]
                properties:
                  data: {type: array, items: {$ref: '#/components/schemas/WebhookEndpoint'}}
        '401': {$ref: '#/components/responses/Unauthorized'}
        '403': {$ref: '#/components/responses/Forbidden'}
        '429': {$ref: '#/components/responses/RateLimited'}
  /partner/webhook-endpoints/{endpoint_id}:
    parameters:
      - $ref: '#/components/parameters/EndpointId'
    patch:
      operationId: updatePartnerWebhookEndpoint
      x-melso-availability: beta
      summary: Update a webhook endpoint
      description: |
        Changes an endpoint's URL, events or description, or turns it off with `status: disabled` and back on with `enabled`. Only the fields you send change.

        Permission: `webhooks:write`.
      tags: [Webhooks]
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/WebhookEndpointUpdate'}
            example: {events: ['tax_return.*'], status: enabled}
      responses:
        '200':
          description: The endpoint.
          content:
            application/json:
              schema: {$ref: '#/components/schemas/WebhookEndpoint'}
        '400': {$ref: '#/components/responses/BadRequest'}
        '401': {$ref: '#/components/responses/Unauthorized'}
        '403': {$ref: '#/components/responses/Forbidden'}
        '404': {$ref: '#/components/responses/NotFound'}
        '429': {$ref: '#/components/responses/RateLimited'}
    delete:
      operationId: deletePartnerWebhookEndpoint
      x-melso-availability: beta
      summary: Delete a webhook endpoint
      description: |
        Deletes an endpoint. Events not yet delivered to it are dropped; List events still returns them.

        Permission: `webhooks:write`.
      tags: [Webhooks]
      responses:
        '204': {description: Deleted.}
        '401': {$ref: '#/components/responses/Unauthorized'}
        '403': {$ref: '#/components/responses/Forbidden'}
        '404': {$ref: '#/components/responses/NotFound'}
        '429': {$ref: '#/components/responses/RateLimited'}
  /partner/webhook-endpoints/{endpoint_id}/rotate-secret:
    parameters:
      - $ref: '#/components/parameters/EndpointId'
    post:
      operationId: rotatePartnerWebhookSecret
      x-melso-availability: beta
      summary: Rotate a webhook secret
      description: |
        Issues a new secret. For 24 hours Melso signs with both, so `Melso-Signature` carries two `v1` values: switch your server over within that window.

        Permission: `webhooks:write`.
      tags: [Webhooks]
      responses:
        '200':
          description: The endpoint, with its new secret.
          content:
            application/json:
              schema: {$ref: '#/components/schemas/WebhookEndpointCreated'}
        '401': {$ref: '#/components/responses/Unauthorized'}
        '403': {$ref: '#/components/responses/Forbidden'}
        '404': {$ref: '#/components/responses/NotFound'}
        '429': {$ref: '#/components/responses/RateLimited'}
  /partner/webhook-endpoints/{endpoint_id}/test:
    parameters:
      - $ref: '#/components/parameters/EndpointId'
    post:
      operationId: sendPartnerTestEvent
      x-melso-availability: beta
      summary: Send a test event
      description: |
        Sends a signed `test.ping` event to the endpoint at once and answers with what your server replied.

        Permission: `webhooks:write`.
      tags: [Webhooks]
      responses:
        '200':
          description: The delivery.
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Delivery'}
              example: {event_id: evt_0a1b2c3d, status: succeeded, response_code: 200, latency_ms: 142}
        '401': {$ref: '#/components/responses/Unauthorized'}
        '403': {$ref: '#/components/responses/Forbidden'}
        '404': {$ref: '#/components/responses/NotFound'}
        '429': {$ref: '#/components/responses/RateLimited'}
  /partner/events:
    get:
      operationId: listPartnerEvents
      x-melso-availability: beta
      summary: List events
      description: |
        Lists the events of your firm's companies from the last 30 days, newest first: the same objects webhooks deliver. Use it to replay what an outage missed, or instead of webhooks.

        Permission: `webhooks:read`.
      tags: [Events]
      parameters:
        - {name: type, in: query, schema: {type: string}, description: 'An event type, or a family such as `tax_return.*`.'}
        - {name: company_id, in: query, schema: {type: string, format: uuid}}
        - {name: created_after, in: query, schema: {type: string, format: date-time}}
        - $ref: '#/components/parameters/Limit'
        - $ref: '#/components/parameters/Cursor'
      responses:
        '200':
          description: A page of events.
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/Page'
                  - properties:
                      data: {type: array, items: {$ref: '#/components/schemas/Event'}}
        '401': {$ref: '#/components/responses/Unauthorized'}
        '403': {$ref: '#/components/responses/Forbidden'}
        '429': {$ref: '#/components/responses/RateLimited'}

components:
  securitySchemes:
    partnerApiKey:
      type: http
      scheme: bearer
      description: |
        A partner key of your firm, `mk_live_…`, which reaches every company of
        the firm. Each key carries the permissions chosen when it was created.
        Keep it on your servers. See [Authentication](/api/partner/authentication).

  parameters:
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      description: A unique key of yours, up to 255 characters. A retry with the same key and body gets the first answer again for 24 hours.
      schema: {type: string, maxLength: 255}
    IncorporationId:
      name: incorporation_id
      in: path
      required: true
      schema: {type: string, format: uuid}
    EndpointId:
      name: endpoint_id
      in: path
      required: true
      schema: {type: string}
    Limit:
      name: limit
      in: query
      schema: {type: integer, minimum: 1, maximum: 200, default: 50}
    Cursor:
      name: cursor
      in: query
      description: The `next_cursor` of the previous page.
      schema: {type: string}

  responses:
    BadRequest:
      description: The request is malformed or a field is invalid; `field` names it.
      content:
        application/json:
          schema: {$ref: '#/components/schemas/Error'}
    Unauthorized:
      description: The key is missing, revoked or invalid.
      content:
        application/json:
          schema: {$ref: '#/components/schemas/Error'}
    Forbidden:
      description: The key lacks the permission named in `permission`.
      content:
        application/json:
          schema: {$ref: '#/components/schemas/Error'}
    NotFound:
      description: No such incorporation in your firm.
      content:
        application/json:
          schema: {$ref: '#/components/schemas/Error'}
    Conflict:
      description: A conflict, such as a NIF already in your firm or a changed `version`. Read again and retry.
      content:
        application/json:
          schema: {$ref: '#/components/schemas/Error'}
    IdempotencyKeyReused:
      description: This `Idempotency-Key` was sent with another request.
      content:
        application/json:
          schema: {$ref: '#/components/schemas/Error'}
    RateLimited:
      description: Over 600 requests a minute for this key. Wait `Retry-After` seconds.
      content:
        application/json:
          schema: {$ref: '#/components/schemas/Error'}

  schemas:
    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.}
        field: {type: string, description: The field at fault, when there is one.}
        permission: {type: string, description: 'With `missing_permission`, the permission the key needs.'}
        request_id: {type: string}
    Page:
      type: object
      required: [data, has_more, next_cursor]
      properties:
        data: {type: array, items: {}}
        has_more: {type: boolean}
        next_cursor: {type: [string, 'null']}
    Owner:
      type: object
      required: [name, email, tax_id]
      additionalProperties: false
      properties:
        name: {type: string, description: 'Full name, as on the DNI or NIE.'}
        email: {type: string, format: email, description: Melso's team writes here for what needs the owner.}
        tax_id: {type: string, description: The owner's DNI or NIE.}
        phone: {type: string}
    CompanyInput:
      type: object
      required: [kind, name]
      additionalProperties: false
      properties:
        kind:
          type: string
          enum: [freelancer, company]
          description: '`freelancer` for a self-employed person (DNI or NIE), `company` for a company (CIF). Fixed once created.'
        name: {type: string, description: The self-employed person's full name, or the company's name.}
        external_id: {type: string, maxLength: 200, description: Your own ID for this customer, unique in your firm.}
        company_form:
          type: string
          enum: [sl, slu, slp, sa, cooperativa, comunidad_bienes, sociedad_civil]
        tax_id: {type: string, description: 'The NIF: a DNI or NIE for a freelancer, a CIF for a company.'}
        email: {type: string, format: email, description: The business's contact. Melso does not write to it.}
        phone: {type: string}
        fiscal_profile: {$ref: '#/components/schemas/FiscalProfileInput'}
    Company:
      type: object
      required: [id, kind, name, status, missing, certificate, created_at, updated_at]
      properties:
        id: {type: string, format: uuid}
        external_id: {type: [string, 'null']}
        kind: {type: string, enum: [freelancer, company]}
        name: {type: string}
        tax_id: {type: [string, 'null']}
        email: {type: [string, 'null']}
        phone: {type: [string, 'null']}
        incorporation_id: {type: [string, 'null'], format: uuid, description: The incorporation that created it, when Melso incorporated or registered it.}
        status:
          type: string
          enum: [active, archived]
          description: '`active` while Melso works on it, `archived` once you archived it.'
        missing:
          type: array
          items: {type: string}
          description: 'What Melso still needs before it can do the taxes: `tax_territory`, `activity_type`, `registration_status` (self-employed), `tax_id`, `legal_name`, `vat_sii`, `vat_redeme`, `is_large_company` (company) and `certificate`. Empty when the company is ready. See [Onboard an existing business](/api/partner/guides/existing-business#2-complete-the-fiscal-profile).'
        certificate: {type: string, enum: [missing, valid, expiring, expired]}
        created_at: {type: string, format: date-time}
        updated_at: {type: string, format: date-time}
    CompanyCreated:
      type: object
      required: [company, errors]
      properties:
        company: {$ref: '#/components/schemas/Company'}
        fiscal_profile: {$ref: '#/components/schemas/FiscalProfile'}
        errors: {type: array, items: {$ref: '#/components/schemas/FieldError'}}
    FieldError:
      type: object
      required: [field, error]
      properties:
        field: {type: string}
        error: {type: string}
    Activity:
      type: object
      required: [iae_code]
      additionalProperties: false
      properties:
        id: {type: string, description: 'The saved activity''s ID, from a read. Omit it to add an activity.'}
        iae_code: {type: string, description: 'Its IAE heading, such as `659.9` or `843.1`.'}
        activity_type: {type: string, enum: [profesional, empresarial], description: 'A company''s activities are always `empresarial`.'}
        description: {type: string, description: What the activity is.}
        vat_regime:
          type: [string, 'null']
          enum: [general, recargo_equivalencia, simplificado, reagp, exento, igic_general, igic_simplificado, igic_repep, ipsi, '', null]
          description: 'Only when it differs from the main activity''s, such as `recargo_equivalencia` for a shop. Empty follows the main one.'
        started_on: {type: string, format: date, description: Its registration date, when known.}
        ended_on: {type: [string, 'null'], format: date, description: 'Its deregistration date, once it has ended.'}
    FiscalProfile:
      type: object
      properties:
        tax_id: {type: string, description: 'The NIF: a DNI, NIE or CIF. Its control character is checked.'}
        legal_name: {type: string, description: 'The full name on the DNI or NIE, or the company''s registered name.'}
        trade_name: {type: string, description: The name the business trades under, when different.}
        address: {type: string, description: 'Fiscal address: street, number, floor.'}
        postal_code: {type: string, description: Five digits. Also sets the province and the tax territory.}
        city: {type: string, description: Municipality.}
        province: {type: string, description: Normally deduced from the postal code.}
        tax_territory: {type: string, enum: [comun, alava, bizkaia, gipuzkoa, navarra, canarias, ceuta, melilla], description: Normally deduced from the postal code. Send it only to correct that.}
        activity_type: {type: string, enum: [profesional, empresarial], description: 'A freelancer''s main activity. A company''s is always `empresarial`.'}
        activity_description: {type: string, description: What the business does.}
        iae_code: {type: string, description: 'The main IAE heading, such as `671.4` for a restaurant or `673.2` for a bar.'}
        activities:
          type: array
          items: {$ref: '#/components/schemas/Activity'}
          description: 'The other activities beside the main one, one per other IAE heading in the census (modelo 036). Sending it replaces the list: send every other activity, each saved one with its `id`. Removing one that has invoices, income or expenses is refused; set its `ended_on` instead.'
        client_types:
          type: array
          items: {type: string, enum: [es_business, es_individual, eu_business, non_eu_business]}
          description: 'Who the business invoices, every kind that applies. Sending it replaces the list. Without `eu_business`, `eu_operator` is saved as `false`.'
        eu_operator: {type: boolean, description: Registered as an intra-community operator (ROI).}
        vat_regime:
          type: string
          enum: [general, recargo_equivalencia, simplificado, reagp, exento, igic_general, igic_simplificado, igic_repep, ipsi]
          description: 'Defaults to `general`, IGIC in the Canary Islands and IPSI in Ceuta and Melilla.'
        vat_sii: {type: boolean, description: 'Keeps its VAT books in the AEAT''s SII, compulsory for large companies.'}
        vat_redeme: {type: boolean, description: 'In the monthly VAT refund register (REDEME), so it files VAT monthly.'}
        is_large_company: {type: boolean, description: 'Volume of operations over 6,010,121.04 euros last year: VAT and withholdings are filed monthly.'}
        irpf_method: {type: string, enum: [directa_simplificada, directa_normal, modulos], default: directa_simplificada, description: Freelancers only.}
        irpf_retention_rate: {type: number, minimum: 0, maximum: 100, description: 'Income tax withheld on a freelancer''s invoices, in percent. Defaults to 15 for a professional. Freelancers only.'}
        registration_status: {type: string, enum: [alta, pendiente], description: 'Freelancers only: `alta` when already registered as self-employed.'}
        registered_on: {type: string, description: 'When the freelancer registered: `YYYY-MM`, or `YYYY-MM-DD` when the day is known.'}
        invoice_series: {type: string, description: Invoice series prefix.}
        next_invoice_number: {type: integer, minimum: 1, description: 'The number the next invoice takes, continuing the business''s own numbering.'}
        iban: {type: string, description: The account invoices are collected in. Masked when read.}
    FiscalProfileInput:
      allOf:
        - $ref: '#/components/schemas/FiscalProfile'
        - type: object
          properties:
            clear: {type: array, items: {type: string}, description: Names of fields to empty.}
    SlIncorporationInput:
      type: object
      required: [owner, activity]
      additionalProperties: false
      properties:
        external_id: {type: string, maxLength: 200, description: Your own ID for this customer, unique in your firm.}
        owner: {$ref: '#/components/schemas/Owner'}
        activity: {type: string, description: 'What the company will do, in a sentence. Melso picks the IAE heading from it.'}
        proposed_names:
          type: array
          minItems: 1
          maxItems: 5
          items: {type: string}
          description: Up to five names, in order of preference, for the name certificate of the Registro Mercantil Central.
        share_capital: {type: string, description: 'The share capital in euros, such as `"3000.00"`. At least `"1.00"`.'}
        postal_code: {type: string, description: The postal code of the registered office. Sets its tax territory.}
    AutonomoRegistrationInput:
      type: object
      required: [owner, activity]
      additionalProperties: false
      properties:
        external_id: {type: string, maxLength: 200, description: Your own ID for this customer, unique in your firm.}
        owner: {$ref: '#/components/schemas/Owner'}
        activity: {type: string, description: 'What the person will do, in a sentence. Melso picks the IAE heading from it.'}
        start_date: {type: string, format: date, description: 'The day the activity starts. Today or later.'}
        postal_code: {type: string, description: The postal code of the fiscal address. Sets the tax territory.}
    Incorporation:
      type: object
      required: [id, type, status, owner, company_id, created_at, updated_at]
      properties:
        id: {type: string, format: uuid}
        external_id: {type: [string, 'null']}
        type: {type: string, enum: [sl, autonomo], description: '`sl` for an S.L. incorporation, `autonomo` for a self-employed registration.'}
        status:
          type: string
          enum: [requested, in_progress, completed, cancelled]
          description: '`requested` until Melso''s team takes it, `in_progress` while it works with the owner, `completed` once the business has its NIF, `cancelled` if it stopped.'
        owner: {$ref: '#/components/schemas/Owner'}
        activity: {type: string}
        proposed_names: {type: array, items: {type: string}, description: S.L. only.}
        company_id: {type: [string, 'null'], format: uuid, description: 'The company Melso created, once `completed`. Null before.'}
        action_required:
          type: [string, 'null']
          enum: [identity_verification, documents, bank_deposit, notary_signature, null]
          description: What Melso's team waits for from the owner, if anything. Beta.
        identity_verifications:
          type: array
          items: {$ref: '#/components/schemas/IdentityVerification'}
          description: Each person who must verify their identity, and how far they got. Beta.
        created_at: {type: string, format: date-time}
        updated_at: {type: string, format: date-time}
        completed_at: {type: [string, 'null'], format: date-time}
    WebhookEndpointInput:
      type: object
      required: [url, events]
      properties:
        url: {type: string, format: uri, description: An HTTPS URL of yours.}
        events:
          type: array
          items: {type: string}
          description: 'Event types to receive, or families such as `tax_return.*`. See [Webhooks](/api/partner/webhooks).'
        description: {type: string, maxLength: 200}
    WebhookEndpointUpdate:
      type: object
      properties:
        url: {type: string, format: uri}
        events: {type: array, items: {type: string}}
        description: {type: string, maxLength: 200}
        status: {type: string, enum: [enabled, disabled]}
    WebhookEndpoint:
      type: object
      required: [id, url, events, status, created_at]
      properties:
        id: {type: string}
        url: {type: string, format: uri}
        events: {type: array, items: {type: string}}
        description: {type: string}
        status:
          type: string
          enum: [enabled, disabled]
          description: '`disabled` when you turned it off, or when Melso did after 3 days of failed deliveries.'
        created_at: {type: string, format: date-time}
    WebhookEndpointCreated:
      allOf:
        - $ref: '#/components/schemas/WebhookEndpoint'
        - type: object
          required: [secret]
          properties:
            secret: {type: string, description: 'The signing secret, `whsec_…`. Shown only in this answer.'}
    Event:
      type: object
      required: [id, type, created_at, company_id, data]
      properties:
        id: {type: string, description: 'Unique per event. Skip an `id` you have already handled.'}
        type:
          type: string
          enum: [incorporation.updated, incorporation.action_required, incorporation.completed, company.ready, company.missing_changed,
                 certificate.expiring, certificate.expired, tax_return.approval_pending, tax_return.approved, tax_return.filed,
                 tax_return.rejected, payroll_run.ready, test.ping]
        created_at: {type: string, format: date-time}
        company_id: {type: [string, 'null'], format: uuid, description: The company the event concerns. Null for an incorporation with no company yet.}
        data:
          type: object
          required: [object]
          properties:
            object: {type: object, description: The object as its GET endpoint returns it at the time of the event.}
    Delivery:
      type: object
      required: [event_id, status]
      properties:
        event_id: {type: string}
        status: {type: string, enum: [succeeded, failed]}
        response_code: {type: [integer, 'null']}
        latency_ms: {type: [integer, 'null']}
    IdentityVerification:
      type: object
      required: [tax_id, name, status]
      properties:
        id: {type: [string, 'null'], description: Null until a verification is created.}
        tax_id: {type: string}
        name: {type: string}
        status: {type: string, enum: [not_started, in_progress, in_review, approved, declined, abandoned, expired]}
        url: {type: [string, 'null'], description: Only in the answer that creates it.}
        expires_at: {type: [string, 'null'], format: date-time}
