> ## 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.
>
> 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.

# Request an alta, baja or variación

> Asks Melso to communicate an employee's registration, deregistration or data change to the TGSS through the Sistema RED, under the company's mandate.

<Info>
  **Preview.** A contract we are building with design partners. It is not callable yet, and fields can still change. See [Availability](/api/availability).
</Info>

Timing is the law's, not Melso's: an alta must reach the TGSS before the
employee starts work, and a baja or a variación within three calendar
days of the event. Send the request as soon as your platform knows.


## OpenAPI

````yaml api/openapi.yaml POST /companies/{company_id}/social-security/affiliations
openapi: 3.1.0
info:
  title: Melso API
  version: 1.0.0-preview
  summary: Spanish tax and labour compliance for the companies on your platform.
  description: |
    The Melso API lets an HR, payroll, banking or ERP platform run the
    Spanish tax and labour obligations of the companies it serves: invoices,
    books, tax returns, Social Security and employment notifications.

    Melso calculates and prepares. A person at the company approves the exact
    version. Melso's professionals file under the company's representation, and
    the filing is proven only by the administration's reference and receipt.

    Every operation states its availability in `x-melso-status`:

    - `live`: Melso runs this capability in production today. Partner keys
      reach it once a partner account is enabled.
    - `preview`: a contract proposed to design partners. Not callable yet.

    `x-melso-actor: person` marks a decision a signed-in person makes in
    Melso; a partner sends them the approval link instead.
  contact:
    name: Melso partnerships
    email: hello@melso.ai
    url: https://docs.melso.ai/api/overview
servers:
  - url: https://api.melso.ai/v1
    description: API. Keys and access are issued per partner.
security:
  - partnerKey: []
tags:
  - name: Companies
    description: The companies you operate for, their fiscal profile and hosted onboarding.
  - name: Mandates
    description: >-
      The company's representation of Melso before the AEAT, the TGSS and the
      SEPE.
  - name: Webhook endpoints
    description: Where Melso sends signed events about your companies.
  - name: Invoicing setup
    description: Registration of the company as a VERI*FACTU or TicketBAI invoice issuer.
  - name: Customers
    description: The company's invoice customers.
  - name: Invoices
    description: >-
      Drafts, approval, legal registration, delivery and payment of the
      company's invoices.
  - name: Expenses
    description: >-
      Purchase invoices and receipts, with their AEAT category and
      deductibility.
  - name: Income
    description: Income invoiced outside Melso.
  - name: Documents
    description: >-
      Files the company gives Melso, and Melso's structured reading of an
      invoice or receipt.
  - name: Banking
    description: >-
      Bank accounts, movements, statements and reconciliation with invoices and
      expenses.
  - name: Accounting
    description: Journal, imported books and the company's financial statements.
  - name: Tax calendar
    description: The forms the company must file, with their periods and deadlines.
  - name: Tax returns
    description: The returns Melso calculates, their approval and their filing.
  - name: Corporate tax
    description: The year's corporate tax (modelo 200) and its instalments (modelo 202).
  - name: Tax estimates
    description: What the company should set aside for taxes, as of today.
  - name: Cases
    description: Gestiones, the procedures Melso's professionals carry out for the company.
  - name: Administration notifications
    description: Electronic notifications from the administration to the company.
  - name: Certificates
    description: >-
      Official certificates such as being up to date with the AEAT or the Social
      Security.
  - name: Employees
    description: The people the company employs.
  - name: Payroll runs
    description: >-
      The payroll results your platform calculated, for Melso to settle and
      declare.
  - name: Social Security
    description: >-
      Affiliation (altas, bajas and variaciones) and monthly contribution
      settlements.
  - name: Employment notifications
    description: >-
      Contrat@ contract notifications and Certific@2 company certificates to the
      SEPE.
