access_control_api

Access Control API

This guide describes how third-party software, such as a hotel management system, can interact with the Thinknx server to create access credentials, retrieve existing accesses and send credentials by email.

Related documentation: ViaVai Access Control, for configuring areas, roles and readers in Thinknx Configurator.

The Access Control API is available starting from Thinknx server firmware version 1.1.10.34.

Call Method Purpose
accessControlCreate POST Creates one access: a PIN, one or more cards, or both, valid for a set of areas and/or a role.
accessControlGet POST Returns an existing access, found by its id (the PIN key) or by a card code.
accessControlSendMail POST Sends the credentials of an existing access by email, through one of the email accounts of the server.
  • Thinknx server firmware 1.1.10.34 or later.
  • The project loaded on the server uses the access control feature, with its areas (and optionally roles) configured.
  • The Integration Kit API is enabled (licensed) on the server. If it is not, the API is not available and the server log shows “Integration Kit API - License needed!”.
  • A server user dedicated to the integration. Its credentials are used for HTTP Basic authentication.
  • At least one email account configured on the server. Needed only for accessControlSendMail.
  • The calling system must reach the Thinknx server directly on its HTTPS web port. The API is not available through the Thinknx cloud.
  1. The integration calls accessControlCreate when a reservation or check-in needs a credential.
  2. It stores the returned id together with the reservation.
  3. It optionally calls accessControlSendMail to send the credentials to the guest.
  4. It calls accessControlGet whenever it needs to read the access again, by id or by card.

All calls are relative to the Integration Kit base path, the same one used by the other Integration Kit APIs, over HTTPS:

POST https://<server-address>/api/V1/<call>?auth=basic

Example: https://192.168.1.50/api/V1/accessControlCreate?auth=basic

The calls are served only on this direct path:

  • Not on action.cgi: a request to action.cgi?cmd=<call> is answered with HTTP 404 and {"namespace": "<call>", "error": "use /api/V1/<call>"}.
  • Not through the Thinknx cloud: a call arriving from the cloud is answered with HTTP 403 and {"namespace": "<call>", "error": "not available through the cloud"}.

<call> is accessControlCreate, accessControlGet or accessControlSendMail. The call names and the path are case-sensitive.

The server certificate is usually self-signed: install it in the trust store of the calling system, or pin it in the client (for example curl –cacert server.pem, or Python requests with verify=“server.pem”).

Access control not configured. If the project loaded on the server does not use access control, the calls answer HTTP 404 with {"namespace": "<call>", "error": "access control not configured"}.

Every request must be authenticated with a Thinknx server user, using HTTP Basic. Add auth=basic to the URL and give the user and password to the HTTP client, for example in the URL itself:

https://apiuser:apipassword@192.168.1.50/api/V1/<call>?auth=basic
  • With auth=basic, a request without credentials gets HTTP 401 with WWW-Authenticate: Basic realm=“Thinknx Server”. Clients that wait for this challenge (browsers, user:password@ URLs, most HTTP libraries) then send the credentials and repeat the request.
  • A client can also send the Authorization: Basic header with every request, without waiting for the challenge (for example curl -u, or Python requests with auth=(user, password)). This works with or without auth=basic.
  • HTTP Digest is not supported, and no session is kept between requests.

Without auth=basic there is no challenge. A request without credentials and without auth=basic is redirected to the login page (HTTP 303 to /login.html). Wrong user or password gives HTTP 401.

Authentication lockout. The server counts failed logins per IP address and can temporarily block the client after repeated failures. Check the credentials before automating calls, and do not retry in a loop on HTTP 401.

  • Every call is an HTTP POST. The body is a single JSON object, encoded as UTF-8.
  • Send Content-Type: text/plain; charset=utf-8 or Content-Type: application/json. Both are accepted and the server reads the body as UTF-8 in both cases. text/plain is the form that keeps non ASCII characters intact on every server version, including older ones.
  • Field names are case-sensitive. Unknown fields are ignored.
  • Every field has a fixed JSON type: a number sent as a string, or a string sent as a number, is refused with Invalid field: <name>.

