PHPackages                             intermedia/ksef-api-v2 - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. intermedia/ksef-api-v2

ActiveLibrary[API Development](/categories/api)

intermedia/ksef-api-v2
======================

v0.11.5(4mo ago)9580↓26%MITPHPPHP &gt;=8.2

Since Sep 8Pushed 4mo ago3 watchersCompare

[ Source](https://github.com/tommekk83/ksef-api-v2)[ Packagist](https://packagist.org/packages/intermedia/ksef-api-v2)[ RSS](/packages/intermedia-ksef-api-v2/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (11)Versions (15)Used By (0)

intermedia/ksef-api-v2
======================

[](#intermediaksef-api-v2)

Developer-friendly &amp; type-safe Php SDK specifically catered to leverage *intermedia/ksef-api-v2* API.

 [![](https://camo.githubusercontent.com/afba42e3fd9e670de63d2590b751d3d91e9b8132e4eb40568ca34faa1166505c/68747470733a2f2f7777772e737065616b656173792e636f6d2f6173736574732f6261646765732f6275696c742d62792d737065616b656173792e737667)](https://www.speakeasy.com/?utm_source=intermedia/ksef-api-v2&utm_campaign=php) [ ![](https://camo.githubusercontent.com/08cef40a9105b6526ca22088bc514fbfdbc9aac1ddbf8d4e6c750e3a88a44dca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e737667) ](https://opensource.org/licenses/MIT)

Summary
-------

[](#summary)

KSeF API TR: **Wersja API:** 2.0.0 (build 2.0.0-tr-20251229.1+4e064b0f8497598eeb393ab74ab9a5ada61f64a5)
**Klucze publiczne** Ministerstwa Finansów (dla danego środowiska): [Pobierz klucze](#tag/Certyfikaty-klucza-publicznego)
**Historia zmian:** [Changelog](https://github.com/CIRFMF/ksef-docs/blob/main/api-changelog.md)
**Rozszerzona dokumentacja API:** [ksef-docs](https://github.com/CIRFMF/ksef-docs/tree/main)

**Adres serwera API:**

- Środowisko DEMO: `https://api-demo.ksef.mf.gov.pl/v2`
- \[deprecated\] Środowisko DEMO: `https://ksef-demo.mf.gov.pl/api/v2`

Table of Contents
-----------------

[](#table-of-contents)

- [intermedia/ksef-api-v2](#intermediaksef-api-v2)
    - [SDK Installation](#sdk-installation)
    - [SDK Example Usage](#sdk-example-usage)
    - [Authentication](#authentication)
    - [Available Resources and Operations](#available-resources-and-operations)
    - [Error Handling](#error-handling)
    - [Server Selection](#server-selection)
- [Development](#development)
    - [Maturity](#maturity)
    - [Contributions](#contributions)

SDK Installation
----------------

[](#sdk-installation)

The SDK relies on [Composer](https://getcomposer.org/) to manage its dependencies.

To install the SDK and add it as a dependency to an existing `composer.json` file:

```
composer require "intermedia/ksef-api-v2"
```

SDK Example Usage
-----------------

[](#sdk-example-usage)

### Example

[](#example)

```
declare(strict_types=1);

require 'vendor/autoload.php';

use Intermedia\Ksef\Apiv2;

$sdk = Apiv2\Client::builder()
    ->setSecurity(
        ''
    )
    ->build();

$response = $sdk->auth->getCurrentSessions(
    pageSize: 10
);

if ($response->authenticationListResponse !== null) {
    // handle response
}
```

### AuthTokenRequest XML generation with XAdES signature example

[](#authtokenrequest-xml-generation-with-xades-signature-example)

```
declare(strict_types=1);

require 'vendor/autoload.php';

use Intermedia\Ksef\Apiv2\AuthTokenRequest;
use Intermedia\Ksef\Apiv2\Models\Components\{TContextIdentifier, TNip, SubjectIdentifierTypeEnum};

$req = new AuthTokenRequest(
    '20250625-CR-20F5EE4000-DA48AE4124-46',
    TContextIdentifier::fromNip(new TNip('5265877635')),
    SubjectIdentifierTypeEnum::CERTIFICATE_SUBJECT
);

// PEM Signature (private key and public certificate in separate files)
$signedXml = $req->signWithXadesToString('/path/to/private.pem', '/path/to/cert.pem');

// or PKCS#12 (private key and public certificate in one .p12 file)
$signedXml = $req->signWithXadesToString('/path/to/cert.p12', null, 'password_to_p12');
```

Authentication
--------------

[](#authentication)

### Per-Client Security Schemes

[](#per-client-security-schemes)

This SDK supports the following security scheme globally:

NameTypeScheme`bearer`httpHTTP BearerTo authenticate with the API the `bearer` parameter must be set when initializing the SDK. For example:

```
declare(strict_types=1);

require 'vendor/autoload.php';

use Intermedia\Ksef\Apiv2;

$sdk = Apiv2\Client::builder()
    ->setSecurity(
        ''
    )
    ->build();

$response = $sdk->auth->getCurrentSessions(
    pageSize: 10
);

if ($response->authenticationListResponse !== null) {
    // handle response
}
```

Available Resources and Operations
----------------------------------

[](#available-resources-and-operations)

Available methods### [Auth](docs/sdks/auth/README.md)

[](#auth)

- [getCurrentSessions](docs/sdks/auth/README.md#getcurrentsessions) - Pobranie listy aktywnych sesji
- [revokeCurrentSession](docs/sdks/auth/README.md#revokecurrentsession) - Unieważnienie aktualnej sesji uwierzytelnienia
- [revokeSession](docs/sdks/auth/README.md#revokesession) - Unieważnienie sesji uwierzytelnienia
- [challenge](docs/sdks/auth/README.md#challenge) - Inicjalizacja uwierzytelnienia
- [withXades](docs/sdks/auth/README.md#withxades) - Uwierzytelnienie z wykorzystaniem podpisu XAdES
- [withKsefToken](docs/sdks/auth/README.md#withkseftoken) - Uwierzytelnienie z wykorzystaniem tokena KSeF
- [getStatus](docs/sdks/auth/README.md#getstatus) - Pobranie statusu uwierzytelniania
- [redeemToken](docs/sdks/auth/README.md#redeemtoken) - Pobranie tokenów dostępowych
- [refreshToken](docs/sdks/auth/README.md#refreshtoken) - Odświeżenie tokena dostępowego

### [Certificates](docs/sdks/certificates/README.md)

[](#certificates)

- [getLimits](docs/sdks/certificates/README.md#getlimits) - Pobranie danych o limitach certyfikatów
- [getEnrollmentData](docs/sdks/certificates/README.md#getenrollmentdata) - Pobranie danych do wniosku certyfikacyjnego
- [processEnrollment](docs/sdks/certificates/README.md#processenrollment) - Wysyłka wniosku certyfikacyjnego
- [getEnrollmentStatus](docs/sdks/certificates/README.md#getenrollmentstatus) - Pobranie statusu przetwarzania wniosku certyfikacyjnego
- [retrieve](docs/sdks/certificates/README.md#retrieve) - Pobranie certyfikatu lub listy certyfikatów
- [revoke](docs/sdks/certificates/README.md#revoke) - Unieważnienie certyfikatu
- [getList](docs/sdks/certificates/README.md#getlist) - Pobranie listy metadanych certyfikatów

### [Invoices](docs/sdks/invoices/README.md)

[](#invoices)

- [getByKsefNumber](docs/sdks/invoices/README.md#getbyksefnumber) - Pobranie faktury po numerze KSeF
- [getList](docs/sdks/invoices/README.md#getlist) - Pobranie listy metadanych faktur
- [export](docs/sdks/invoices/README.md#export) - Eksport paczki faktur
- [getExportStatus](docs/sdks/invoices/README.md#getexportstatus) - Pobranie statusu eksportu paczki faktur

### [Limits](docs/sdks/limits/README.md)

[](#limits)

- [getContext](docs/sdks/limits/README.md#getcontext) - Pobranie limitów dla bieżącego kontekstu
- [getSubject](docs/sdks/limits/README.md#getsubject) - Pobranie limitów dla bieżącego podmiotu
- [getApiRate](docs/sdks/limits/README.md#getapirate) - Pobranie aktualnie obowiązujących limitów API

### [Peppol](docs/sdks/peppol/README.md)

[](#peppol)

- [listProviders](docs/sdks/peppol/README.md#listproviders) - Pobranie listy dostawców usług Peppol

### [Permissions](docs/sdks/permissions/README.md)

[](#permissions)

- [grantToPersons](docs/sdks/permissions/README.md#granttopersons) - Nadanie osobom fizycznym uprawnień do pracy w KSeF
- [grantToEntities](docs/sdks/permissions/README.md#granttoentities) - Nadanie podmiotom uprawnień do obsługi faktur
- [grantAuthorizations](docs/sdks/permissions/README.md#grantauthorizations) - Nadanie uprawnień podmiotowych
- [grantIndirectly](docs/sdks/permissions/README.md#grantindirectly) - Nadanie uprawnień w sposób pośredni
- [grantToSubunits](docs/sdks/permissions/README.md#granttosubunits) - Nadanie uprawnień administratora podmiotu podrzędnego
- [grantRights](docs/sdks/permissions/README.md#grantrights) - Nadanie uprawnień administratora podmiotu unijnego
- [grantToEuEntities](docs/sdks/permissions/README.md#granttoeuentities) - Nadanie uprawnień reprezentanta podmiotu unijnego
- [revoke](docs/sdks/permissions/README.md#revoke) - Odebranie uprawnień
- [revokeAuthorizations](docs/sdks/permissions/README.md#revokeauthorizations) - Odebranie uprawnień podmiotowych
- [getOperationStatus](docs/sdks/permissions/README.md#getoperationstatus) - Pobranie statusu operacji
- [checkAttachmentStatus](docs/sdks/permissions/README.md#checkattachmentstatus) - Sprawdzenie statusu zgody na wystawianie faktur z załącznikiem
- [getPersonalGrants](docs/sdks/permissions/README.md#getpersonalgrants) - Pobranie listy własnych uprawnień
- [getPersonGrants](docs/sdks/permissions/README.md#getpersongrants) - Pobranie listy uprawnień do pracy w KSeF nadanych osobom fizycznym lub podmiotom
- [getSubunitsGrants](docs/sdks/permissions/README.md#getsubunitsgrants) - Pobranie listy uprawnień administratorów jednostek i podmiotów podrzędnych
- [getEntityRoles](docs/sdks/permissions/README.md#getentityroles) - Pobranie listy ról podmiotu
- [getSubordinateEntitiesRoles](docs/sdks/permissions/README.md#getsubordinateentitiesroles) - Pobranie listy podmiotów podrzędnych
- [getAuthorizationsGrants](docs/sdks/permissions/README.md#getauthorizationsgrants) - Pobranie listy uprawnień podmiotowych do obsługi faktur
- [getEuEntityGrants](docs/sdks/permissions/README.md#geteuentitygrants) - Pobranie listy uprawnień administratorów lub reprezentantów podmiotów unijnych uprawnionych do samofakturowania

### [Security](docs/sdks/security/README.md)

[](#security)

- [getPublicKeyCertificates](docs/sdks/security/README.md#getpublickeycertificates) - Pobranie certyfikatów

### [Sessions](docs/sdks/sessions/README.md)

[](#sessions)

- [getList](docs/sdks/sessions/README.md#getlist) - Pobranie listy sesji
- [getStatus](docs/sdks/sessions/README.md#getstatus) - Pobranie statusu sesji
- [getUpo](docs/sdks/sessions/README.md#getupo) - Pobranie UPO dla sesji
- [openOnline](docs/sdks/sessions/README.md#openonline) - Otwarcie sesji interaktywnej
- [closeOnline](docs/sdks/sessions/README.md#closeonline) - Zamknięcie sesji interaktywnej
- [openBatch](docs/sdks/sessions/README.md#openbatch) - Otwarcie sesji wsadowej
- [closeBatch](docs/sdks/sessions/README.md#closebatch) - Zamknięcie sesji wsadowej

#### [Sessions.Invoices](docs/sdks/sessionsinvoices/README.md)

[](#sessionsinvoices)

- [getList](docs/sdks/sessionsinvoices/README.md#getlist) - Pobranie faktur sesji
- [getStatus](docs/sdks/sessionsinvoices/README.md#getstatus) - Pobranie statusu faktury z sesji
- [getFailed](docs/sdks/sessionsinvoices/README.md#getfailed) - Pobranie niepoprawnie przetworzonych faktur sesji
- [getInvoiceUpoByKsefNumber](docs/sdks/sessionsinvoices/README.md#getinvoiceupobyksefnumber) - Pobranie UPO faktury z sesji na podstawie numeru KSeF
- [getUpo](docs/sdks/sessionsinvoices/README.md#getupo) - Pobranie UPO faktury z sesji na podstawie numeru referencyjnego faktury
- [sendOnline](docs/sdks/sessionsinvoices/README.md#sendonline) - Wysłanie faktury

### [Tokens](docs/sdks/tokens/README.md)

[](#tokens)

- [generate](docs/sdks/tokens/README.md#generate) - Wygenerowanie nowego tokena
- [getList](docs/sdks/tokens/README.md#getlist) - Pobranie listy wygenerowanych tokenów
- [getStatus](docs/sdks/tokens/README.md#getstatus) - Pobranie statusu tokena
- [revoke](docs/sdks/tokens/README.md#revoke) - Unieważnienie tokena

Error Handling
--------------

[](#error-handling)

Handling errors in this SDK should largely match your expectations. All operations return a response object or throw an exception.

By default an API error will raise a `Errors\APIException` exception, which has the following properties:

PropertyTypeDescription`$message`*string*The error message`$statusCode`*int*The HTTP status code`$rawResponse`*?\\Psr\\Http\\Message\\ResponseInterface*The raw HTTP response`$body`*string*The response contentWhen custom error responses are specified for an operation, the SDK may also throw their associated exception. You can refer to respective *Errors* tables in SDK docs for more details on possible exception types for each operation. For example, the `getCurrentSessions` method throws the following exceptions:

Error TypeStatus CodeContent TypeErrors\\ExceptionResponse400application/jsonErrors\\TooManyRequestsResponseException429application/jsonErrors\\APIException4XX, 5XX\*/\*### Example

[](#example-1)

```
declare(strict_types=1);

require 'vendor/autoload.php';

use Intermedia\Ksef\Apiv2;
use Intermedia\Ksef\Apiv2\Models\Errors;

$sdk = Apiv2\Client::builder()
    ->setSecurity(
        ''
    )
    ->build();

try {
    $response = $sdk->auth->getCurrentSessions(
        pageSize: 10
    );

    if ($response->authenticationListResponse !== null) {
        // handle response
    }
} catch (Errors\ExceptionResponseThrowable $e) {
    // handle $e->$container data
    throw $e;
} catch (Errors\TooManyRequestsResponseExceptionThrowable $e) {
    // handle $e->$container data
    throw $e;
} catch (Errors\APIException $e) {
    // handle default exception
    throw $e;
}
```

Server Selection
----------------

[](#server-selection)

### Select Server by Index

[](#select-server-by-index)

You can override the default server globally using the `setServerIndex(int $serverIdx)` builder method when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:

\#ServerDescription0`https://api-demo.ksef.mf.gov.pl/v2`Środowisko DEMO1`https://ksef-demo.mf.gov.pl/api/v2`\[deprecated\] Środowisko DEMO#### Example

[](#example-2)

```
declare(strict_types=1);

require 'vendor/autoload.php';

use Intermedia\Ksef\Apiv2;

$sdk = Apiv2\Client::builder()
    ->setServerIndex(0)
    ->setSecurity(
        ''
    )
    ->build();

$response = $sdk->auth->getCurrentSessions(
    pageSize: 10
);

if ($response->authenticationListResponse !== null) {
    // handle response
}
```

### Override Server URL Per-Client

[](#override-server-url-per-client)

The default server can also be overridden globally using the `setServerUrl(string $serverUrl)` builder method when initializing the SDK client instance. For example:

```
declare(strict_types=1);

require 'vendor/autoload.php';

use Intermedia\Ksef\Apiv2;

$sdk = Apiv2\Client::builder()
    ->setServerURL('https://ksef-demo.mf.gov.pl/api/v2')
    ->setSecurity(
        ''
    )
    ->build();

$response = $sdk->auth->getCurrentSessions(
    pageSize: 10
);

if ($response->authenticationListResponse !== null) {
    // handle response
}
```

Development
===========

[](#development)

Maturity
--------

[](#maturity)

This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.

Contributions
-------------

[](#contributions)

While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation. We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.

### SDK Created by [Speakeasy](https://www.speakeasy.com/?utm_source=intermedia/ksef-api-v2&utm_campaign=php)

[](#sdk-created-by-speakeasy)

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance76

Regular maintenance activity

Popularity24

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~9 days

Recently: every ~16 days

Total

14

Last Release

132d ago

PHP version history (2 changes)v0.3.29PHP &gt;=8.2

v0.3.33PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/5f1fc8c67f77ed70a60610cf83536d4f9a323ead0cdef3813f1f4f90609309a1?d=identicon)[gsmservice](/maintainers/gsmservice)

---

Top Contributors

[![tommekk83](https://avatars.githubusercontent.com/u/130782947?v=4)](https://github.com/tommekk83 "tommekk83 (30 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/intermedia-ksef-api-v2/health.svg)

```
[![Health](https://phpackages.com/badges/intermedia-ksef-api-v2/health.svg)](https://phpackages.com/packages/intermedia-ksef-api-v2)
```

###  Alternatives

[clerkinc/backend-php

2755.0k](/packages/clerkinc-backend-php)[polar-sh/sdk

4014.5k4](/packages/polar-sh-sdk)[wheelpros/fitment-platform-api

Magento 2 (Open Source)

12.1k1.2k](/packages/wheelpros-fitment-platform-api)[packbackbooks/lti-1p3-tool

A library used for building IMS-certified LTI 1.3 tool providers in PHP.

51438.3k2](/packages/packbackbooks-lti-1p3-tool)[yoti/yoti-php-sdk

Yoti SDK for quickly integrating your PHP backend with Yoti

27539.9k1](/packages/yoti-yoti-php-sdk)[hoels/app-store-server-library-php

The PHP server library for the App Store Server API and App Store Server Notifications.

44162.2k](/packages/hoels-app-store-server-library-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
