Sync economic activities from Hacienda's registry
const url = 'https://api.emite.cr/v1/tenants/example/economic-activities/sync';const options = { method: 'POST', headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'}, body: '{"newDefault":"6201.0"}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://api.emite.cr/v1/tenants/example/economic-activities/sync \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --data '{ "newDefault": "6201.0" }'Reads Hacienda's registry for the company's identification and brings the company's activities in line with it: adds the new ones, removes the ones Hacienda no longer registers, and updates their names. If the current default is among the removed, nothing is applied and the API answers 409 DEFAULT_ACTIVITY_DROPPED, with error.details.removed ({ code, description } of the dropped default) and error.details.suggested ([{ code, description }], every activity Hacienda registers): call again with { "newDefault": "<code>" } to choose the replacement. An empty suggested means Hacienda registers no activity for the company, which must register one with Hacienda before it can sync. Hacienda's answer is cached for an hour; 404 when Hacienda's registry does not know the identification, 424 HACIENDA_LOOKUP_UNAVAILABLE or 429 when its registry fails or throttles. Answers 201 (a POST), also when nothing changed.
Authorizations
Section titled “Authorizations”Parameters
Section titled “Parameters”Path Parameters
Section titled “Path Parameters”Request Bodyrequired
Section titled “Request Bodyrequired”object
Code of the activity that becomes the default, one of those Hacienda registers for the company. Send it after a 409 DEFAULT_ACTIVITY_DROPPED, choosing from error.details.suggested; a code Hacienda does not register answers 409 INVALID_NEW_DEFAULT and nothing is applied.
Example
6201.0Responses
Section titled “Responses”object
Activities Hacienda registers that the company did not have, now added.
object
Id of the activity in the company; PATCH …/{activityId}/default takes it.
Hacienda's economic activity code, in the dotted form its registry returns. The default one is what documents declare as <CodigoActividadEmisor>.
The activity's name, as Hacienda's registry returns it (in Spanish). null for an activity seeded from the company's economicActivityCode at its creation, until the first sync with Hacienda fills it.
Whether documents declare this activity when the request names none. At most one activity of the company is the default; with none, creating a document that names no activity answers 412 TENANT_NOT_CONFIGURED.
Activities the company had that Hacienda no longer registers, now removed (as they were before the sync).
object
Id of the activity in the company; PATCH …/{activityId}/default takes it.
Hacienda's economic activity code, in the dotted form its registry returns. The default one is what documents declare as <CodigoActividadEmisor>.
The activity's name, as Hacienda's registry returns it (in Spanish). null for an activity seeded from the company's economicActivityCode at its creation, until the first sync with Hacienda fills it.
Whether documents declare this activity when the request names none. At most one activity of the company is the default; with none, creating a document that names no activity answers 412 TENANT_NOT_CONFIGURED.
How many activities the company has after the sync.
The default activity after the sync: the newDefault you sent, the previous default if Hacienda still registers it, or Hacienda's primary activity when the company had none. null when Hacienda registers no activity.
Example
{ "added": [ { "code": "6201.0", "description": "Programación de computadoras" } ], "removed": [ { "code": "6201.0", "description": "Programación de computadoras" } ]}Missing or invalid JWT / API key
Tenant boundary violation or insufficient scope.
DEFAULT_ACTIVITY_DROPPED: the current default is no longer registered (see error.details). INVALID_NEW_DEFAULT: newDefault is not one of the activities Hacienda registers (error.details.suggested lists them).