Every response body is a JSON object with Content-Type: application/json, and it starts with namespace, the name of the call. Success is reported with HTTP status 200. Errors use the HTTP status codes listed in the error reference and contain an error field with a description.

Non ASCII characters in answers are escaped as \uXXXX, as JSON allows. The server sends compact JSON; the examples in this guide are formatted for reading. The server closes the connection after any answer other than 200; HTTP clients reconnect automatically.

A call succeeded when the HTTP status is 200 and the answer has no error field.

Term Meaning
Access One record that grants entry. It is identified by its id.
PIN The server always generates a PIN for a new access, with the length configured in the project. The PIN is the id of the access. use_pin decides whether the PIN is also a valid credential at keypads: when it is false the PIN still exists as the id but does not open any door.
Card A card or badge code. An access can have several cards, and a card belongs to one access only.
Areas The areas the access can open, by numeric id. The ids are the ones shown in the project configuration.
Subareas Areas can contain other areas. Granting an area also grants every area below it, but not the areas above it. The answers list only the areas that were granted, not the ones they contain.
Validity An optional period (valid_from and valid_to) outside which the access does not open anything. Without it the access has no time limit. Times are written in ISO 8601.
Weekly rules Optional weekly time slots (weekly_rules): the access opens only inside them. See the weekly rules section.
Role Optional numeric id of a role. A role grants a set of areas, which are added to the areas listed in the request.
Description Free text shown in the server web page.

Credential activation. Credentials are active as soon as the call returns HTTP 200. Delivery to locks and keypads can take a few more seconds, for example for battery operated locks that are updated through the gateway.

Creates one access and returns it. The server generates the PIN, which is also the id of the new access. Creations run one at a time on the server, so two concurrent calls never get in each other's way.

{
  "description": "Room 101 - J. Smith",
  "use_pin": true,
  "use_card": true,
  "card_codes": ["04A1B2C3", "04D4E5F6"],
  "areas": [1, 2],
  "role": 3,
  "valid_from": "2026-11-14T15:00:00",
  "valid_to": "2026-11-16T11:00:00"
}
Field Type Required Rules
description string No Maximum 200 characters, with no control characters (including line breaks and tabs). See the reserved sequences below.
use_pin boolean One of use_pin and use_card must be true The PIN is a valid credential. Default false.
use_card boolean See above Cards are valid credentials. Default false.
card_codes array of strings When use_card is true Not allowed when use_card is false. Each card code must contain 1 to 64 printable ASCII characters, with no spaces or reserved characters. Matching is case insensitive.
replace_card_owners boolean No Takes the cards over from the accesses that own them. Default false. See the section on replacing card owners.
areas array of integers At least one of areas and role Every id must exist. Repeated ids are counted once.
role integer At least one of areas and role Must exist.
valid_from string (date and time) Only together with valid_to ISO 8601, for example 2026-11-14T15:00:00. See the notes on dates below.
valid_to string (date and time) Only together with valid_from ISO 8601. Must be after valid_from.
weekly_rules array of objects No Weekly time slots: the access opens only inside them. See the weekly rules section.

The fields are checked in this order: description, weekly_rules, use_pin and use_card, card_codes, areas and role, valid_from and valid_to. The first problem found is the one reported, and nothing is created.

Unknown fields are ignored.

Reserved sequences and characters

  • In description, these sequences are not allowed: |%|, $% and $$$.
  • In card_codes, spaces and these characters are not allowed: comma, vertical bar, percent sign and dollar sign.
  • Write dates as YYYY-MM-DDTHH:MM:SS. Seconds and fractions of a second are optional (fractions are dropped). Other formats, such as 14/11/2026 or a date without a time, are refused with Invalid field: valid_from (or valid_to).
  • A date without an offset is the local time of the server, which is the right choice for check-in and check-out times of the hotel. A date with Z or an offset such as +02:00 is converted to the local time of the server.
  • The access opens doors from valid_from to valid_to, both included. A period that already ended is accepted, but the access never opens anything (in_validity is false).
  • Answers write dates with the offset of the server, for example 2026-11-14T15:00:00+01:00.

A card belongs to one access only. If a card in card_codes is already owned by another access and replace_card_owners is not true, the call fails with HTTP 409 Card code already assigned to another user and nothing is created. This also applies to cards owned by accesses that another server manages.

With “replace_card_owners”: true a card can be given to the new access even if another access owns it, for example when a hotel re-encodes a key card for the next guest:

  • The server first runs every check of the request. Only when all of them pass, it deletes each access that owns one of the cards, then creates the new one.
  • The previous owner is deleted as a whole: its PIN and all its other cards stop working, not only the card that was taken over.
  • The answer has an extra field, replaced: the ids of the deleted accesses. It is present whenever replace_card_owners is true, and is [] when no card had an owner.
  • A card owned by an access that another server manages cannot be taken over: the call fails with HTTP 409 Card code assigned to a user managed by another server and nothing is deleted or created.
{"namespace": "accessControlCreate", "id": "73019", ..., "replaced": ["48213"]}

The previous owners are deleted before the new access is saved. If saving the new access then fails (HTTP 500), the previous owners stay deleted and the error answer has no replaced field. Read the cards with accessControlGet to see the current state before retrying.

weekly_rules limits an access to weekly time slots, for example office hours or the opening hours of a gym. It is a list of rules; each rule has a list of days and a list of slots:

"weekly_rules": [
  {"days": [1, 2, 3, 4, 5],
   "slots": [{"from": "08:00", "till": "12:30"}, {"from": "14:00", "till": "18:00"}]},
  {"days": [6],
   "slots": [{"from": "09:00", "till": "13:00"}]}
]
Field Type Rules
days array of integers Days of the week, from 0 (Sunday) to 6 (Saturday). At least one day, no repeated days.
slots array of objects At least one slot, at most 8 slots in a rule.
from string Start of the slot, HH:MM from 00:00 to 23:59.
till string End of the slot, HH:MM. It must be after from. 24:00 means midnight, and 00:00 as an end also means midnight.
  • At most 7 rules, and at most 8 slots in a rule.
  • Each slot opens from from to till on every day of its rule, in the local time of the server. A slot cannot cross midnight: split it there, with the second part in a rule for the next day.
  • The rules add to valid_from and valid_to: with a period the access opens only inside the period and inside a slot; without one the slots apply with no time limit.
  • The server turns the rules into a shared weekly timetable. The order of the rules, days and slots does not matter: accesses sent with the same rules use the same timetable, whose id comes back in timetable.

Checking for weekly rules support. The rules are checked right after the description and before every other field, so the body {“weekly_rules”: []} always answers HTTP 400 weekly_rules must be a non-empty array and creates nothing. A server older than this field answers a different HTTP 400 message: a client can use this to find out whether time slots are supported before it replaces the owner of a card.

{
  "namespace": "accessControlCreate",
  "id": "48213",
  "description": "Room 101 - J. Smith",
  "enabled": true,
  "in_validity": true,
  "use_pin": true,
  "pin": "48213",
  "use_card": true,
  "card_codes": ["04A1B2C3", "04D4E5F6"],
  "areas": [1, 2],
  "role": 3,
  "valid_from": "2026-11-14T15:00:00+01:00",
  "valid_to": "2026-11-16T11:00:00+01:00",
  "extra_periods": [],
  "timetable": null
}

accessControlCreate and accessControlGet return the same access object:

Field Type Description
namespace string Name of the call that produced the response.
id string The key of the access. Use it with accessControlGet and accessControlSendMail.
description string The description, or an empty string.
enabled boolean true for a new access.
in_validity boolean true when the access opens doors right now: it is inside its validity period (or has none) and, if a timetable applies, inside one of its slots.
use_pin boolean The PIN is a valid credential.
pin string The generated PIN. Present only when use_pin is true.
use_card boolean Cards are valid credentials.
card_codes array of strings The cards of the access. Always present, [] when there are none.
areas array of integers The granted areas. Subareas that are covered by a granted area are not listed.
role integer or null The role id, or null.
valid_from, valid_to string or null The validity period, or null for both when the access has no time limit.
extra_periods array of objects Further validity periods, as a list of objects with valid_from and valid_to. Read only: they can be added from the server web page, not through this API.
timetable integer or null Id of the weekly timetable that limits the access, or null. Set from weekly_rules, otherwise read only, like extra_periods.
replaced array of strings Only in accessControlCreate with replace_card_owners: ids of the accesses deleted to take over their cards.

When a call fails, the response contains namespace and error:

{"namespace": "accessControlCreate", "error": "Card code already assigned to another user"}

When accessControlCreate fails while saving or delivering a new access (Error saving, Error sending to checkers), the access already exists on the server and the error answer also carries its id:

{"namespace": "accessControlCreate", "error": "Error saving", "id": "48213"}

Returns an existing access, found by its id or by one of its cards. Read only.

Provide exactly one identifier: id or card.

Field Type Required Description
id string Exactly one of id and card The id returned by accessControlCreate. Send it as a string, for example “48213”: a number is refused with Invalid field: id.
card string See above One card code of the access. Matching is case insensitive.

Look up by id:

{ "id": "48213" }

Look up by card code:

{ "card": "04A1B2C3" }

The same access object returned by accessControlCreate, with “namespace”: “accessControlGet” and without replaced. The call answers HTTP 404 User not found when there is no match, and HTTP 400 Exactly one of id and card is required when both id and card, or neither, are given.

Sends the credentials of an access to an email address.

{ "id": "48213", "to": "guest@example.com", "account": 0 }
Field Type Required Rules
id or card string Exactly one As in accessControlGet.
to string Yes One plain email address (letters, digits and . _ % + - before the @). Lists and display names such as Name <a@b.com> are refused.
account integer No Index of the server email account used as sender. Default 0.

The message has the subject “Your access credentials” and contains the description, the PIN (only when use_pin is true), the cards, the validity period (when there is one) and the names of the areas, including the areas of the role and the subareas that a granted area covers. Further validity periods and weekly rules are not listed. Subject and text are fixed by the server and are in English.

{ "namespace": "accessControlSendMail", "mail": "queued" }

Email delivery. queued means the message was handed to the mail sender of the server. Sending is asynchronous and the delivery result is not reported to this call, so a wrong SMTP configuration is not visible in the answer. After the first use, check that the message arrives.

HTTP error Cause and solution
400 The body must be a JSON object All calls. The body is empty, malformed, or not a JSON object.
400 Invalid field: <name> All calls. A field has the wrong JSON type (for example “use_pin”: “yes” or “id”: 48213), an integer is out of range, or a date is not ISO 8601.
400 description is longer than 200 characters Shorten the description.
400 description contains control characters Remove line breaks, tabs and other control characters.
400 description contains a reserved sequence Remove the reserved sequences listed in the accessControlCreate section.
400 weekly_rules must be a non-empty array The field is not an array, is empty, or holds something other than objects.
400 weekly_rules has too many rules or slots More than 7 rules, or more than 8 slots in one rule.
400 Invalid weekly rule days: use 0 (Sunday) to 6, at least one A rule has no days, a repeated day or a day outside 0 to 6.
400 Invalid time slot: use HH:MM and an end after the start A rule has no slots, a time is not HH:MM, or a slot does not end after it starts.
400 At least one of use_pin and use_card must be true No credential requested.
400 card_codes requires use_card to be true Cards were sent with use_card false or missing.
400 card_codes is required when use_card is true Cards enabled but none given.
400 Invalid card code: … A card does not follow the format described in the accessControlCreate section.
400 Unknown area: 99, Unknown role: 9 The id does not exist in the project.
400 At least one area or a role is required The access would not open anything.
400 valid_from and valid_to must be given together Only one of the two limits was sent.
400 valid_to must be after valid_from The period is empty or reversed.
400 Exactly one of id and card is required accessControlGet and accessControlSendMail: both or neither were given.
400 to must be one valid email address Missing or malformed recipient.
303 (redirect to the login page, no JSON body) No credentials were sent and the URL has no auth=basic. Add auth=basic to the URL, or send the Authorization: Basic header with every request.
401 (no JSON body) Wrong server user name or password.
403 not available through the cloud The call was sent through the Thinknx cloud. Call the server directly.
404 User not found No access matches the id or card.
404 Email account not found: 2 No email account with that index.
404 access control not configured The loaded project does not use access control.
404 use /api/V1/<call> The call was sent to action.cgi. Send it to /api/V1/<call>.
409 Card code already assigned to another user The card is already in use. Use another card, or replace_card_owners.
409 Card code assigned to a user managed by another server Only with replace_card_owners: the owner of the card is managed by another server and cannot be replaced here.
409 Code is already used The generated PIN collided with an existing one. Rare: retry the call.
409 No email account is configured The project has no email account.
500 Error saving, Error sending to checkers The access exists on the server (the answer carries its id) but saving or delivery failed. Read it with accessControlGet and retry the operation.
500 Internal error Unexpected server error, or the timetable for weekly_rules could not be created. The server log has the details.

In rare cases the storage step of accessControlCreate reports other messages, such as PIN already in use or Generic Error (HTTP 400), or Code syntax not valid (HTTP 500). Nothing is created; retry the call and check the server log if the error persists.

# create
curl --cacert server.pem -u api_user:api_password \
  -H "Content-Type: text/plain; charset=utf-8" \
  -d '{"description":"Room 101","use_pin":true,"use_card":true,
       "card_codes":["04A1B2C3"],"replace_card_owners":true,"areas":[1,2],
       "valid_from":"2026-11-14T15:00:00","valid_to":"2026-11-16T11:00:00"}' \
  "https://server.example.com/api/V1/accessControlCreate?auth=basic"

# read by card
curl --cacert server.pem -u api_user:api_password \
  -H "Content-Type: text/plain; charset=utf-8" \
  -d '{"card":"04A1B2C3"}' \
  "https://server.example.com/api/V1/accessControlGet?auth=basic"

# send by email with the second email account
curl --cacert server.pem -u api_user:api_password \
  -H "Content-Type: text/plain; charset=utf-8" \
  -d '{"id":"48213","to":"guest@example.com","account":1}' \
  "https://server.example.com/api/V1/accessControlSendMail?auth=basic"
import requests
 
BASE = "https://192.168.1.50/api/V1/"
AUTH = ("apiuser", "apipassword")   # Thinknx server user, sent as HTTP Basic
 
def call(name, body):
    r = requests.post(BASE + name, auth=AUTH, json=body, timeout=30,
                      verify="server.pem")
    answer = r.json()
    if "error" in answer:
        raise RuntimeError(f"{name}: HTTP {r.status_code} {answer['error']}")
    return answer
 
# 1. Create a PIN and a card for the stay
access = call("accessControlCreate", {
    "description": "Room 101 - J. Smith",
    "use_pin": True,
    "use_card": True,
    "card_codes": ["04A1B2C3"],
    "replace_card_owners": True,          # the card was used by a previous guest
    "areas": [1, 2],
    "valid_from": "2026-11-14T15:00:00",  # check-in, local time of the server
    "valid_to": "2026-11-16T11:00:00",    # check-out
})
print("Created", access["id"], "replaced", access["replaced"])
 
# 2. Send the credentials to the guest
call("accessControlSendMail", {"id": access["id"], "to": "guest@example.com"})
 
# 3. Read the access again by card
print(call("accessControlGet", {"card": "04A1B2C3"})["in_validity"])
$base    = "https://192.168.1.50/api/V1/"
$pair    = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes("apiuser:apipassword"))
$headers = @{ Authorization = "Basic $pair" }
 
function Invoke-AccessControl($name, $body) {
    # -Depth 5 keeps weekly_rules intact; the bytes keep the body UTF-8
    $json = ConvertTo-Json $body -Depth 5 -Compress
    $utf8 = [Text.Encoding]::UTF8.GetBytes($json)
    try {
        Invoke-RestMethod -Method Post -Uri ($base + $name) -Headers $headers `
            -ContentType "text/plain; charset=utf-8" -Body $utf8
    } catch {
        $answer = $_.ErrorDetails.Message | ConvertFrom-Json
        throw "$name failed: $($answer.error)"
    }
}
 
# Create a PIN valid on weekdays, office hours
$access = Invoke-AccessControl "accessControlCreate" @{
    description  = "Cleaning staff"
    use_pin      = $true
    areas        = @(1)
    weekly_rules = @(@{ days = @(1, 2, 3, 4, 5); slots = @(@{ from = "08:00"; till = "18:00" }) })
}
$access.id
 
# Read it back
Invoke-AccessControl "accessControlGet" @{ id = $access.id }
POST /api/V1/accessControlCreate HTTP/1.1
Host: 192.168.1.50
Authorization: Basic YXBpdXNlcjphcGlwYXNzd29yZA==
Content-Type: text/plain; charset=utf-8
Content-Length: 123

{"description":"Room 101","use_pin":true,"areas":[1,2],"valid_from":"2026-11-14T15:00:00","valid_to":"2026-11-16T11:00:00"}
HTTP/1.1 200 OK
Content-Type: application/json

{"namespace":"accessControlCreate","id":"48213","description":"Room 101","enabled":true,"in_validity":true,"use_pin":true,"pin":"48213","use_card":false,"card_codes":[],"areas":[1,2],"role":null,"valid_from":"2026-11-14T15:00:00+01:00","valid_to":"2026-11-16T11:00:00+01:00","extra_periods":[],"timetable":null}
  • Use HTTPS and verify the certificate. The credentials of the API user travel in every request and the PINs travel in the answers. Trust or pin the server certificate instead of turning verification off, and do not expose the server directly to the internet.
  • Use a dedicated server user for API access, with a strong password, so it can be disabled without affecting other users.
  • Do not log the answers of accessControlCreate and accessControlGet in the integration system: they contain the PIN.
  • Restrict network access to the web port of the server to the systems that need it (firewall, VPN, management VLAN).
  • Use replace_card_owners only for cards you manage. It deletes the previous owner of the card as a whole, including its PIN.
  • Store the id returned by accessControlCreate together with your reservation. It is the only handle for reading the access by PIN afterwards.
  • accessControlCreate is not idempotent: retrying after a 500 or a timeout without checking first can create a second access with a new PIN.
  • When a card was used without replace_card_owners, a retry is refused with HTTP 409 and the existing access can be read by its card.
  • When a card was used with replace_card_owners, a retry deletes the access created by the first attempt and creates a new one with a new id and PIN. Read the card with accessControlGet before retrying.
  • On Error saving or Error sending to checkers the access exists: use the id of the error answer with accessControlGet instead of creating it again.
  • Removing or disabling an access is not part of this API version. replace_card_owners deletes an access only as a side effect of giving its cards to a new one.
Symptom What to check
Every request is redirected to the login page (HTTP 303) The credentials are not sent with the request. Add auth=basic to the URL so the server asks for them, or send the Authorization: Basic header every time.
Every request returns HTTP 401 Wrong server user or password, or the IP address of the caller has been temporarily blocked after repeated failures. Wait, or ask the administrator to remove the block from the web access settings of the server.
/api/V1 does not answer or returns a web page Check the URL (the path and the call names are case-sensitive), the firmware version and that the Integration Kit API is licensed.
HTTP 404 with use /api/V1/… The integration still calls action.cgi with the cmd parameter. The calls are only on the /api/V1/ path.
Accented characters of the description arrive wrong The body is not UTF-8. Encode the body as UTF-8 and send Content-Type: text/plain; charset=utf-8.
Invalid field: id The id was sent as a number. Send it as a string: {“id”: “48213”}.
The answer is queued but the email never arrives Check the SMTP settings of the email account on the server and the spam folder of the recipient. Delivery errors are not reported to the API.
in_validity is false on a new access The validity period already ended or has not started, or the current time is outside the weekly rules. Dates without an offset are the local time of the server.
Call Method Body fields
accessControlCreate POST use_pin and/or use_card, card_codes (if use_card), areas and/or role, description (optional), valid_from with valid_to (optional), weekly_rules (optional), replace_card_owners (optional)
accessControlGet POST id or card
accessControlSendMail POST id or card, to, account (optional)
URL:             https://<server>/api/V1/<call>?auth=basic
Authentication:  Authorization: Basic base64(user:password)
Body:            Content-Type: text/plain; charset=utf-8  (or application/json)
Success:         200  {"namespace": "<call>", ...}
Error:           4xx or 5xx  {"namespace": "<call>", "error": "..."}
  • access_control_api.txt
  • Last modified: 2026/11/30 16:17
  • by francesco