---
title: National Court Register (Poland)
url: https://documentation.cluedin.net/govern/rest-api-enricher-samples/krs-poland
content_type: reference
section: Govern & improve > REST API enricher samples
---

# National Court Register (Poland)

> reference: Facts, options, APIs.

This example looks up an organization's KRS number in the Polish National Court Register (Krajowy Rejestr Sądowy, KRS) by using the Ministry of Justice's [open KRS API](https://prs.ms.gov.pl/krs/openApi). For each golden record it stores the registered name, legal form, NIP and REGON numbers, registered address, website, registration date, main PKD activity, share capital, and whether the entity has public benefit (OPP) status. No API key is needed.

**Enricher version:** V2  
**API key:** not needed

To set up the enricher, see [Add REST API enricher](https://documentation.cluedin.net/govern/enrichment/rest-api.md#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** – leave empty.

- **Filters** – we recommend a rule that only accepts golden records where `organization.krsNumber` has a value. Otherwise, every record without a KRS number is listed on the enricher's **Logs** tab as having returned no results.

## Vocabulary and Properties

```
organization.krsNumber
```

`organization.krsNumber` holds the 10-digit KRS number. If your data uses another vocabulary key, change this field and the `KRS_NUMBER_KEY` value at the top of the script.

## Request and response

**Base URL:** `https://api-krs.ms.gov.pl/api/krs`  
**Endpoint:** `GET /OdpisAktualny/{krsNumber}?rejestr={P|S}&format=json` (current extract)  
**Authentication:** none  
**Rate limits:** none published. Each request takes about 1–3 seconds.

KRS has two registers that the API serves separately: `P`, the register of entrepreneurs (companies), and `S`, the register of associations, foundations and other organizations. The script looks in `P` first and, if the number isn't found there (HTTP 404), in `S`:

```http
GET https://api-krs.ms.gov.pl/api/krs/OdpisAktualny/0000028860?rejestr=P&format=json
Accept: application/json
```

Shortened response (the full extract is 50–60 KB):

```json
{
  "odpis": {
    "rodzaj": "Aktualny",
    "naglowekA": {
      "rejestr": "RejP",
      "numerKRS": "0000028860",
      "stanZDnia": "30.11.2026",
      "dataRejestracjiWKRS": "19.07.2001",
      "dataOstatniegoWpisu": "09.10.2026"
    },
    "dane": {
      "dzial1": {
        "danePodmiotu": {
          "formaPrawna": "SPÓŁKA AKCYJNA",
          "identyfikatory": { "regon": "61018820100000", "nip": "7740001454" },
          "nazwa": "ORLEN SPÓŁKA AKCYJNA",
          "czyPosiadaStatusOPP": false
        },
        "siedzibaIAdres": {
          "siedziba": { "kraj": "POLSKA", "wojewodztwo": "MAZOWIECKIE", "powiat": "M. PŁOCK", "gmina": "M. PŁOCK", "miejscowosc": "PŁOCK" },
          "adres": { "ulica": "CHEMIKÓW", "nrDomu": "7", "miejscowosc": "PŁOCK", "kodPocztowy": "09-411", "poczta": "PŁOCK-BIAŁA", "kraj": "POLSKA" },
          "adresPocztyElektronicznej": "ZARZAD@ORLEN.PL",
          "adresStronyInternetowej": "WWW.ORLEN.PL"
        },
        "kapital": {
          "wysokoscKapitaluZakladowego": { "wartosc": "1451177561,25", "waluta": "PLN" }
        }
      },
      "dzial3": {
        "przedmiotDzialalnosci": {
          "przedmiotPrzewazajacejDzialalnosci": [
            { "opis": "WYTWARZANIE I PRZETWARZANIE PRODUKTÓW RAFINACJI ROPY NAFTOWEJ ORAZ PRODUKTÓW Z PALIW KOPALNYCH", "kodDzial": "19", "kodKlasa": "20", "kodPodklasa": "Z" }
          ]
        }
      }
    }
  }
}
```

## Properties added by the enricher

| Property | Response field | Example |
| -------- | -------------- | ------- |
| `krs.krsNumber` | `naglowekA.numerKRS` | `0000028860` |
| `krs.register` | `Entrepreneurs` (register `P`) or `Associations` (register `S`) | `Entrepreneurs` |
| `krs.name` | `danePodmiotu.nazwa` | `ORLEN SPÓŁKA AKCYJNA` |
| `krs.legalForm` | `danePodmiotu.formaPrawna` | `SPÓŁKA AKCYJNA` |
| `krs.nip` | `danePodmiotu.identyfikatory.nip` | `7740001454` |
| `krs.regon` | `danePodmiotu.identyfikatory.regon`; a 14-digit REGON ending in `00000` is shortened to 9 digits | `610188201` |
| `krs.address` | `siedzibaIAdres.adres`, on one line | `CHEMIKÓW 7, 09-411 PŁOCK-BIAŁA` |
| `krs.city` | `siedzibaIAdres.siedziba.miejscowosc` | `PŁOCK` |
| `krs.voivodeship` | `siedzibaIAdres.siedziba.wojewodztwo` | `MAZOWIECKIE` |
| `krs.postalCode` | `siedzibaIAdres.adres.kodPocztowy` | `09-411` |
| `krs.country` | `siedzibaIAdres.adres.kraj` | `POLSKA` |
| `krs.website` | `siedzibaIAdres.adresStronyInternetowej` | `WWW.ORLEN.PL` |
| `krs.email` | `siedzibaIAdres.adresPocztyElektronicznej` | `ZARZAD@ORLEN.PL` |
| `krs.registrationDate` | `naglowekA.dataRejestracjiWKRS`, as `YYYY-MM-DD` | `2001-07-19` |
| `krs.lastEntryDate` | `naglowekA.dataOstatniegoWpisu`, as `YYYY-MM-DD` | `2026-10-09` |
| `krs.mainActivityCode` | PKD code of the first `przedmiotPrzewazajacejDzialalnosci` entry | `19.20.Z` |
| `krs.mainActivity` | `opis` of that entry (in Polish) | `WYTWARZANIE I PRZETWARZANIE PRODUKTÓW RAFINACJI ROPY NAFTOWEJ ORAZ PRODUKTÓW Z PALIW KOPALNYCH` |
| `krs.shareCapital` | `kapital.wysokoscKapitaluZakladowego.wartosc`, with a decimal point | `1451177561.25` |
| `krs.shareCapitalCurrency` | `kapital.wysokoscKapitaluZakladowego.waluta` | `PLN` |
| `krs.publicBenefitOrganization` | `danePodmiotu.czyPosiadaStatusOPP` | `False` |

A property is added only when the register returns a value for it. Associations and foundations usually have no share capital or PKD activity.

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 `KRS` with the key prefix `krs`, 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, dashes, and a leading `KRS` are removed, and numbers that lost their leading zeros are padded to 10 digits, so `KRS 28860` is looked up as `0000028860`. Golden records without a valid number (1 to 10 digits, not all zeros) are skipped without calling the API.

- If the number isn't in either register (HTTP 404 from both), the script logs it and adds nothing.

- If the entity has been deleted from the register (wykreślony), the API answers HTTP 204 with no content. The script logs it and adds nothing.

- If the API returns another error, the script logs the reason, adds nothing, and doesn't try the other register.

- If the API 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 KRS number. Only the mapped properties are cached, not the whole extract. Not-found answers and errors aren't cached. To change this, edit `CACHE_MILLISECONDS` in the script.

## Testing the enricher

- **Test connection** checks only that the script runs. It doesn't call the API.

- To try the setup, create a golden record with `organization.krsNumber` set to `0000028860` (ORLEN S.A., register `P`) or `0000225587` (Polski Czerwony Krzyż, register `S`).

## Limitations

- KRS covers companies, partnerships, cooperatives, associations and foundations. Sole traders are registered in CEIDG, not KRS, so they can't be looked up with this script.

- Only the current extract is used. Deleted entities get no result; their history is available from the `OdpisPelny` (full extract) endpoint.

- Values are in Polish and in capital letters, as they are in the register.

- Board members, shareholders and branches aren't added. They are in other parts of the extract (`dzial2`, `jednostkiTerenoweOddzialy`).

## Process script

```javascript
// REST API enricher (V2) - Polish company lookup in the National Court Register (KRS)
//
// Looks up a golden record's KRS number in the Polish National Court Register (Krajowy Rejestr
// Sądowy), using the Ministry of Justice's open KRS API (https://prs.ms.gov.pl/krs/openApi), and
// adds the current extract (odpis aktualny) to the golden record as krs.* properties:
//
//   krs.krsNumber              10-digit KRS number that was looked up
//   krs.register               Entrepreneurs (rejestr przedsiębiorców) or Associations (rejestr
//                              stowarzyszeń, foundations and other organizations)
//   krs.name                   registered name
//   krs.legalForm              legal form, for example SPÓŁKA AKCYJNA
//   krs.nip                    NIP (tax identification number)
//   krs.regon                  REGON (statistical number), 9 digits for a head office
//   krs.address                registered address on one line
//   krs.city                   city of the registered office (siedziba)
//   krs.voivodeship            voivodeship (province) of the registered office
//   krs.postalCode             postal code of the registered address
//   krs.country                country of the registered address
//   krs.website                website
//   krs.email                  e-mail address
//   krs.registrationDate       date the entity was entered in KRS (YYYY-MM-DD)
//   krs.lastEntryDate          date of the latest entry in the register (YYYY-MM-DD)
//   krs.mainActivityCode       PKD code of the main activity, for example 19.20.Z
//   krs.mainActivity           description of the main activity (Polish)
//   krs.shareCapital           share capital, for example 1451177561.25
//   krs.shareCapitalCurrency   currency of the share capital, for example PLN
//   krs.publicBenefitOrganization "True" / "False" - has public benefit (OPP) status
//
// No API key is needed. See README.md next to this file for the enricher settings.
//
// A record gets no result (nothing is stored) when it has no valid KRS number, when the number
// isn't registered or the entity has been deleted from the register, or when the API can't answer.

// ---- Settings -------------------------------------------------------------------------

// Vocabulary key to read. Add the same key to the Vocabulary and Properties field.
const KRS_NUMBER_KEY = "organization.krsNumber";

const KRS_URL = "https://api-krs.ms.gov.pl/api/krs/OdpisAktualny/";

// How long to reuse an answer for the same KRS number. 0 turns caching off.
const CACHE_MILLISECONDS = 24 * 60 * 60 * 1000;

// ---- Script ---------------------------------------------------------------------------

// The two registers of KRS that the open API serves. The number is looked up in the first one,
// then in the second one if it isn't found there.
const REGISTERS = [
  { code: "P", name: "Entrepreneurs" },
  { code: "S", name: "Associations" },
];

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 "0000028860", "28860", "KRS 0000028860", "0000 028 860", etc. Returns the number as
// 10 digits, or null when it isn't a KRS number.
function parseKrsNumber(raw) {
  const text = raw.toUpperCase().replace(/^KRS/, "");
  if (/[A-Z]/.test(text)) {
    return null;
  }
  const digits = text.replace(/[^0-9]/g, "");
  if (digits.length < 1 || digits.length > 10 || /^0+$/.test(digits)) {
    return null;
  }
  return ("0000000000" + digits).slice(-10);
}

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;
  }
}

// KRS dates are DD.MM.YYYY. Returns YYYY-MM-DD, or null.
function toDate(value) {
  const match = /^(\d{2})\.(\d{2})\.(\d{4})$/.exec(clean(value) || "");
  return match ? `${match[3]}-${match[2]}-${match[1]}` : null;
}

// KRS amounts use a decimal comma, for example "1451177561,25".
function toAmount(value) {
  const text = clean(value);
  return text ? text.replace(/\s/g, "").replace(",", ".") : null;
}

// A 14-digit REGON ending in 00000 is the head office's 9-digit REGON.
function toRegon(value) {
  const text = clean(value);
  return text && /^\d{9}00000$/.test(text) ? text.substring(0, 9) : text;
}

// Returns the address on one line, for example "CHEMIKÓW 7, 09-411 PŁOCK".
function formatAddress(address) {
  if (!address) {
    return null;
  }
  const number = [clean(address.nrDomu), clean(address.nrLokalu)].filter((x) => !!x).join("/");
  const street = clean(address.ulica)
    ? [clean(address.ulica), number].filter((x) => !!x).join(" ")
    : [clean(address.miejscowosc), number].filter((x) => !!x).join(" ");
  const town = [clean(address.kodPocztowy), clean(address.poczta) || clean(address.miejscowosc)].filter((x) => !!x).join(" ");
  const lines = [street, town].filter((x) => !!x);
  if (clean(address.kraj) && address.kraj !== "POLSKA") {
    lines.push(clean(address.kraj));
  }
  return lines.length > 0 ? lines.join(", ") : null;
}

function formatActivityCode(activity) {
  const parts = [clean(activity.kodDzial), clean(activity.kodKlasa), clean(activity.kodPodklasa)].filter((x) => !!x);
  return parts.length > 0 ? parts.join(".") : null;
}

// Calls the API for one register. Returns { status, extract }.
function lookUpInRegister(krsNumber, register) {
  const apiResponse = http.send({
    url: `${KRS_URL}${krsNumber}?rejestr=${register.code}&format=json`,
    method: "GET",
    headers: [{ Key: "Accept", Value: "application/json" }],
  });

  const status = String(apiResponse.HttpStatus || "");
  const body = parseJson(apiResponse.Content);

  if (status === "TooManyRequests") {
    throw new Error("TooManyRequests - the KRS API is busy, the record will be retried");
  }

  if (status === "OK" && body && body.odpis && body.odpis.naglowekA && body.odpis.dane) {
    return { status: status, extract: body.odpis };
  }

  // NotFound and NoContent (deleted) are reported by lookUp.
  if (status !== "NotFound" && status !== "NoContent") {
    log(`KRS could not look up ${krsNumber} in register ${register.code}. HTTP ${status}. ${String(apiResponse.Content || "").substring(0, 200)}`);
  }
  return { status: status, extract: null };
}

// Returns { register, extract }, or null when there's no answer to store.
function lookUp(krsNumber) {
  for (let i = 0; i < REGISTERS.length; i++) {
    const answer = lookUpInRegister(krsNumber, REGISTERS[i]);
    if (answer.extract) {
      return { register: REGISTERS[i].name, extract: answer.extract };
    }
    if (answer.status === "NoContent") {
      // The number is in this register, but the entity has been deleted (wykreślony), so there
      // is no current extract.
      log(`KRS ${krsNumber} has been deleted from the register, so there is no current extract.`);
      return null;
    }
    if (answer.status !== "NotFound") {
      // An error: don't try the other register.
      return null;
    }
  }
  log(`KRS ${krsNumber} isn't registered.`);
  return null;
}

// Maps the current extract to krs.* properties, leaving out values the register didn't return.
function toData(krsNumber, register, extract) {
  const header = extract.naglowekA || {};
  const section1 = extract.dane.dzial1 || {};
  const section3 = extract.dane.dzial3 || {};
  const entity = section1.danePodmiotu || {};
  const ids = entity.identyfikatory || {};
  const seatAndAddress = section1.siedzibaIAdres || {};
  const seat = seatAndAddress.siedziba || {};
  const address = seatAndAddress.adres || null;
  const capital = (section1.kapital || {}).wysokoscKapitaluZakladowego || {};
  const activities = section3.przedmiotDzialalnosci || {};
  const mainActivities = Array.isArray(activities.przedmiotPrzewazajacejDzialalnosci) ? activities.przedmiotPrzewazajacejDzialalnosci : [];
  const mainActivity = mainActivities.length > 0 ? mainActivities[0] || {} : {};

  const data = {
    "krs.krsNumber": clean(header.numerKRS) || krsNumber,
    "krs.register": register,
    "krs.name": clean(entity.nazwa),
    "krs.legalForm": clean(entity.formaPrawna),
    "krs.nip": clean(ids.nip),
    "krs.regon": toRegon(ids.regon),
    "krs.address": formatAddress(address),
    "krs.city": clean(seat.miejscowosc),
    "krs.voivodeship": clean(seat.wojewodztwo),
    "krs.postalCode": address ? clean(address.kodPocztowy) : null,
    "krs.country": address ? clean(address.kraj) : clean(seat.kraj),
    "krs.website": clean(seatAndAddress.adresStronyInternetowej),
    "krs.email": clean(seatAndAddress.adresPocztyElektronicznej),
    "krs.registrationDate": toDate(header.dataRejestracjiWKRS),
    "krs.lastEntryDate": toDate(header.dataOstatniegoWpisu),
    "krs.mainActivityCode": formatActivityCode(mainActivity),
    "krs.mainActivity": clean(mainActivity.opis),
    "krs.shareCapital": toAmount(capital.wartosc),
    "krs.shareCapitalCurrency": clean(capital.waluta),
    "krs.publicBenefitOrganization": typeof entity.czyPosiadaStatusOPP === "boolean" ? entity.czyPosiadaStatusOPP : null,
  };

  Object.keys(data).forEach((key) => {
    if (data[key] === null) {
      delete data[key];
    }
  });
  return data;
}

function run() {
  const krsNumber = parseKrsNumber(getValue(KRS_NUMBER_KEY));
  if (!krsNumber) {
    // No valid KRS number on this record (this is also what Test connection hits, because it
    // passes placeholder values instead of real ones).
    return [];
  }

  // The mapped properties are cached, not the whole extract (which can be over 60 KB).
  const cacheKey = `krs:${krsNumber}`;
  const cached = CACHE_MILLISECONDS > 0 ? cache.get(cacheKey) : null;
  let data = cached ? parseJson(String(cached)) : null;

  if (!data) {
    const found = lookUp(krsNumber);
    if (!found) {
      return [];
    }
    data = toData(krsNumber, found.register, found.extract);
    if (CACHE_MILLISECONDS > 0) {
      cache.set(cacheKey, JSON.stringify(data), CACHE_MILLISECONDS);
    }
  }

  return [{ Data: data, Score: 100 }];
}

response = JSON.stringify(run());
```

Up: [REST API enricher samples](https://documentation.cluedin.net/govern/rest-api-enricher-samples.md)
