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

# Onboard an existing business

> Open the Melso company of a business that already has its NIF, send every fiscal field Melso needs, and know when it is ready for its taxes.

Use this guide when your customer's business already exists: an S.L. with its
CIF, or a self-employed person registered with the AEAT. For a business that
does not exist yet, see [Incorporations](https://docs.melso.ai/api/partner/guides/incorporation.md).

Creating a company only opens its account in Melso. Nothing is filed and nobody
is written to.

## 1. Create the company

```bash theme={null}
curl https://api.melso.ai/v1/partner/companies \
  -H "Authorization: Bearer $MELSO_PARTNER_KEY" \
  -H "Idempotency-Key: 0b9c7d1e-4f2a-4b8c-9d3e-5a6f7b8c9d0e" \
  -H "Content-Type: application/json" \
  -d '{
    "kind": "company",
    "name": "Brasa Norte S.L.",
    "company_form": "sl",
    "tax_id": "B00000000",
    "external_id": "ws_48213",
    "email": "admin@brasanorte.example",
    "phone": "+34600000000",
    "fiscal_profile": {
      "legal_name": "Brasa Norte S.L.",
      "address": "Carrer de Pallars 100",
      "postal_code": "08018",
      "city": "Barcelona",
      "province": "Barcelona",
      "tax_territory": "comun",
      "activity_type": "empresarial",
      "iae_code": "671.4",
      "vat_regime": "general",
      "vat_sii": false,
      "vat_redeme": false,
      "is_large_company": false
    }
  }'
```

| Field | Required | Notes |
| - | - | - |
| `kind` | Yes | `company` for a CIF, `freelancer` for a DNI or NIE. It cannot change later. |
| `name` | Yes | The name your customer knows. It is also `legal_name` unless you send one. |
| `company_form` | Company only | `sl`, `slu`, `slp`, `sa`, `cooperativa`, `comunidad_bienes` or `sociedad_civil`. |
| `tax_id` | Recommended | The CIF, DNI or NIE. It must fit `kind`. |
| `external_id` | Recommended | Your own ID, up to 200 characters, unique in your firm. It comes back on every company. |
| `email`, `phone` | No | The business's contact details. Melso does not write to them. |
| `fiscal_profile` | No | Any field of the [fiscal profile](#the-fiscal-profile). You can send it now or later. |

Send a fresh `Idempotency-Key` per company. If the call times out, send it
again with the same key and body: you get the same company back, with
`Idempotent-Replayed: true`, never a second one.

### The answer

```json theme={null}
{
  "company": {
    "id": "1b2c3d4e-5f6a-4b7c-8d9e-0f1a2b3c4d5e",
    "external_id": "ws_48213",
    "kind": "company",
    "name": "Brasa Norte S.L.",
    "tax_id": "B00000000",
    "status": "active",
    "missing": ["certificate"],
    "certificate": "missing",
    "created_at": "2026-12-01T09:30:00Z",
    "updated_at": "2026-12-01T09:30:00Z"
  },
  "fiscal_profile": { "...": "..." },
  "errors": []
}
```

Store `company.id` beside your own record. Every later call uses it.

The company is created even when a fiscal field is refused: `errors` names
each refused field and why, and every other field is saved.

### Refusals

Nothing is created when the call answers:

| Status | `code` | Meaning |
| - | - | - |
| `400` | `invalid_request` | A field is invalid, such as a NIF that does not fit `kind`. `error` says which. |
| `400` | `invalid_arguments` | An unknown field. Melso never ignores a field it does not know. |
| `402` | `gestoria_payment_method_required` | Your firm has no payment method yet. `payment_url` opens the page to add one. |
| `402` | `gestoria_unpaid` | Your firm has an unpaid invoice. |
| `409` | `conflict` | `field` is `tax_id` or `external_id`: another company of your firm already has it. |
| `422` | `idempotency_key_reused` | This `Idempotency-Key` came with a different body. |

## 2. Complete the fiscal profile

`missing` lists what Melso needs before it can do the company's taxes. Send the
fields with [Update the fiscal profile](https://docs.melso.ai/api/reference/fiscal-profile/update-fiscal-profile.md),
your partner key and the company's `id` in the path. Only the fields you send
change.

```bash theme={null}
curl -X PATCH https://api.melso.ai/v1/companies/$COMPANY_ID/fiscal-profile \
  -H "Authorization: Bearer $MELSO_PARTNER_KEY" \
  -H "Content-Type: application/json" \
  -d '{"vat_sii": false, "vat_redeme": false, "is_large_company": false}'
```

The answer carries the updated `missing`. The company is ready when `missing`
is empty, and the [`company.ready`](https://docs.melso.ai/api/partner/webhooks) event tells you so.

| Item in `missing` | Who | What to send |
| - | - | - |
| `tax_territory` | Everyone | Deduced from `postal_code`. Send `comun`, `alava`, `bizkaia`, `gipuzkoa`, `navarra`, `canarias`, `ceuta` or `melilla` only to correct it. |
| `activity_type` | Everyone | `empresarial` or `profesional`. A company is always `empresarial`. |
| `registration_status` | Self-employed | `alta` once registered with the AEAT, else `pendiente`. |
| `tax_id` | Company | A valid CIF. |
| `legal_name` | Company | The name in the deed. |
| `vat_sii` | Company | `true` if the company keeps its VAT books through SII. |
| `vat_redeme` | Company | `true` if it is on the monthly VAT refund register. |
| `is_large_company` | Company | `true` above €6,010,121.04 of turnover. |
| `certificate` | Everyone | A valid [digital certificate](https://docs.melso.ai/api/partner/guides/certificate.md). |

> [!NOTE]
>
> A self-employed person with `registration_status: pendiente` has no tax
> calendar until it becomes `alta`, even with an empty `missing`.

## The fiscal profile

These fields shape every return Melso prepares. The
[reference](https://docs.melso.ai/api/reference/fiscal-profile/update-fiscal-profile.md) lists their
formats.

| Field | Why it matters |
| - | - |
| `address`, `postal_code`, `city`, `province` | The fiscal address. `postal_code` also tells Melso the tax territory. |
| `tax_territory` | Common territory, the Basque provinces, Navarre, the Canary Islands, Ceuta or Melilla. Each has its own returns. |
| `iae_code`, `activity_description` | The main IAE heading. `671.4` is a restaurant, `673.2` a bar. |
| `activities` | Up to 20 more IAE headings, each with its own `vat_regime` and dates. |
| `vat_regime` | `general` for most. Also `recargo_equivalencia`, `simplificado`, `reagp`, `exento`, and IGIC or IPSI outside common territory. |
| `registered_on` | When the business started, `YYYY-MM` or `YYYY-MM-DD`. |
| `irpf_method` | Self-employed: `directa_simplificada` (default), `directa_normal` or `modulos`. |
| `irpf_retention_rate` | Self-employed professionals: the withholding on their invoices. |
| `client_types` | Who the business sells to: `es_business`, `es_individual`, `eu_business`, `non_eu_business`. |
| `eu_operator` | Registered for intra-EU operations (ROI). |
| `iban` | The account the business's invoices are collected in. |

## 3. Add the certificate

Melso files with a digital certificate of the business. See
[Digital certificate](https://docs.melso.ai/api/partner/guides/certificate.md).

## Next

* [Send the books](https://docs.melso.ai/api/partner/guides/books.md) as they happen.
* [Approvals](https://docs.melso.ai/api/partner/guides/approvals.md): how the company approves a return in your product.


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