Adding Users to a Dashboard with Postman Flows
This article will explain how to add N number of Users to a dashboard using Postman.
Postman
Postman is a free utility that works with API calls. You can download & install or use the online version. Register and you’re away.
The Panintelligence dashboard contains an API which we will utilise.
Postman Flows
In essence, Postman Flows allow you to “string-together” postman requests.
Unfortunately Postman Flows CANNOT be shared on the free subscription, but are easy to create, so we are going to create it from scratch
We will use 2 postman requests within a Postman Flow, alongside some control flow logic and a few variables to create as many users as required.
Postman flows employ or reference existing postman collection requests, so before creating a flow we have to create the requests that we want to put in our flow.
To help visualise where we are heading here is a image of the flow end result.
There are just 2 Send Requests, one (1) is to logon onto the dashboard and get a token which is used as the authenticator in the other second call (2) which creates a user.
The create user send request is part of a repeating control flow that loops the number of times you have set the variable usersToCreate
The variable userNamePrefix is used as the prefix for all user names.
The variable StartAt sets the user number to start creating from.
If you want to create 500 users starting at 1001 with a prefix of “TH_” eg “TH_1001” through to “TH_1500” then the variable values would be:
userType = 4 ( UserType: 0=Admin, 1=Designer, 2=Explorer, 3=User, 4=Viewer)
usersToCreate: 500
StartAt: 1001
userNamePrefix: TH_
Create Users Collection
Lets get started by creating a new Collection in Postman called Create Users
We will then create the 2 POST requests, Get Token & Create User By Type
Start Postman
Create a New Collection - Call it Create Users
POST Get Token
Hover over the folder called Create Users, click the 3 dots and select Add Request which will create a request stub. Immediately rename it by hovering over the New Request, again click the 3 dots then click Rename and give it a name of Get Token
Change it to be a POST request
Enter the URL - this is where the variables become useful, simply enter:
{{DASHBOARD_URL}}{{DASHBOARD_API_PATH}}/tokens
Set the Authentication Type to Basic and enter references to the variables in Username and Password.
Add a little magic ! In the Scripts tab enter the code below which in simple terms grabs the dashboard token from the response of this POST request, which if we have supplied valid credentials, will have a value that we will capture and re-use in all subsequent API requests.
const jsonResponse = pm.response.json(); pm.collectionVariables.set("DASHBOARD_TOKEN", jsonResponse.token);
Test by clicking the Send button (Top-Right) - this needs to respond with a status code of 200 and show the returned token.
POST Create User by Type
Hover over the folder called Create Users, click the 3 dots and select Add Request which will create a request stub. Immediately rename it by hovering over the New Request, again click the 3 dots then click Rename and give it a name of Create User by Type
Change it to be a POST request
Enter the URL - this is where the variables become useful, simply enter:
{{DASHBOARD_URL}}{{DASHBOARD_API_PATH}}/users
Set the Authentication Type to Bearer Token and enter references to the variable {{bearerToken}} in the Token.
Set the content Body. Click the Body tab, then click Raw and enter JSON for creating a user.
{ "clientEnabled": true, "usercode": {{userNamePrefix}}{{currUserNum}}, "userTypeId": {{userType}}, "parentId": {{parentId}}, "surname": {{userNamePrefix}}, "forenames": "{{currUserNum}}", "email": {{userNamePrefix}}{{currUserNum}}"@panintelligence.com", "orgId": {{orgId}}, "clientPassword": "password", "forceChangingPassword": false, "allowPasswordLogin": true, "allowExternalLogin": true, "clientExcludePasswordExpiry": true, "themeName": null, "requireMfa": false, "userExpirationDate": null, "lite": false, "canLogInAsAnotherUser": true, //ADMIN USERTYPE = 0 "editApis": true, "editCategories": true, "editConnections": true, "editRoles": true, "editServerSettings": true, "editThemes": true, "editUsers": true, "editVariables": true, "editUserAccess": true, //DESIGNER USERTYPE = 1 "saveLayouts": true, "editSql": true, "editChartStyles": true, "anonymousCharts": true, //CHART EXPLORER USERTYPE = 2 "editCharts": true, //USER USERTYPE = 3 "collaborate": true, "editReports": true, "modifyLayouts": true, "saveFilters": true, "schedule": true, "scheduleToEmail": true, //VIEWER USERTYPE = 4 "accessAccount": true, "addTempCategoryObjects": true, "applySavedFilters": true, "editOwnPassword": true, "editOwnStylesheet": true, "logoutEnabled": true, "carousel": true, "carouselForDashboard": true, "carouselForCategory": true, "enableWarnings": true, "enableDebugging": true, "displayChartInfo": true, "canViewChartInfoDetails": true, "canViewChartEmbeddingLink": true, "displayDisabledButtons": true, "audit": true, "exportToCsv": true, "exportToExcel": true, "Pdf": true, "exportToPpt": true, "exportToWord": true }
Related articles
CUSTOMER NEWS - Our November 24 Release Is Now Available - Download It Now!