{"id":449,"date":"2024-04-02T16:31:03","date_gmt":"2024-04-02T14:31:03","guid":{"rendered":"https:\/\/ksefapi.pl\/?page_id=449"},"modified":"2026-03-27T21:39:26","modified_gmt":"2026-03-27T20:39:26","slug":"rest-ksef-api-dokumentacja","status":"publish","type":"page","link":"https:\/\/ksefapi.pl\/en\/rest-ksef-api-dokumentacja\/","title":{"rendered":"REST API KSeF \u2013 documentation"},"content":{"rendered":"<h1 style=\"text-align: center;\">KSeF REST API \u2013 technical (integration) documentation <br \/>for the National e-Invoice System<\/h1>\r\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/ksefapi.pl\/wp-content\/uploads\/2024\/01\/logo-no-background_mini.png\" alt=\"KSeF API logo\" width=\"150\" height=\"152\" class=\"size-full wp-image-328 alignnone\" srcset=\"https:\/\/ksefapi.pl\/wp-content\/uploads\/2024\/01\/logo-no-background_mini.png 150w, https:\/\/ksefapi.pl\/wp-content\/uploads\/2024\/01\/logo-no-background_mini-12x12.png 12w\" sizes=\"(max-width: 150px) 100vw, 150px\" \/><\/p>\r\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_76 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewbox=\"0 0 24 24\" version=\"1.2\" baseprofile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/ksefapi.pl\/en\/rest-ksef-api-dokumentacja\/#Wprowadzenie\" >Introduction<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/ksefapi.pl\/en\/rest-ksef-api-dokumentacja\/#Rejestracja_i_utworzenie_konta\" >Registration and account creation<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/ksefapi.pl\/en\/rest-ksef-api-dokumentacja\/#Srodowiska\" >Environment<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/ksefapi.pl\/en\/rest-ksef-api-dokumentacja\/#Srodowisko_testowe\" >Testing environment<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/ksefapi.pl\/en\/rest-ksef-api-dokumentacja\/#Srodowisko_produkcyjne\" >Production environment<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/ksefapi.pl\/en\/rest-ksef-api-dokumentacja\/#Uwierzytelnienie_i_autoryzacja_zapytan\" >Authentication and authorization of queries<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/ksefapi.pl\/en\/rest-ksef-api-dokumentacja\/#Uwierzytelnienie_Basic_Authentication\" >Basic Authentication<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/ksefapi.pl\/en\/rest-ksef-api-dokumentacja\/#Kliknij_tutaj_aby_zobaczyc_dalsza_czesc_dokumentacji_KSeF_REST_API_ktora_zostala_udostepniona_na_dedykowanej_witrynie\" >Click here to see the rest of the KSeF REST API documentation which is available on a dedicated website<\/a><\/li><\/ul><\/nav><\/div>\n\r\n<h2 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"Wprowadzenie\"><\/span>Introduction<span class=\"ez-toc-section-end\"><\/span><\/h2>\r\n<p>This documentation describes the REST API interface enabling comprehensive implementation of structured invoice handling in the KSeF system.<\/p>\r\n<p>The detailed API definition is available in an OpenAPI-compatible format and can be downloaded as a file <code><a href=\"https:\/\/ksefapi.pl\/public\/rest\/ksefapi-api.yaml\"><strong>JSON<\/strong><\/a><\/code>.<\/p>\r\n<p class=\" translation-block\">The API is also available in the form of a client interface <code><strong><a href=\"https:\/\/ksefapi.pl\/api-test\/swagger-ui\/index.html#\/\" target=\"_self\">Swagger UI<\/a><\/strong><\/code>.<\/p>\r\n<h3 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"Rejestracja_i_utworzenie_konta\"><\/span>Registration and account creation<span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n<p>In order to test the capabilities of the REST KSEF API, it is necessary to complete the registration process, i.e. create a dedicated account on the website. To do this, please visit the website <a href=\"https:\/\/ksefapi.pl\/portal-test\/register\/\"><code><strong>Registration<\/strong><\/code><\/a> and fill in the appropriate form. The necessary condition for using the service system is acceptance of the Regulations. Correct completion of the form and clicking the button <em>Register<\/em> creates an account in the system and automatically activates it.<\/p>\r\n<p>During the first login, an ID and the corresponding key are generated automatically. The ID and key can be found after logging in to your account in the tab <em>API keys<\/em>. The identifier is public and does not require protection, while the key is private and should not be made available to third parties.<\/p>\r\n<p><strong>Attention<\/strong>! To use the operations provided in the REST KSEF API, you must save the access token generated for the KSeF production or test environment, respectively, and enable access to the given type of environment.<\/p>\r\n<h3 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"Srodowiska\"><\/span>Environment<span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n<p>To facilitate integration for our clients in the area of KSeF invoices, we have prepared two identical environments: test and production, which are connected to the KSeF test and production environments.<\/p>\r\n<h4><span class=\"ez-toc-section\" id=\"Srodowisko_testowe\"><\/span>Testing environment<span class=\"ez-toc-section-end\"><\/span><\/h4>\r\n<p>Full functionality of all exposed operations in the REST KSEF API and <a href=\"\/en\/pobierz-ksef-php-java-net\/\">libraries<\/a>, you can check using the provided test environment.<\/p>\r\n<p>Testing environment <a href=\"#post-449-BKM_8B8E7387_2644_4057_9B27_0DDAFD03F5A8\">REST KSEF API<\/a> is integrated with the environment <a href=\"https:\/\/ksef-test.mf.gov.pl\/\"><span style=\"text-decoration: underline;\"><strong>test<\/strong><\/span> <strong>National e-Invoice System<\/strong><\/a> and is available at: <code>https:\/\/ksefapi.pl\/api-test\/<\/code><strong><\/strong><\/p>\r\n<p>All operations available within the KSEF API REST environment are also available from the shared level <a href=\"\/en\/pobierz-ksef-php-java-net\/\">libraries<\/a>.<\/p>\r\n<p>Thanks to the REST KSEF API test environment, it is possible to check all operations offered in paid KSeF packages, <b><span style=\"text-decoration: underline;\">without having to buy them<\/span>.<br \/><\/b><\/p>\r\n<p><strong>Attention<\/strong>! To use the KSEF API REST operations in a test environment, simply save the access token generated in the KSeF test environment and activate access to this type of environment.<\/p>\r\n<h4><span class=\"ez-toc-section\" id=\"Srodowisko_produkcyjne\"><\/span>Production environment<span class=\"ez-toc-section-end\"><\/span><\/h4>\r\n<p>The REST KSEF API production environment is integrated with the environment <a href=\"https:\/\/ksef.mf.gov.pl\/\"><strong><span style=\"text-decoration: underline;\">production<\/span><\/strong> <strong>National e-Invoice System<\/strong><\/a> and is available at: <code>https:\/\/ksefapi.pl\/api\/<\/code><\/p>\r\n<p><strong>Attention<\/strong>! To use the KSEF API REST operation in a production environment, you must save the access token generated in the KSeF production environment, activate access to this type of environment and purchase any KSEF package.<\/p>\r\n<h3 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"Uwierzytelnienie_i_autoryzacja_zapytan\"><\/span>Authentication and authorization of queries<span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n<p>The provided API interface uses the standard HTTP protocol. API operations (methods) use HTTP GET or POST methods. Each operation call requires query authorization. Authorization of executed queries is possible using <code>Basic Authentication<\/code><\/p>\r\n<h4><span class=\"ez-toc-section\" id=\"Uwierzytelnienie_Basic_Authentication\"><\/span>Basic Authentication<span class=\"ez-toc-section-end\"><\/span><\/h4>\r\n<p>Specification of the authorization method used: <a href=\"https:\/\/www.nip24.pl\/public\/rest\/rfc7617.txt\">HTTP Authentication: Basic Authentication<\/a>. Preparing the authorization header for a query sent to our website using this method involves encoding the appropriately prepared string with the Base64 function and sending the result in the HTTP header.<\/p>\r\n<h5>Example<\/h5>\r\n<p>The input string to the Base64 function is:<\/p>\r\n<pre><code>str = key_id + &#039;:&#039; + key<\/code><\/pre>\r\n<p>Where:<\/p>\r\n<ul>\r\n<li><code>key_id<\/code> \u2013 API key ID, which can be found on the tab <em>API keys<\/em>.<\/li>\r\n<li><code>key<\/code> \u2013 API key, the value of which can be found on the tab <em>API keys<\/em>.<\/li>\r\n<\/ul>\r\n<p>If the key ID had a value <em><code>test_id<\/code><\/em>, and the key had a value <code><em>test_key<\/em><\/code>, then the input string for the Base64 function will be:<\/p>\r\n<pre><code>str = &quot;test_id:test_key&quot;<\/code><\/pre>\r\n<p>After applying the Base64 function we get:<\/p>\r\n<pre><code>Base64(str) = dGVzdF9pZDp0ZXN0X2tleQ==<\/code><\/pre>\r\n<p>This value should be sent as a Basic value in the header with authorization data. Ultimately:<\/p>\r\n<pre><code>Authorization: Basic dGVzdF9pZDp0ZXN0X2tleQ==<\/code><\/pre>\r\n<h5>Example<\/h5>\r\n<p>The following example shows a query that can be run in a test environment from a web browser. Just copy and paste it into your browser&#039;s address bar:<\/p>\r\n<pre><code>https:\/\/test_id:test_key@www.ksefapi.pl\/api-test\/invoice\/generate<\/code><\/pre>\r\n<p>Where:<\/p>\r\n<ul>\r\n<li><code>test_id<\/code> \u2013 example key ID value. To authenticate in a production or test environment, the parameter should contain the correct key ID used for authentication,<\/li>\r\n<li><code>test_key<\/code> \u2013 example key value. To authenticate in a production or test environment, the parameter should contain a valid value for the key used for authentication.<\/li>\r\n<\/ul>\r\n<p>The key and identifier are generated by the user after logging into their account (tab <code>API Keys and KSeF Tokens<\/code>). Field <code>KSeF Client Token<\/code> must be supplemented with a token generated in the KSeF system in accordance with the instructions described in <a href=\"\/en\/poradnik-ksef-jak-wygenerowac-token\/\">Guide to KSeF<\/a>:<\/p>\r\n<p><a href=\"https:\/\/ksefapi.pl\/wp-content\/uploads\/2026\/01\/klucze_api.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/ksefapi.pl\/wp-content\/uploads\/2026\/01\/klucze_api.png\" alt=\"KSeF 2.0 rejestracja - klucze API\" width=\"1763\" height=\"536\" class=\"aligncenter wp-image-1053 size-full\" srcset=\"https:\/\/ksefapi.pl\/wp-content\/uploads\/2026\/01\/klucze_api.png 1763w, https:\/\/ksefapi.pl\/wp-content\/uploads\/2026\/01\/klucze_api-300x91.png 300w, https:\/\/ksefapi.pl\/wp-content\/uploads\/2026\/01\/klucze_api-1024x311.png 1024w, https:\/\/ksefapi.pl\/wp-content\/uploads\/2026\/01\/klucze_api-768x233.png 768w, https:\/\/ksefapi.pl\/wp-content\/uploads\/2026\/01\/klucze_api-1536x467.png 1536w, https:\/\/ksefapi.pl\/wp-content\/uploads\/2026\/01\/klucze_api-18x5.png 18w\" sizes=\"(max-width: 1763px) 100vw, 1763px\" \/><\/a><\/p>\r\n<h2 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"Kliknij_tutaj_aby_zobaczyc_dalsza_czesc_dokumentacji_KSeF_REST_API_ktora_zostala_udostepniona_na_dedykowanej_witrynie\"><\/span><a href=\"https:\/\/ksef24.com\">Click here to see the rest of the KSeF REST API documentation which is available on a dedicated website<\/a><span class=\"ez-toc-section-end\"><\/span><\/h2>\r\n\r\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-1 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis: 100%;\"><\/div>\r\n<\/div>","protected":false},"excerpt":{"rendered":"<p>KSeF REST API \u2013 technical documentation (integration) for the National e-Invoice System Introduction This documentation describes the REST API interface enabling comprehensive implementation of structured invoice handling in the KSeF system. A detailed definition of the API interface is available in a format compatible with OpenAPI and can be downloaded as a JSON file. The API is also available [\u2026]<\/p>","protected":false},"author":2,"featured_media":351,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"page-templates\/template-fullwidth.php","meta":{"footnotes":""},"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/ksefapi.pl\/en\/wp-json\/wp\/v2\/pages\/449"}],"collection":[{"href":"https:\/\/ksefapi.pl\/en\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/ksefapi.pl\/en\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/ksefapi.pl\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ksefapi.pl\/en\/wp-json\/wp\/v2\/comments?post=449"}],"version-history":[{"count":138,"href":"https:\/\/ksefapi.pl\/en\/wp-json\/wp\/v2\/pages\/449\/revisions"}],"predecessor-version":[{"id":1105,"href":"https:\/\/ksefapi.pl\/en\/wp-json\/wp\/v2\/pages\/449\/revisions\/1105"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ksefapi.pl\/en\/wp-json\/wp\/v2\/media\/351"}],"wp:attachment":[{"href":"https:\/\/ksefapi.pl\/en\/wp-json\/wp\/v2\/media?parent=449"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}