Gusex
Elixir client for Polish Business Registry Service (GUS BIR) Gusex is an Elixir library that provides access to the Polish Central Statistical Office (GUS) BIR (Baza Internetowa Regon) service. It enables developers to programmatically retrieve data about business entities from Polish registries including CEIDG, KRS, and RSPO, which are synchronised into the BIR database.
Features
- All officially exposed BIR service methods supported
- Search businesses by REGON, NIP, or KRS identifiers
- Retrieve full business reports and aggregate data
- Elixir structs for many data types
- Support for both test and production environments
- Uses the required SOAP 1.2 protocol with handcrafted MTOM support
- Extensive error handling and validation
Installation
If available in Hex, the package can be installed
by adding gusex to your list of dependencies in mix.exs:
def deps do
[
{:gusex, "~> 1.0"}
]
endThen run:
mix deps.getConfiguration
config :gusex,
api_key: "your_production_api_key",
environment: :production # or :testFor testing, you can use the test environment:
config :gusex,
api_key: "abcde12345abcde12345", # Test API key
environment: :testalthough it is default if not specified and in dev or test environment.
Quick Start
# Login to the service and obtain a session (uses test environment by default; configure with valid API key for production environment)
{:ok, session} = Gusex.zaloguj()
# Search for entities by REGON (using ParametryWyszukiwania struct)
search_params = %Gusex.Types.ParametryWyszukiwania{Regon: "000331501"}
{:ok, entities} = Gusex.dane_szukaj_podmioty(search_params, session)
# or (using simple map with atom keys - error will be returned for invalid or non-atom keys)
{:ok, entities} = Gusex.dane_szukaj_podmioty(%{Regon: "000331501"}, session)
# Get detailed report for an entity
{:ok, report} = Gusex.dane_pobierz_pelny_raport("000331501", "BIR12OsPrawna", session)
# Logout
{:ok, true} = Gusex.wyloguj(session)API Reference
Authentication
zaloguj/2
Authenticates with the BIR service and establishes a session.
# Using configured or default (for GUS test environment) credentials
{:ok, session} = Gusex.zaloguj()
# Using explicit credentials and environment (you shouldn't do this in production code)
{:ok, session} = Gusex.zaloguj("your_api_key", :production)Returns:{:ok, %Gusex.Types.Session{}} or {:error, reason}
Entity Search
dane_szukaj_podmioty/2
Searches for business entities using various identifier types.
# Search by REGON (9 or 14 digits)
search_params = %Gusex.Types.ParametryWyszukiwania{Regon: "000331501"}
{:ok, entities} = Gusex.dane_szukaj_podmioty(search_params, session)
# Search by NIP (Tax ID)
search_params = %Gusex.Types.ParametryWyszukiwania{Nip: "5260001246"}
{:ok, entities} = Gusex.dane_szukaj_podmioty(search_params, session)
# Search by KRS (Court Register number)
search_params = %Gusex.Types.ParametryWyszukiwania{Krs: "0000028860"}
{:ok, entities} = Gusex.dane_szukaj_podmioty(search_params, session)
# Multiple search (up to 20 entities)
search_params = %Gusex.Types.ParametryWyszukiwania{
Regony9zn: "000331501,123456789",
Nipy: "5260001246,1234567890"
}
{:ok, entities} = Gusex.dane_szukaj_podmioty(search_params, session)Returns:{:ok, [%Gusex.Types.Podmiot{}]} or {:error, error_data}
Detailed Reports
dane_pobierz_pelny_raport/3
Retrieves detailed information about a specific entity.
# Legal entities (companies)
{:ok, company_data} = Gusex.dane_pobierz_pelny_raport("000331501", "BIR12OsPrawna", session)
# Natural persons - general data
{:ok, person_data} = Gusex.dane_pobierz_pelny_raport("12345678901234", "BIR12OsFizycznaDaneOgolne", session)
# Natural persons - CEIDG business activity
{:ok, ceidg_data} = Gusex.dane_pobierz_pelny_raport("12345678901234", "BIR12OsFizycznaDzialalnoscCeidg", session)
# Local units of legal entities
{:ok, local_unit} = Gusex.dane_pobierz_pelny_raport("12345678901234", "BIR12JednLokalnaOsPrawnej", session)Available Report Types:
BIR12JednLokalnaOsFizycznejBIR12JednLokalnaOsFizycznejPkdBIR12JednLokalnaOsPrawnejBIR12JednLokalnaOsPrawnejPkdBIR12OsFizycznaDaneOgolneBIR12OsFizycznaDzialalnoscCeidgBIR12OsFizycznaDzialalnoscPozostalaBIR12OsFizycznaDzialalnoscRolniczaBIR12OsFizycznaDzialalnoscSkreslonaDo20141108BIR12OsFizycznaListaJednLokalnychBIR12OsFizycznaPkdBIR12OsPrawnaBIR12OsPrawnaListaJednLokalnychBIR12OsPrawnaPkdBIR12OsPrawnaSpCywilnaWspolnicyBIR12TypPodmiotu
Aggregate Reports
dane_pobierz_raport_zbiorczy/3
Retrieves aggregate reports with lists of entities modified on a specific date.
# New legal entities and individual business activities
{:ok, new_entities} = Gusex.dane_pobierz_raport_zbiorczy(
"2014-01-15",
"BIR11NowePodmiotyPrawneOrazDzialalnosciOsFizycznych",
session
)Available Aggregate Reports:
BIR11AktualizowaneJednostkiLokalneBIR11AktualizowanePodmiotyPrawneOrazDzialalnosciOsFizycznychBIR11NoweJednostkiLokalneBIR11NowePodmiotyPrawneOrazDzialalnosciOsFizycznychBIR11SkresloneJednostkiLokalneBIR11SkreslonePodmiotyPrawneOrazDzialalnosciOsFizycznych
Service Information
get_value/2
Retrieves service diagnostic information.
# Get service status message (no session required)
{:ok, service_message} = Gusex.get_value("KomunikatUslugi")
# Get session status (requires active session)
{:ok, session_status} = Gusex.get_value("StatusSesji", session)wyloguj/1
Terminates the active session.
{:ok, true} = Gusex.wyloguj(session)Data Types and Structures
Core Types
# Session information
%Gusex.Types.Session{
id: "abcdef1234567890abcd",
environment: :test,
endpoint_url: "https://wyszukiwarkaregontest.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc"
}
# Search parameters
%Gusex.Types.ParametryWyszukiwania{
Regon: "000331501",
Nip: nil,
Krs: nil,
Regony9zn: nil,
Regony14zn: nil,
Nipy: nil,
Krsy: nil
}
# Entity information
%Gusex.Types.Podmiot{
Regon: "000331501",
Nip: "5260001246",
StatusNip: "",
Nazwa: "GŁÓWNY URZĄD STATYSTYCZNY",
Typ: "P", # P = Legal entity, F = Natural person
SilosID: "6"
}Entity Types
P- Legal entity (Osoba prawna)F- Natural person conducting business activityLP- Local unit of legal entityLF- Local unit of natural person
Activity Types (SilosID)
1- CEIDG registered activity2- Agricultural activity3- Other business activity4- Activity deleted before 2014-11-086- Legal entity activity
Environment Setup
Test Environment
- Endpoint:
https://wyszukiwarkaregontest.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc - WSDL:
https://wyszukiwarkaregontest.stat.gov.pl/wsBIR/wsdl/UslugaBIRzewnPubl-ver11-test.wsdl - API Key:
abcde12345abcde12345(public test key) - Data: Partially anonymised data from November 8, 2014
Production Environment
Registration: Email
regon_bir@stat.gov.plwith:Organisation name and REGON/NIP
Contact person details
Phone numbers
Expected concurrent users
IP addresses (if applicable)
Endpoint:
https://wyszukiwarkaregon.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc
Error Handling
The library provides comprehensive error handling for various scenarios:
case Gusex.zaloguj("api_key", :production) do
{:ok, session} ->
# Success
session
{:error, :api_key_missing} ->
# No API key provided or configured
handle_missing_key()
{:error, :login_failure} ->
# Invalid credentials or service unavailable
handle_login_failure()
{:error, reason} ->
# Other errors (network, parsing, etc.)
handle_error(reason)
endTechnical Notes
Session Management
- Sessions automatically expire after 60 minutes
- Daily maintenance at 3:20 AM closes all active sessions
Data Security
- Returned data may contain executable code (HTML/JavaScript/SQL)
- Always sanitise and validate data before displaying or storing
- Implement proper input filtering to prevent XSS/SQL injection
Rate Limiting
- No automatic sequential ID scanning allowed
- Respect service limits and usage guidelines
- Maximum 20 entities per bulk search request
Dependencies
- httpoison - HTTP client for SOAP requests
- sweet_xml - XML parsing and manipulation
- exvcr - HTTP request recording for tests (test only)
- credo - Static code analysis (dev/test only)
- mock - Mocking support for tests (test only)
Documentation
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/gusex.
Contributing
- Fork the repository
-
Create your feature branch (
git checkout -b feature/amazing-feature) -
Make your changes following the existing code style (do NOT run
mix format) - Add tests for new functionality
-
Run tests and ensure they pass (
mix test) -
Run static analysis (
mix credo) - Commit your changes
- Push to the branch
- Open a Pull Request
License
This project is licensed under the MIT License - see the LICENCE file for details.
Support
For issues, questions, or contributions, please visit the BitBucket repository.
Note: This library provides access to official Polish government business registry data. Ensure compliance with applicable data protection regulations and service terms of use.