Skip to content

Commit d362d19

Browse files
authored
Merge pull request #348 from sigmacomputing/bulk-deactivate-api
Bulk-deactivate-recipe
2 parents 84560ca + ca9e1be commit d362d19

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed
44.1 KB
Loading
106 KB
Loading
140 KB
Loading

site/sigmaguides/src/developers_api_code_samples/developers_api_code_samples.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,56 @@ The expected response is:
331331

332332
<img src="assets/apics58.png" width="800"/>
333333

334+
![Footer](assets/sigma_footer.png)
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+
<aside class="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+
<img src="assets/apics71.png" width="500"/>
372+
373+
Press `F5` to run the script with VSCode's debugger.
374+
375+
The expected response is:
376+
377+
<img src="assets/apics72.png" width="800"/>
378+
379+
Confirm the users have been deactivated in Sigma:
380+
381+
<img src="assets/apics73.png" width="800"/>
382+
383+
334384
![Footer](assets/sigma_footer.png)
335385
<!-- END OF SECTION-->
336386

0 commit comments

Comments
 (0)