You are integrating Melso into our backend.
Context
- Melso is an online gestoría. Our product offers our customers accounting,
tax returns and payroll through Melso, under our brand. Our platform is a
firm in Melso. Each customer business with a NIF is a Melso company of that
firm.
- Two contracts. The Partner API opens companies:
https://docs.melso.ai/api/partner-openapi.yaml. The Melso API does everything
else for one company, with its id in the path:
https://docs.melso.ai/api/openapi.yaml. Our partner key calls both. Read
https://docs.melso.ai/api/partner/acting-for-companies first.
- Base URL: https://api.melso.ai/v1. The key is in the MELSO_PARTNER_KEY
environment variable on the server.
Rules
- Use only endpoints and fields in the contracts. If you need one that is not
there, stop and list it as a question for Melso. Never invent one.
- Operations marked x-melso-availability: beta are not served yet. Build them
behind a feature flag and say which ones you used.
- The key lives on the server only. Never send it to the browser, log it or
commit it.
- Send an Idempotency-Key on every POST that creates something, derived from
our own IDs (for example company-<our workspace id>), and reuse it on retries.
- Webhooks are the source of truth for changes: verify Melso-Signature on the
raw body, skip event ids already handled, answer 2xx fast and work after.
Reconcile with GET /partner/events. Never poll in a tight loop.
- The digital certificate and its password go straight from our form to
POST /companies/{company_id}/certificate. Never store or log either.
- Never approve a tax return on the customer's behalf. Show the exact version
to an authenticated person of the company, record their consent, then send
it to POST /companies/{company_id}/tax-returns/{id}/approval. Show a return
as filed only when filing.reference is present.
Build, in this order
1. A Melso client module: base URL, bearer key, Idempotency-Key (a UUID per
operation, reused on retries), cursor pagination, and errors mapped from
code and field. Retry 429 after Retry-After, and 5xx with backoff.
2. Store the Melso company id beside our customer record.
3. Onboarding: POST /partner/companies with kind, name, company_form, tax_id,
external_id = our ID and the fiscal details we have. A customer without a
NIF goes to POST /partner/incorporations/sl or /partner/incorporations/autonomo;
when action_required is identity_verification, create one with
POST /partner/incorporations/{id}/identity-verifications and open its url.
4. Complete the company with PATCH /companies/{company_id}/fiscal-profile until
missing is empty. Show each refused field from errors.
5. A certificate form that uploads to POST /companies/{company_id}/certificate
and shows each refusal code in plain words.
6. Books: send each invoice file to POST /companies/{company_id}/documents, or
its figures to POST /companies/{company_id}/expenses with account per line.
Surface warnings (possible_duplicate, vat_mismatch) to the user.
7. A webhook receiver for incorporation.*, company.ready, certificate.*,
tax_return.* and payroll_run.ready.
8. A taxes screen: the tax calendar, returns waiting for approval with the
approval flow above, and filed returns with their receipt.
9. Tests for each call and each webhook against the contracts' examples.
Finish with a short list of what you built, what you could not, and the
questions for Melso.