Retrieve user login info using SonicOS API

Description

This KB explains how to run an API call to find out the users that are logged in at that time. No history of the past (logged out) users will be seen.

To know the status of users logged in using User-level authentication and/or VPN on the GUI is found under Device | User | Status page after you log in.

Image

 

User logged in status from CLI is explained here: 

Retrieve user login info using CLI

Resolution

Step 1: Enable SonicOS API and Log in:

SonicOS API is disabled by default in SonicOS. Any attempt to access SonicOS API while it is disabled results in an HTTP 403 Forbidden error. To use the SonicOS API, you must enable it, either through the SonicOS Management Interface or from the CLI. Please enable the SonicOS API module in the SonicWall UI.

Gen 7: Enable SonicOS API Gen7

Gen 6: Enable SonicOS API Gen6

The above KB also has the steps on how to log in using API Applications

 CAUTION: My SonicWall interface IP address is 192.168.168.168 with login credentials as admin/password. This has to be kept in mind while running the commands from the below screenshots.  

 

Step 2: Calling on postman using GET method

Image

There are 2 users:

  1. admin user
  2. SSLVPN user

cURL commands for the same example would be:

curl --location --request GET 'https://10.61.42.65/api/sonicos/user/status/logged-in/all' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Content-Type: application/xml' \
--header 'Authorization: Basic YWRtaW46c29uaWN3YWxs' \
--data '{"override" : true}'

 

Step 3: Log out the SonicWall with API
It is recommended to log out from the SonicWall via API once the desired configuration is committed.
Log out

curl -k -i -u "admin:password" -X DELETE https://192.168.188.200/api/sonicos/auth

Related Articles

  • SonicOS 8.1.0 FAQ
    Read More
  • SonicWall GEN8 TZs and GEN8 NSas Settings Migration
    Read More
  • Getting started with SonicWall firewalls
    Read More
not finding your answers?