paths:
  /companies/{company_id}/social-security/affiliations:
    parameters:
      - $ref: '#/components/parameters/CompanyId'
    post:
      tags:
        - Social Security
      summary: Request an alta, baja or variación
      description: |
        Asks Melso to communicate an employee's registration (`alta`),
        deregistration (`baja`) or data change (`variacion`) to the TGSS through
        the Sistema RED, under the company's TGSS mandate.

        Timing is the law's, not Melso's: an alta must reach the TGSS before the
        employee starts work, and a baja or a variación within three calendar
        days of the event. Send the request as soon as your platform knows.
      operationId: createAffiliation
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AffiliationInput'
            example:
              employee_id: 6a1f0c2e-4b3d-4e5f-8a9b-0c1d2e3f4a5b
              action: alta
              effective_date: '2026-11-02'
      responses:
        '201':
          description: The request, `pending` until it reaches the TGSS.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Affiliation'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '409':
          $ref: '#/components/responses/Conflict'
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, such as a UUID, that makes a retried create safe. Reusing
        a key with a different body is refused.
      schema:
        type: string
        maxLength: 255
  schemas:
    AffiliationInput:
      type: object
      required:
        - employee_id
        - action
        - effective_date
      additionalProperties: false
      properties:
        employee_id:
          type: string
          format: uuid
          description: >-
            The employee, with `tax_id`, `social_security_number` and
            `employment` filled.
        action:
          type: string
          enum:
            - alta
            - baja
            - variacion
        effective_date:
          type: string
          format: date
        termination_reason:
          type: string
          enum:
            - end_of_contract
            - dismissal
            - objective_dismissal
            - voluntary_resignation
            - probation_not_passed
            - retirement
            - other
          description: Required for a `baja`.
        unused_vacation_days:
          type: integer
          minimum: 0
          description: >-
            For a `baja`, the vacation paid and not taken, which extends the
            contribution period.
        changes:
          $ref: '#/components/schemas/EmploymentData'
          description: For a `variacion`, the new employment data.
    Affiliation:
      type: object
      required:
        - id
        - employee_id
        - action
        - effective_date
        - status
        - created_at
      properties:
        id:
          type: string
          format: uuid
        employee_id:
          type: string
          format: uuid
        action:
          type: string
          enum:
            - alta
            - baja
            - variacion
        effective_date:
          type: string
          format: date
        status:
          type: string
          enum:
            - pending
            - submitted
            - accepted
            - rejected
        submitted_at:
          type:
            - string
            - 'null'
          format: date-time
        resolution:
          oneOf:
            - $ref: '#/components/schemas/Document'
            - type: 'null'
          description: The TGSS's resolution once accepted.
        rejection_reason:
          type:
            - string
            - 'null'
        created_at:
          type: string
          format: date-time
    EmploymentData:
      type: object
      description: Preview. What the TGSS and the SEPE need about the job.
      properties:
        contribution_account:
          type: string
          pattern: ^[0-9]{11}$
          description: The company's código cuenta de cotización (CCC) for this workplace.
        contract_type:
          type: string
          description: >-
            The contract key, such as `100` (permanent, full time) or `402`
            (temporary, full time).
        working_time_coefficient:
          type: integer
          minimum: 1
          maximum: 1000
          description: Part-time coefficient per thousand. `1000` is full time.
        contribution_group:
          type: integer
          minimum: 1
          maximum: 11
          description: The grupo de cotización.
        occupation_code:
          type: string
          description: The CNO-11 occupation code.
        collective_agreement:
          type: string
          description: The código de convenio colectivo.
    Document:
      type: object
      properties:
        id:
          type: string
          format: uuid
        filename:
          type: string
        content_type:
          type: string
        size_bytes:
          type: integer
        url:
          type: string
          format: uri
          description: A short-lived download URL.
    Error:
      type: object
      required:
        - error
      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: Quote it when you contact Melso.
  responses:
    BadRequest:
      description: >-
        The request is malformed or a field is invalid. Unknown fields are
        refused.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: lines[0].vat_rate must be 21, 10, 4 or 0
            code: invalid_invoice
            request_id: req_01JAB3K9X2
    Unauthorized:
      description: The key is missing, revoked or invalid.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: invalid token
            code: unauthorized
            request_id: req_01JAB3K9X2
    Conflict:
      description: >-
        The object changed or is not in a state that allows this. Read it again
        and decide.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: The tax return changed or is not ready for approval
            code: version_conflict
            request_id: req_01JAB3K9X2
  securitySchemes:
    partnerKey:
      type: http
      scheme: bearer
      description: |
        Your partner secret key, `mk_live_…` for real companies or `mk_test_…`
        for test companies. Keep it on your servers. See
        [Authentication](/api/authentication).

````

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