Court Register (Croatia)
reference Facts, options, APIs
On this page
- Settings
- Vocabulary and Properties
- Request and response
- Properties added by the enricher
- How the script handles input and errors
- Testing the enricher
- Limitations
- Process script
This example looks up an organization’s OIB (personal identification number) or MBS (court register number) in the Croatian Court Register’s (Sudski registar) open data API. For each golden record it stores the registered name and short name, the legal form, the registered office address, the main activity (NKD code), the first e-mail address, the share capital, the foundation date, the competent commercial court, and any bankruptcy or liquidation proceeding and deletion from the register.
Enricher version: V2
API key: your Court Register client ID and client secret (free; register at sudreg-data.gov.hr)
This sample couldn’t be tried with real credentials. The request and response follow the detalji_subjekta operation in the Court Register’s OpenAPI specification (https://sudreg-data.gov.hr/api/javni/dokumentacija/open_api), which doesn’t include an example response, so the response on this page is illustrative: it has the structure of the specification, but the company and values are made up. The token endpoint and the API were checked live with made-up credentials, and their error responses are handled as described below.
To set up the enricher, see Add REST API enricher, then use the settings and script on this page.
Settings
-
Accepted Business Domain –
/Organization, or the business domain that holds your companies. -
Version – V2 (recommended).
-
API Key – your client credentials, as
clientId:clientSecret. To get them, register at sudreg-data.gov.hr and confirm your registration e-mail. The client ID and the client secret both end with two dots (..); the dots are part of the values. Enter them in the API Key field separated by a colon.The script gets an access token from the token endpoint with these credentials and reuses it until shortly before it expires. If the field is empty, the script adds nothing and doesn’t call the Court Register.
-
Filters – we recommend a rule that only accepts golden records where
organization.oibororganization.mbshas a value. Otherwise, every record without either number is listed on the enricher’s Logs tab as having returned no results.
Vocabulary and Properties
organization.oib
organization.mbs
organization.oib holds the 11-digit OIB, and organization.mbs holds the court register number (MBS). The script uses the OIB when it is valid, and otherwise the MBS; you can keep only one of the keys if your data has only one of them. If your data uses other vocabulary keys, change this field and the OIB_KEY and MBS_KEY values at the top of the script.
Request and response
Base URL: https://sudreg-data.gov.hr/api/javni
Endpoint: GET /detalji_subjekta?tip_identifikatora={oib|mbs}&identifikator={number}&expand_relations=1
Authentication: OAuth2 bearer token in the Authorization header. Tokens come from https://sudreg-data.gov.hr/api/oauth/token with the client credentials grant, with the client ID and secret in an HTTP Basic Authorization header.
Test environment: https://sudreg-data-test.gov.hr/api/javni
When it has no valid token, the script first requests one:
POST https://sudreg-data.gov.hr/api/oauth/token
Authorization: Basic <base64 of clientId:clientSecret>
Content-Type: application/x-www-form-urlencoded
Accept: application/json
grant_type=client_credentials
{ "access_token": "Q2x1ZWRJbi...", "token_type": "bearer", "expires_in": 21600 }
Then it sends one request per golden record:
GET https://sudreg-data.gov.hr/api/javni/detalji_subjekta?tip_identifikatora=oib&identifikator=12345678903&expand_relations=1
Authorization: Bearer Q2x1ZWRJbi...
Accept: application/json
Shortened response (illustrative values):
{
"mbs": 80000014,
"potpuni_mbs": "080000014",
"oib": 12345678903,
"potpuni_oib": "12345678903",
"sud_nadlezan": { "sifra": 4, "naziv": "Trgovački sud u Zagrebu" },
"datum_osnivanja": "1990-12-28T00:00:00Z",
"tvrtka": { "ime": "PRIMJER d.o.o. za proizvodnju električne energije", "naznaka_imena": "PRIMJER" },
"skracena_tvrtka": { "ime": "PRIMJER d.o.o." },
"sjediste": {
"drzava": { "naziv": "Hrvatska", "oznaka_2": "HR" },
"naziv_zupanije": "Grad Zagreb",
"naziv_opcine": "Zagreb",
"naziv_naselja": "Zagreb",
"ulica": "Ulica grada Vukovara",
"kucni_broj": 37,
"kucni_podbroj": "A",
"postanski_broj": 10000
},
"email_adrese": [{ "email_adresa_rbr": 1, "adresa": "info@primjer.hr" }],
"pravni_oblik": { "vrsta_pravnog_oblika": { "naziv": "društvo s ograničenom odgovornošću", "kratica": "d.o.o." } },
"pretezita_djelatnost": { "nacionalna_klasifikacija_djelatnosti": { "sifra": "35.11", "puni_naziv": "Proizvodnja električne energije", "verzija": "NKD 2007" } },
"temeljni_kapitali": [{ "temeljni_kapital_rbr": 1, "valuta": { "naziv": "EUR" }, "iznos": 2500.5 }]
}
Properties added by the enricher
| Property | Response field | Example |
|---|---|---|
sudreg.mbs | potpuni_mbs | 080000014 |
sudreg.oib | potpuni_oib | 12345678903 |
sudreg.name | tvrtka.ime | PRIMJER d.o.o. za proizvodnju električne energije |
sudreg.shortName | skracena_tvrtka.ime | PRIMJER d.o.o. |
sudreg.legalForm | pravni_oblik.vrsta_pravnog_oblika.naziv | društvo s ograničenom odgovornošću |
sudreg.legalFormCode | pravni_oblik.vrsta_pravnog_oblika.kratica | d.o.o. |
sudreg.address | sjediste street, house number, postal code and place, on one line | Ulica grada Vukovara 37A, 10000 Zagreb |
sudreg.postalCode | sjediste.postanski_broj | 10000 |
sudreg.city | sjediste.naziv_naselja | Zagreb |
sudreg.municipality | sjediste.naziv_opcine | Zagreb |
sudreg.county | sjediste.naziv_zupanije | Grad Zagreb |
sudreg.countryCode | sjediste.drzava.oznaka_2 | HR |
sudreg.industryCode | pretezita_djelatnost.nacionalna_klasifikacija_djelatnosti.sifra | 35.11 |
sudreg.industry | pretezita_djelatnost.nacionalna_klasifikacija_djelatnosti.puni_naziv (in Croatian) | Proizvodnja električne energije |
sudreg.email | first email_adrese[].adresa | info@primjer.hr |
sudreg.shareCapital | iznos of the first temeljni_kapitali entry | 2500.5 |
sudreg.shareCapitalCurrency | valuta.naziv of that entry | EUR |
sudreg.foundationDate | datum_osnivanja, as YYYY-MM-DD | 1990-12-28 |
sudreg.court | sud_nadlezan.naziv | Trgovački sud u Zagrebu |
sudreg.proceeding | postupak.postupak.znacenje | Stečaj |
sudreg.bankruptcyDate | postupak.datum_stecaja, as YYYY-MM-DD | 2023-10-02 |
sudreg.deleted | True when datum_brisanja has a value | True |
sudreg.deletionDate | datum_brisanja, as YYYY-MM-DD | 2024-03-09 |
A property is added only when the Court Register returns a value for it. When the response includes historical rows, only the current rows (status 1) are used.
If the enricher has a Preview tab, the results appear there first. To add them to golden records, go to the Map tab, select Map Data, and choose Auto Mapping. Select the business domain, enter a new vocabulary named Sudreg with the key prefix sudreg, and then create the mapping. Auto mapping also uses name as the golden record name, so remove that from the mapping if you want to keep your existing names. Then process the data on the Process tab. If the enricher has no Preview tab, the properties are added to the golden record as soon as it is enriched.
How the script handles input and errors
-
Spaces, dots and dashes are removed from both numbers, and an
HRprefix (as in the Croatian VAT number) is removed from the OIB, soHR 123 4567 8903is looked up as12345678903. The OIB must have a valid ISO 7064 MOD 11,10 check digit. An MBS with fewer than 9 digits is padded with leading zeros. Golden records without a valid OIB or MBS are skipped without calling the Court Register. -
If the token endpoint rejects the client ID and secret (HTTP 401), the script throws an error, so the golden record is listed on the Logs tab with a message to check the API Key field. If the API rejects the token (HTTP 401 or 403), the script first gets a new token and tries once more, and then throws an error. The API also rejects tokens until you have confirmed your registration e-mail.
-
If the entity isn’t registered (HTTP 400 with error code
505, “Vaš zahtjev nije vratio ni jedan redak”), or the API returns another error, the script logs the reason, including thelog_idthe Court Register’s support asks for, and adds nothing. -
If the Court Register reports that it is too busy (HTTP 429), the script throws an error that makes the enricher try the golden record again later.
-
Successful results are cached for 24 hours per OIB or MBS. The register is updated once a day. To change this, edit
CACHE_MILLISECONDSin the script.
Testing the enricher
-
Test connection checks only that the script runs. It doesn’t call the Court Register.
-
To try the setup against the Court Register’s test environment, change
SUDREG_URLandTOKEN_URLat the top of the script to the test environment addresses (see the comment above them), and use credentials for the test environment. -
To try it in production, create a golden record with
organization.oibset to the OIB of a company you know, then enrich it.
Limitations
-
detalji_subjektais meant for looking up individual entities, and the Court Register limits how many calls a public user can make to it per minute. Enrich a large number of golden records in smaller batches, and keep the cache on. If the limit is exceeded with HTTP 429, the enricher retries the golden record. -
Only the registered office (
sjediste) is used. Branches (podruznice), the full list of business activities (predmeti_poslovanja), members and annual financial statements aren’t added. -
Activity descriptions, legal forms and proceedings are in Croatian.
-
The Court Register’s API reports
expand_relationsas optional. The script sets it to1so that code lists (legal form, activity, court, country) are returned as names rather than IDs.
Process script
// REST API enricher (V2) - Croatian company lookup with the Court Register (Sudski registar)
//
// Looks up a golden record's OIB (personal identification number) or MBS (court register
// number) in the Croatian Court Register's open data API (https://sudreg-data.gov.hr/), and adds
// the result to the golden record as sudreg.* properties:
//
// sudreg.mbs 9-digit court register number (MBS)
// sudreg.oib 11-digit OIB
// sudreg.name registered name (tvrtka)
// sudreg.shortName short name (skraćena tvrtka)
// sudreg.legalForm legal form, for example društvo s ograničenom odgovornošću
// sudreg.legalFormCode legal form abbreviation, for example d.o.o.
// sudreg.address registered office address on one line
// sudreg.postalCode postal code of the registered office
// sudreg.city place (naselje) of the registered office
// sudreg.municipality municipality or city (općina / grad) of the registered office
// sudreg.county county (županija) of the registered office
// sudreg.countryCode 2-letter country code of the registered office
// sudreg.industryCode NKD code of the main activity, for example 35.11
// sudreg.industry description of the main activity (Croatian)
// sudreg.email first registered e-mail address
// sudreg.shareCapital share capital amount
// sudreg.shareCapitalCurrency currency of the share capital
// sudreg.foundationDate date the entity was founded (YYYY-MM-DD)
// sudreg.court competent commercial court
// sudreg.proceeding current proceeding, for example bankruptcy or liquidation
// sudreg.bankruptcyDate date bankruptcy proceedings were opened (YYYY-MM-DD)
// sudreg.deleted "True" when the entity has been deleted from the register
// sudreg.deletionDate date it was deleted (YYYY-MM-DD)
//
// Needs free API credentials (a client ID and client secret) from https://sudreg-data.gov.hr/.
// Enter them in the enricher's API Key field as clientId:clientSecret. The script gets an access
// token itself and reuses it until shortly before it expires. See README.md next to this file
// for the enricher settings.
//
// A record gets no result (nothing is stored) when it has no valid OIB or MBS, when the entity
// isn't registered, or when the API can't answer. Missing credentials make no call; rejected
// credentials fail the record with an error that says so.
// ---- Settings -------------------------------------------------------------------------
// Vocabulary keys to read. Add the same keys to the Vocabulary and Properties field. The OIB is
// used when it is valid; otherwise the MBS.
const OIB_KEY = "organization.oib";
const MBS_KEY = "organization.mbs";
// The Court Register's test environment is https://sudreg-data-test.gov.hr/api/javni
// (token endpoint https://sudreg-data-test.gov.hr/api/oauth/token).
const SUDREG_URL = "https://sudreg-data.gov.hr/api/javni/detalji_subjekta";
const TOKEN_URL = "https://sudreg-data.gov.hr/api/oauth/token";
// The {APIKey} placeholder is replaced with the API Key field value (clientId:clientSecret).
const API_KEY = "{APIKey}";
// How long to reuse an answer for the same entity. 0 turns caching off. The register is
// updated once a day, and detalji_subjekta allows only a few calls a minute.
const CACHE_MILLISECONDS = 24 * 60 * 60 * 1000;
// ---- Script ---------------------------------------------------------------------------
function getValue(key) {
// A plain loop rather than vocabularies.find(...): vocabularies is a .NET list, and when
// .find is called from inside a function, later calls return the first call's match.
const items = vocabularies || [];
for (let i = 0; i < items.length; i++) {
if (items[i].Key === key) {
const value = items[i].Value;
return value === null || value === undefined ? "" : String(value).trim();
}
}
return "";
}
// Accepts "81793146560", "HR81793146560" (the VAT number) and "817 9314 6560". Returns the 11
// digits, or null when it isn't a valid OIB (ISO 7064 MOD 11,10 check digit).
function parseOib(raw) {
const digits = raw.toUpperCase().replace(/^HR/, "").replace(/[\s.\-]/g, "");
if (!/^\d{11}$/.test(digits)) {
return null;
}
let product = 10;
for (let i = 0; i < 10; i++) {
let sum = (Number(digits.charAt(i)) + product) % 10;
if (sum === 0) {
sum = 10;
}
product = (sum * 2) % 11;
}
const checkDigit = (11 - product) % 10;
return checkDigit === Number(digits.charAt(10)) ? digits : null;
}
// Accepts "080000014", "80000014", "080 000 014". Returns the MBS as 9 digits (with leading
// zeros), or null when it isn't one.
function parseMbs(raw) {
const text = raw.toUpperCase().replace(/^MBS/, "").replace(/[\s.\-:]/g, "");
if (!/^\d{1,9}$/.test(text) || /^0+$/.test(text)) {
return null;
}
return ("000000000" + text).slice(-9);
}
function clean(value) {
if (value === null || value === undefined) {
return null;
}
const text = String(value).replace(/\s+/g, " ").trim();
return text === "" ? null : text;
}
function parseJson(text) {
try {
return JSON.parse(text);
} catch (e) {
return null;
}
}
function dateOnly(value) {
const text = clean(value);
return text && /^\d{4}-\d{2}-\d{2}/.test(text) ? text.substring(0, 10) : null;
}
function credentials() {
const value = clean(API_KEY) || "";
const separator = value.indexOf(":");
if (separator <= 0 || separator === value.length - 1) {
return null;
}
// The Court Register's client IDs and secrets end with two dots; they are part of the value.
return { clientId: value.substring(0, separator), clientSecret: value.substring(separator + 1) };
}
// Gets an access token with the OAuth2 client credentials grant (client ID and secret in an
// HTTP Basic authentication header).
function requestToken(creds) {
const tokenResponse = http.send({
url: TOKEN_URL,
method: "POST",
headers: [
{ Key: "Authorization", Value: `Basic ${stringEncoder.toBase64(`${creds.clientId}:${creds.clientSecret}`)}` },
{ Key: "Content-Type", Value: "application/x-www-form-urlencoded" },
{ Key: "Accept", Value: "application/json" },
],
body: "grant_type=client_credentials",
});
const status = String(tokenResponse.HttpStatus || "");
const body = parseJson(tokenResponse.Content);
if (status === "TooManyRequests") {
throw new Error("TooManyRequests - the Court Register token endpoint is busy, the record will be retried");
}
if (status === "OK" && body && body.access_token) {
return { accessToken: String(body.access_token), expiresIn: Number(body.expires_in) || 3600 };
}
if (status === "BadRequest" || status === "Unauthorized" || status === "Forbidden") {
const reason = body ? clean(body.error_description || body.error || body.message || body.code) : null;
throw new Error(`The Court Register rejected the client ID and secret in the API Key field (HTTP ${status}${reason ? `, ${reason}` : ""}).`);
}
log(`Could not get a Court Register access token. HTTP ${status}. ${String(tokenResponse.Content || "").substring(0, 200)}`);
return null;
}
// Returns an access token, from the cache when there's one that hasn't expired.
function getAccessToken(creds, forceNew) {
const cacheKey = `sudreg:token:${creds.clientId}`;
if (!forceNew) {
const cached = cache.get(cacheKey);
if (cached) {
return String(cached);
}
}
const token = requestToken(creds);
if (!token) {
return null;
}
// Reuse the token until 5 minutes before it expires (at least 1 minute). A forced new token
// isn't cached, because cache.set does nothing when the key already exists.
if (!forceNew) {
cache.set(cacheKey, token.accessToken, Math.max(60, token.expiresIn - 300) * 1000);
}
return token.accessToken;
}
function callApi(identifier, accessToken) {
return http.send({
url: `${SUDREG_URL}?tip_identifikatora=${identifier.type}&identifikator=${identifier.value}&expand_relations=1`,
method: "GET",
headers: [
{ Key: "Authorization", Value: `Bearer ${accessToken}` },
{ Key: "Accept", Value: "application/json" },
],
});
}
// The API's errors are { error_code, error_message, log_id }, sometimes in an array.
function getErrors(body) {
const list = Array.isArray(body) ? body : body ? [body] : [];
const errors = [];
for (let i = 0; i < list.length; i++) {
if (list[i] && list[i].error_code !== undefined) {
errors.push({ code: Number(list[i].error_code), message: `${list[i].error_code}: ${list[i].error_message} (log_id ${list[i].log_id})` });
}
}
return errors;
}
// Calls the API. Returns the entity, or null when there's no answer to store.
function lookUp(identifier, creds) {
const accessToken = getAccessToken(creds, false);
if (!accessToken) {
return null;
}
let apiResponse = callApi(identifier, accessToken);
let status = String(apiResponse.HttpStatus || "");
// A cached token can stop working before it expires. Try once more with a new token.
if (status === "Unauthorized") {
const newToken = getAccessToken(creds, true);
if (!newToken) {
return null;
}
apiResponse = callApi(identifier, newToken);
status = String(apiResponse.HttpStatus || "");
}
const body = parseJson(apiResponse.Content);
if (status === "TooManyRequests") {
throw new Error("TooManyRequests - the Court Register API is busy, the record will be retried");
}
if (status === "Unauthorized" || status === "Forbidden") {
throw new Error(
`The Court Register API rejected the credentials in the API Key field (HTTP ${status}). ` +
"If you have just registered, confirm your registration e-mail first."
);
}
const entity = Array.isArray(body) ? body[0] : body;
if (status === "OK" && entity && (entity.mbs || entity.potpuni_mbs) && getErrors(body).length === 0) {
return entity;
}
const errors = getErrors(body);
// Error 505: the request returned no rows (the entity isn't registered)
const reason = errors.length > 0 ? errors.map((x) => x.message).join(", ") : String(apiResponse.Content || "").substring(0, 200);
log(`The Court Register could not look up ${identifier.type.toUpperCase()} ${identifier.value}. HTTP ${status}. ${reason}`);
return null;
}
// Sections hold the current value directly, or (when the API returns history too) as a list of
// rows where status 1 is the current one.
function current(value) {
if (!value || typeof value !== "object") {
return null;
}
const keys = Object.keys(value);
if (keys.length === 1 && Array.isArray(value[keys[0]])) {
value = value[keys[0]];
}
if (Array.isArray(value)) {
for (let i = 0; i < value.length; i++) {
if (value[i] && (value[i].status === undefined || Number(value[i].status) === 1)) {
return value[i];
}
}
return null;
}
return value;
}
function list(value) {
if (Array.isArray(value)) {
return value.filter((x) => x && (x.status === undefined || Number(x.status) === 1));
}
const keys = value && typeof value === "object" ? Object.keys(value) : [];
return keys.length === 1 && Array.isArray(value[keys[0]]) ? list(value[keys[0]]) : [];
}
function formatAddress(seat) {
if (!seat) {
return null;
}
const number = [clean(seat.kucni_broj), clean(seat.kucni_podbroj)].filter((x) => !!x).join("");
const street = [clean(seat.ulica), number].filter((x) => !!x).join(" ");
const place = [clean(seat.postanski_broj), clean(seat.naziv_naselja) || clean(seat.naselje_van_sifrarnika)].filter((x) => !!x).join(" ");
const country = seat.drzava && clean(seat.drzava.oznaka_2) !== "HR" ? clean(seat.drzava.naziv) : null;
const lines = [street, place, country].filter((x) => !!x);
return lines.length > 0 ? lines.join(", ") : null;
}
function toData(entity) {
const name = current(entity.tvrtka) || {};
const shortName = current(entity.skracena_tvrtka) || {};
const legalForm = current(entity.pravni_oblik) || {};
const legalFormType = legalForm.vrsta_pravnog_oblika || {};
const seat = current(entity.sjediste);
const mainActivity = current(entity.pretezita_djelatnost) || {};
const activity = mainActivity.nacionalna_klasifikacija_djelatnosti || {};
const emails = list(entity.email_adrese);
const capitals = list(entity.temeljni_kapitali);
const capital = capitals.length > 0 ? capitals[0] : null;
const proceeding = current(entity.postupak) || {};
const court = entity.sud_nadlezan || {};
const deletionDate = dateOnly(entity.datum_brisanja);
const data = {
"sudreg.mbs": clean(entity.potpuni_mbs) || (entity.mbs ? ("000000000" + entity.mbs).slice(-9) : null),
"sudreg.oib": clean(entity.potpuni_oib) || (entity.oib ? ("00000000000" + entity.oib).slice(-11) : null),
"sudreg.name": clean(name.ime),
"sudreg.shortName": clean(shortName.ime),
"sudreg.legalForm": clean(legalFormType.naziv),
"sudreg.legalFormCode": clean(legalFormType.kratica),
"sudreg.address": formatAddress(seat),
"sudreg.postalCode": seat ? clean(seat.postanski_broj) : null,
"sudreg.city": seat ? clean(seat.naziv_naselja) || clean(seat.naselje_van_sifrarnika) : null,
"sudreg.municipality": seat ? clean(seat.naziv_opcine) : null,
"sudreg.county": seat ? clean(seat.naziv_zupanije) : null,
"sudreg.countryCode": seat && seat.drzava ? clean(seat.drzava.oznaka_2) : null,
"sudreg.industryCode": clean(activity.sifra),
"sudreg.industry": clean(activity.puni_naziv),
"sudreg.email": emails.length > 0 ? clean(emails[0].adresa) : null,
"sudreg.shareCapital": capital && typeof capital.iznos === "number" ? capital.iznos : null,
"sudreg.shareCapitalCurrency": capital && capital.valuta ? clean(capital.valuta.naziv) : null,
"sudreg.foundationDate": dateOnly(entity.datum_osnivanja),
"sudreg.court": clean(court.naziv),
"sudreg.proceeding": proceeding.postupak ? clean(proceeding.postupak.znacenje) : null,
"sudreg.bankruptcyDate": dateOnly(proceeding.datum_stecaja),
"sudreg.deleted": deletionDate ? true : null,
"sudreg.deletionDate": deletionDate,
};
// Leave out values the register didn't return, so they don't overwrite existing data with blanks.
Object.keys(data).forEach((key) => {
if (data[key] === null) {
delete data[key];
}
});
return data;
}
function run() {
const oib = parseOib(getValue(OIB_KEY));
const mbs = oib ? null : parseMbs(getValue(MBS_KEY));
if (!oib && !mbs) {
// No valid OIB or MBS on this record (this is also what Test connection hits, because it
// passes placeholder values instead of real ones).
return [];
}
const identifier = oib ? { type: "oib", value: oib } : { type: "mbs", value: mbs };
const creds = credentials();
if (!creds) {
log("The Court Register API needs credentials. Enter clientId:clientSecret in the enricher's API Key field.");
return [];
}
// The mapped properties are cached rather than the whole answer, which can be large.
const cacheKey = `sudreg:${identifier.type}:${identifier.value}`;
const cached = CACHE_MILLISECONDS > 0 ? cache.get(cacheKey) : null;
let data = cached ? parseJson(String(cached)) : null;
if (!data) {
const entity = lookUp(identifier, creds);
if (!entity) {
return [];
}
data = toData(entity);
if (CACHE_MILLISECONDS > 0) {
cache.set(cacheKey, JSON.stringify(data), CACHE_MILLISECONDS);
}
}
return [{ Data: data, Score: 100 }];
}
response = JSON.stringify(run());