Connector onboarding
Provision a company, let its owner upload the certificate and Hacienda login from the browser, and read the credential status.
A connector is an app that integrates with Sello on behalf of many
companies, for example a bookkeeping product. Sello registers each connector
and gives it a platform credential (sello_platform_…). With it, the
connector onboards a company with no portal session and no Sello operator.
The certificate (.p12), its PIN and the Hacienda user and password never pass
through the connector's servers. The customer's browser sends them straight to
Sello with a single-use upload grant.
All four operations live under /connect, outside /v1. They are listed in the
API reference.
The flow
Connector server Customer's browser Sello
──────────────── ────────────────── ─────
provisionConnectorCompany ─────────────────────────────────────▶ account, emisor, company key
mintCredentialUploadGrant ─────────────────────────────────────▶ uploadUrl + token (600 s)
hand uploadUrl + token ───────▶ form: .p12, PIN, user, password
redeemCredentialUploadGrant ───▶ validates, then stores all four
getEmisorCredentialStatus ─────────────────────────────────────▶ none / valid / expiring / expired| Operation | Path | Credential |
|---|---|---|
provisionConnectorCompany | POST /connect/companies | platform credential |
mintCredentialUploadGrant | POST /connect/emisores/{emisorId}/credential-grants | platform credential, or a company key pinned to the emisor with credentials:write |
redeemCredentialUploadGrant | POST /connect/emisores/{emisorId}/credentials | the grant token only, sent by the browser |
getEmisorCredentialStatus | GET /connect/emisores/{emisorId}/credential-status | a company key pinned to the emisor with credentials:read |
A platform credential works only on the first two. /v1, /reference and the
status read refuse it with 401.
1. Provision the company
POST /connect/companies with your companyId (your own id for the company,
compared exactly: case-sensitive and untrimmed), the environment (sandbox or
production) and the emisor's details. Sello creates an account, one emisor and
one company key pinned to that emisor, and answers 201 with the key's
plaintext. That answer is the only place the key appears; Sello stores its hash.
The same companyId and environment again is a replay: Sello answers 200
with the same account and emisor and a new key, and revokes the key it
returned before. Changed details answer 409 and change nothing.
A late retry of provisioning revokes the key an earlier answer returned. If a first request times out on your side and you retry, the retry's key is the only live one, even if the first answer reaches you later. Always save the newest key you receive.
2. Mint an upload grant
POST /connect/emisores/{emisorId}/credential-grants, with no body. The answer
is 201:
{
"uploadUrl": "https://api.sello.cr/connect/emisores/<emisorId>/credentials",
"token": "sello_grant_…",
"expiresAt": "2026-11-22T12:10:00.000Z"
}The grant lives 600 seconds, writes this one emisor's credentials once and reads
nothing. Give uploadUrl and token to the customer's browser page. Minting
does not cancel earlier grants. Ten mints per emisor per ten-minute window; the
eleventh answers 429 with Retry-After.
3. Upload from the browser
The page posts a multipart/form-data form with exactly four parts, p12,
pin, haciendaUsername and haciendaPassword, to uploadUrl with
Authorization: Bearer <token>. The page must be served from an origin Sello
registered for your connector; any other origin answers 403.
Sello spends the grant first, then validates the certificate and PIN, then logs
in to Hacienda once with the submitted user and password against the emisor's
own endpoints. Only when all of that passes does it store the four values, in
one commit, and answer 200 with the certificate's expiry. A failed upload
leaves the previously stored set unchanged. Every refusal after the token check
spends the grant, so mint a new one to try again. A renewal is the same call
with the new certificate.
4. Read the credential status
GET /connect/emisores/{emisorId}/credential-status with the company key:
{ "emisorId": "…", "status": "expiring", "certificateExpiresAt": "2026-12-01T00:00:00.000Z" }none: a value is missing (the certificate, its PIN, the Hacienda user or password, the emisor's Hacienda endpoints or client id, or the certificate expiry).certificateExpiresAtis still given when an expiry is stored.expired: the certificate's expiry is at or before now.expiring: it expires within 30 days.valid: otherwise.
This reports what is stored, not whether Hacienda accepts the login now. The read decrypts nothing and calls no Hacienda service. A suspended or closed account may still read it.
With the TypeScript SDK
@magiios/sdk 0.4.0 and later has a connect group. On your server, with the
platform credential:
import { SelloClient } from '@magiios/sdk';
const connector = new SelloClient({ token: process.env.SELLO_PLATFORM_CREDENTIAL });
const company = await connector.connect.provisionCompany({
companyId: 'realm-123',
environment: 'sandbox',
name: 'Pura Vida Supplies S.A.',
emisor: { name: 'Pura Vida Supplies S.A.', tipoIdentificacion: '02', identificacion: '3101123456' },
});
// Save company.apiKey now: a later replay revokes it.
const grant = await connector.connect.mintCredentialUploadGrant(company.emisorId);
// Hand grant.uploadUrl and grant.token to the customer's browser page.
// Later, with the company key.
const status = await new SelloClient({ apiKey: company.apiKey }).connect.getCredentialStatus(
company.emisorId,
);In the customer's browser, with the grant only:
import { SelloClient } from '@magiios/sdk';
const stored = await new SelloClient().connect.redeemCredentialUploadGrant({
uploadUrl: grant.uploadUrl,
token: grant.token,
p12: fileInput.files[0],
pin,
haciendaUsername,
haciendaPassword,
});redeemCredentialUploadGrant sends only the grant token, never the client's
own credential, and never retries: a retry of a spent grant can only be
refused.
A browser bundler (esbuild, Vite, webpack) loads the package's browser build
through the browser export condition. That build has everything except
verifyWebhook, parseWebhookEvent and the webhook header and event-type
constants: those need node:crypto and the webhook secret, so they stay on
your server.
A page with no bundler can send the same request with fetch:
const form = new FormData();
form.append('p12', fileInput.files[0]);
form.append('pin', pin);
form.append('haciendaUsername', haciendaUsername);
form.append('haciendaPassword', haciendaPassword);
const res = await fetch(grant.uploadUrl, {
method: 'POST',
headers: { Authorization: `Bearer ${grant.token}` },
body: form,
});The browser sets the Origin header and the multipart boundary itself.