While using 2N® Access Commander, there is a chance to customize your approach by using the REST API.

Available commands are called End-points. The list of the end-points is in the Access Commander HTTP API manual:
https://wiki.2n.cz/acc/latest/en/6-http-api
Note: Each endpoint starts with the response of the Access Commander to the specific command. The command is always below.

 

Several points before we start:

 

____________________________________________________________________________________________________________________________________________________

Examples:


At this moment, we are ready to post the commands. First of all, we use the valid credentials to login:

(Let's consider we have an Access Commander using an IP 192.168.0.250, username: Admin, Password: Admin1234)

 

 

 

Login command:

Command:

PUT https://192.168.0.250/api/v2/login

Body(data to be sent):

{"login":"Admin","password":"Admin1234","longTimeLogin":true}

____________________________________________________________________________________________________________________________________________________

 

List of current users:

Now we want to receive a list of users with all the parameters

Command:

GET https://192.168.0.250/api/v2/users


Body(data to be sent):
{}

____________________________________________________________________________________________________________________________________________________

 

Getting information about a specific user.

Each user has a unique ID called UUID. It is possible to get from the previous command.

(Lets say our user has a UUID: e7207ded-b864-424b-ad0f-e06b9d8f7527)

Command:

GET https://192.168.0.250/api/v2/users/e7207ded-b864-424b-ad0f-e06b9d8f7527

 

Body(data to be sent):

{}

____________________________________________________________________________________________________________________________________________________

 

Creating a new user:

Now we want to create a new user with the name UserAPI. This user will belong to the company with the ID=1

Command:

POST https://192.168.0.250/api/v2/users

 

Body(data to be sent):

{"Name":"UserAPI","Company":{"Id":1}}

 

In the answer, there will be a parameter E.G.: "ID": "09e7eab1-7b80-4071-89c9-4969a61354e1"

____________________________________________________________________________________________________________________________________________________

 

Adding an RFID card for this new user:

If it is a new user and no one else could edit this user, we can assume the ModifiedGUID=0 , it is not needed to use this parameter then.

Command:

POST https://192.168.0.250/api/v2/users/09e7eab1-7b80-4071-89c9-4969a61354e1/cards

 

Body(data to be sent):

{"Identification":"12345678"}

____________________________________________________________________________________________________________________________________________________

 

Updating RFID card (similar for other parameters):

For maintaining database consistency, we need to use a specific ID for each parameter to prevent multiple processes from modifying data at the same time. This is called ModifiedGUID and we need to get this information from the parameter before we change it. Let's say another process changed the RFID card number 3 times already to the number 12342622. We are going to find out this now.

Command:

GET https://192.168.0.250/api/v2/users/09e7eab1-7b80-4071-89c9-4969a61354e1

 

in the response, we will such an answer:

"Cards": [
            {
                "Identification""12342622",
                "Description""",
                "Id""25d79b1f-8612-4c44-859b-e04f89e19bb5",
                "ModifiedGuid"3
            }

 

Now we know the GUID=3 and we can change the card number to 12121212 (note: we are adding the ID of the card position to the URL):

Command:

PUT https://192.168.0.250/api/v2/users/09e7eab1-7b80-4071-89c9-4969a61354e1/cards/25d79b1f-8612-4c44-859b-e04f89e19bb5


Body(data to be sent):
{"Identification":"12121212","ModifiedGuid":3}

____________________________________________________________________________________________________________________________________________________

 

Creating 2 codes for a user (1234, 9876) (Note: Ordinal = ID of a code):

Command:

POST https://192.168.0.250/api/v2/users/09e7eab1-7b80-4071-89c9-4969a61354e1/codes


Body(data to be sent):
{"SwitchCode":"1234","User":{"Id":"e7207ded-b864-424b-ad0f-e06b9d8f7527"},"Ordinal":0}

Command:
POST https://192.168.0.250/api/v2/users/09e7eab1-7b80-4071-89c9-4969a61354e1/codes

Body(data to be sent):
{"SwitchCode":"9876","User":{"Id":"e7207ded-b864-424b-ad0f-e06b9d8f7527"},"Ordinal":1}

____________________________________________________________________________________________________________________________________________________

Deleting the 2nd code:
We need to know the code ID the ModifiedGuid first:
Command:
GET https://192.168.0.210/api/v2/users/09e7eab1-7b80-4071-89c9-4969a61354e1

Responce:
 
 "Codes": [
            {
                "Ordinal"0,
                "SwitchCode""1234",
                "Id"4,
                "ModifiedGuid"0,
                "Collisions": []
            },
            {
                "Ordinal"1,
                "SwitchCode""9876",
                "Id"5,
                "ModifiedGuid"0,
                "Collisions": []
            }
        ],


To the URL we need to put the ID of the code we want to delete.

Command:
DELETE https://192.168.0.210/api/v2/users/09e7eab1-7b80-4071-89c9-4969a61354e1/codes/5
 
Body(data to be sent):
{"Identification":"9876","ModifiedGuid":0}