Skip to content

Tor2r/laravel-brreg-api

Repository files navigation

Laravel Brreg API

Latest Version on Packagist GitHub Tests Action Status Total Downloads

A Laravel package for fetching basic data from Brønnøysundregisteret (the Norwegian Register of Business Enterprises). Supports both Enhetsregisteret and Frivillighetsregisteret.

Requirements

  • PHP 8.2 or higher
  • Laravel 11 or 12

Installation

You can install the package via composer:

composer require tor2r/laravel-brreg-api

You can publish the config file with:

php artisan vendor:publish --tag="brreg-api-config"

This is the contents of the published config file:

return [
    'base_url' => env('BRREG_API_BASE_URL', 'https://data.brreg.no'),
    'results_per_page' => env('BRREG_API_RESULTS_PER_PAGE', 100),
];

Usage

Enhetsregisteret (Business Registry)

use Tor2r\BrregApi\Facades\BrregApi;

// Fetch a single entity by organisation number
$entity = BrregApi::getByOrgnr('987654321');

// Search by name
$results = BrregApi::searchByName('Sesam');

// Limit the number of results
$results = BrregApi::searchByName('Sesam', 10);

Frivillighetsregisteret (Voluntary Organisations Registry)

// Fetch a single voluntary organisation
$org = BrregApi::voluntary()->getByOrgnr('987654321');

// Search voluntary organisations by name
$results = BrregApi::voluntary()->searchByName('Frivillig');

Response Format

Single entity (getByOrgnr) returns a flat array with the entity data:

$entity = BrregApi::getByOrgnr('925183873');

// [
//     'organisasjonsnummer' => '925183873',
//     'navn' => 'FAGFOKUS AS',
//     'organisasjonsform' => [...],
//     'forretningsadresse' => [...],
//     'antallAnsatte' => 7,
//     ...
// ]

Search methods (searchByName) return a structured response with data and meta:

$results = BrregApi::searchByName('Fagfokus');

// [
//     'data' => [
//         [
//             'organisasjonsnummer' => '925183873',
//             'navn' => 'FAGFOKUS AS',
//             'antallAnsatte' => 7,
//             ...
//         ],
//     ],
//     'meta' => [
//         'per_page' => 100,
//         'total' => 1,
//         'total_pages' => 1,
//         'current_page' => 0,
//     ],
// ]

Internal API fields (_links, respons_klasse) are automatically stripped from responses.

Error Handling

The package throws Tor2r\BrregApi\Exceptions\BrregApiException when something goes wrong:

use Tor2r\BrregApi\Exceptions\BrregApiException;

try {
    $entity = BrregApi::getByOrgnr('000000000');
} catch (BrregApiException $e) {
    // "No entity found with organisation number: 000000000"
    echo $e->getMessage();
}

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.

About

Get data from Brønnøysundregisteret API

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages