You can read and change the eKasa settings (login, CORS, printers, extensions, hosting and more) from your software just like in the web interface. The merchant then does not have to set them up by hand.
This article applies to the HTTP API. The .NET library is set up differently, see Configuration.
From version 9.1.0, the settings are also available in version 2 (/api/v2/settings). In it, the GET response
can be sent back unchanged, single values can be changed without sending the whole settings, and a stored password
or key can be removed. Connect a new integration to version 2. Version 1 behaves as before; the differences are in
the comparison below.
Overview
| Request | What it does | Version 1 | Version 2 |
|---|---|---|---|
GET …/settings |
returns the current settings | yes | yes, the same response |
PUT …/settings |
replaces the whole settings | yes | yes |
PATCH …/settings |
changes only the values sent | no | yes |
The settings fields and responses are described in the HTTP API reference.
Passwords and other secrets
eKasa stores secrets but does not return them in responses. Instead of the value there is null, and next to it
a flag telling whether the secret is stored:
| Secret | Flag |
|---|---|
authentication.users[].password |
authentication.users[].hasPassword |
printers.email.credentials.password |
printers.email.credentials.hasPassword |
hosting.https.certificates.pfx |
hosting.https.certificates.hasPfx |
hosting.https.certificates.password |
hosting.https.certificates.hasPassword |
extensions.Expose.privateKey |
extensions.Expose.hasPrivateKey |
extensions.Expose.accessToken |
extensions.Expose.hasAccessToken |
Part of the GET {server_address}/api/v2/settings response when an SMTP password is stored:
{
"printers": {
"email": {
"credentials": {
"userName": "edoklad@ninedigit.sk",
"password": null,
"hasPassword": true
}
}
}
}
Saving the whole settings
PUT replaces the whole settings. Sections and values you do not send get their defaults
(authentication.requireHttps is on by default when HTTPS is on). A body with a single
section would, for example, switch the login off and remove the users. The secrets GET does not return are kept
according to their flag (see below), but only in the sections you send. A section left out gets its default along
with its secrets: without extensions.Expose the Expose settings are removed with their key and token, without
hosting the HTTPS certificate. The SMTP server address printers.email.host and the sender address
printers.email.addressFrom are required: they have no meaningful default, so settings without them (or without the
printers.email section) are refused. Version 1 also keeps the values an older client may not know (see the
comparison).
The procedure is therefore always the same: load the settings with GET, change what you need and send them back
as a whole.
PUT {server_address}/api/v2/settings
Content-Type: application/json
The response contains the saved settings in the same form as GET.
Secrets in version 2
In version 2 the flag means the same as in the GET response: whether the secret is stored. By sending the flag you
keep or change that state:
| Value | has… flag |
Result |
|---|---|---|
| a new value | true or not sent |
the new value is stored |
| a new value | false |
refused (400), the flag removes the value |
null |
true or not sent |
the stored value is kept (if none is stored, nothing happens) |
null |
false |
the stored value is removed (if none is stored, nothing happens) |
"" or only spaces |
any | refused (400) |
The GET response can therefore be sent back unchanged and nothing changes. The flag takes precedence: if you add a
new password after GET that was not stored yet (GET returned false), change the flag to true or leave it out.
With false the request is refused and nothing is saved.
A new SMTP password:
{
"printers": {
"email": {
"credentials": {
"userName": "edoklad@ninedigit.sk",
"password": "Password123!"
}
}
}
}
Removing the access token of Expose switched off (the other Expose settings stay as they were in GET):
{
"extensions": {
"Expose": {
/* … the other Expose settings from GET */
"hasAccessToken": false
}
}
}
Some combinations would leave the settings invalid, so eKasa refuses them:
- The SMTP server and the sender address are required (
printers.email.host,printers.email.addressFrom), even if you do not use the e-mail printer. A new installation has the placeholderssmtp.example.comandmail@example.comin them, whichGETreturns and which can be sent back. - A user must have a password. A user’s password cannot be removed (
hasPassword: false). Remove the user by leaving them out of theauthentication.userslist. A new user must have a password. - An SMTP password needs a user name. A user name without a password is stored,
GETreturnshasPassword: falsefor it, and with the sign-in switched on (printers.email.authenticate) eKasa signs in with an empty password. Remove the credentials by sendinguserName: nullandhasPassword: false. With the sign-in switched on and no credentials, eKasa sends without signing in. - A certificate that cannot be loaded without a password cannot be saved without one.
- A certificate password needs a certificate. Remove the certificate along with its password (
hasPfx: falseandhasPassword: false);hasPfx: falsealone while a password is stored is refused. - An extension switched on must have everything it needs. While Expose is on, its key and token cannot be removed, and Expose cannot be switched on without them. The extension settings are checked only while it is on: for example the format of the token of Expose switched off is checked only when it is switched on.
An extension switched on is checked at every save, also when the save does not change it. If an older version saved it without these checks (for example Expose without its token), the save is refused until you fix the extension or switch it off. Version 1 checks, as 9.0.7 did, only an extension the save changes.
Changing single values
PATCH (version 2 only) changes only what you send. The rest of the settings stays saved, so you do not have to call
GET first. The body is a JSON Merge Patch (RFC 7396):
PATCH {server_address}/api/v2/settings
Content-Type: application/merge-patch+json
{ "dateTimeProvider": { "validateTime": false } }
eKasa also accepts Content-Type: application/json. Merge rules:
- objects are merged, arrays (
cors.allowOrigins,authentication.users) are replaced as a whole, nullresets a value to its default, a whole section as well (for example"hosting": null); the requiredprinters.email.hostandprinters.email.addressFromhave no default, so theirnullis refused, as leaving them out ofPUTis,- a secret the patch does not mention stays stored,
- a secret without its flag follows its value like any other value: a new value sets it,
nullresets it to its default, that is removes it; you do not have to know whether one is stored, - a flag the patch has applies as in
PUT:"has…": falseremoves the secret, with a new value it is refused,nullwith"has…": truekeeps it, - the patch replaces an array as a whole, so the passwords in
authentication.usersfollow the rules ofPUT: a user without a password or withnullkeeps theirs, - names are case-insensitive.
Removing the SMTP password (the user name stays):
{ "printers": { "email": { "credentials": { "password": null } } } }
Adding a user: the array is replaced as a whole, so send the existing users too. Without a password they keep theirs:
{
"authentication": {
"users": [
{ "userName": "admin" },
{ "userName": "cashier", "password": "Password123!" }
]
}
}
A value of a wrong type and an invalid value are refused, and nothing is saved. A name the settings do not have is
ignored, as in PUT: a newer client still saves on an older eKasa version what that version knows. The response
contains the saved settings; check in it that the change applied (for example after a typo in a name).
When saving fails
PUT and PATCH refuse invalid settings with status 400 and code
-900. Nothing is saved. The errors field holds an error for
each wrong value:
{
"title": "Validácia zlyhala",
"status": 400,
"code": -900,
"errors": {
"Authentication.Users[0].Password": [
"Používateľ musí mať heslo, nedá sa odstrániť. Používateľa odstránite tak, že ho vynecháte zo zoznamu."
]
}
}
The messages are in Slovak and their wording may change between versions. Recognize the error by code -900 and
the value name in errors.
Comparison with version 1
GET returns the same in both versions. What differs is the meaning of the has… flags when saving: in version 1
the flag does not say whether the secret is stored, but whether you are sending it.
| Value | has… flag |
Version 1 | Version 2 |
|---|---|---|---|
| a new value | true or not sent |
stored | stored |
| a new value | false |
refused (400) |
refused (400) |
null |
not sent | kept | kept |
null |
true |
refused (400) |
kept |
null |
false |
kept | removed |
The certificate (hosting.https.certificates) does not follow these rules in version 1, because it came to the
settings only in version 9.1.0: only its value decides (null keeps it, a new value replaces it).
Other rules of version 1 stay as they were in version 9.0.7:
- An SMTP server address (
printers.email.host) or sender address (printers.email.addressFrom) not sent, or the whole section not sent, gets the placeholdersmtp.example.comormail@example.com. Version 2 requires them. - An empty string
""without a flag: the user password stays stored, the SMTP password is removed and the user name stays. Version 2 always refuses"". - The flags of the secrets of an extension switched off are not checked. A flag contradicting the value keeps
the stored secret.
""without a flag or withtrueremoves it.
In practice this means:
| Version 1 | Version 2 | |
|---|---|---|
send the GET response back unchanged |
refused if passwords or keys are stored | yes |
| remove one password, the certificate or an Expose key | no | yes, has…: false |
change one value without the whole settings (PATCH) |
no | yes |
a missing hosting section, authentication.requireHttps or hosting.enableMdns |
kept (an older client may not know them) | the default, as every value not sent |
In version 1 the GET response therefore has to be adjusted before sending: set all has… flags to false, and to
true only for a secret whose new value you send. The procedure is described in
Migration to version 8.
Moving from version 1 to version 2
- Change the address from
/api/v1/settingsto/api/v2/settings. - After
GET, no longer rewrite thehas…flags tofalse. In version 2,falsewould remove the stored secret. - Send a new value with the flag
trueor without it, as before. - Remove a secret by sending
nullinstead of the value and the flagfalse. - Send the whole settings from
GET, thehostingsection included. In version 2 a missinghostingsection,authentication.requireHttpsorhosting.enableMdnsgets its default.