You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: site/sigmaguides/src/developers_api_code_samples/developers_api_code_samples.md
+50Lines changed: 50 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -331,6 +331,56 @@ The expected response is:
331
331
332
332
<imgsrc="assets/apics58.png"width="800"/>
333
333
334
+

335
+
<!-- END OF SECTION-->
336
+
337
+
## Members: Bulk Deactivate
338
+
Duration: 20
339
+
340
+
This script identifies users in Sigma matching a specified name pattern, retrieves their status, and deactivates them by marking them as inactive using the Sigma API.
341
+
342
+
It can be used to bulk deactivate users through the use of a regex pattern match against the user's `name`.
343
+
344
+
<asideclass="positive">
345
+
<strong>IMPORTANT:</strong><br> This script will call the get-access-token > getBearerToken function to get a new/refreshed token automatically so there is no need to do anything else, assuming you have completed the section of this QuickStart "Authentication - REQUIRED" and ensured your .env file is configured correctly.
346
+
</aside>
347
+
348
+
### Description
349
+
Here's a summary of what the code does:
350
+
351
+
<ul>
352
+
<li><strong>Load Environment Variables: </strong>Loads configuration details (e.g., base URL, user name pattern, and API keys) from a .env file.</li>
353
+
<li><strong>Obtain a Bearer Token: </strong>Authenticates with the Sigma API to retrieve a bearer token for authorization.</li>
354
+
<li><strong>List Users: </strong> Fetches all users (both active and inactive) from the Sigma API and filters them based on a regex pattern for their names (first name and last name combined).</li>
355
+
<li><strong>Fetch User Status: </strong>For each filtered user, retrieves additional details, including their isInactive status, to confirm if they are already deactivated.</li>
356
+
<li><strong>Deactivate Users: </strong>If a user is active, sends a request to the Sigma API to mark them as inactive using their memberId.</li>
357
+
<li><strong>Log Results: </strong>Logs the status of each operation (e.g., successful deactivations or errors) for monitoring and debugging purposes.</li>
358
+
</ul>
359
+
360
+
The following demonstrates the code that was provided on the `API Code Samples` > `Members: Bulk Deactivate` page, [located here.](https://help.sigmacomputing.com/recipes/members-bulk-deactivate)
361
+
362
+
### Running the Script
363
+
Open the file `bulk-deactivate.js` in the `members` folder:
364
+
365
+
Each code block is commented to explain what operations are being performed.
366
+
367
+
Update the `.env` file, providing a `USER_NAME_PATTERN` that will be used to identify members that are to be deleted.
368
+
369
+
For example:
370
+
371
+
<imgsrc="assets/apics71.png"width="500"/>
372
+
373
+
Press `F5` to run the script with VSCode's debugger.
0 commit comments