Get User Roles
This guide walks you through retrieving the roles assigned to a specific user in your organization using the Stewart Sign API.
When to Use
Retrieving user roles is useful when you need to:
- Verify a user's permissions before performing actions
- Build role-based access control (RBAC) in your integration
- Audit user access levels within your organization
Requirements
- You need to have Node.js installed on your system.
- You'll also need the axios library. You can install it using the following command:
npm install axios
- A valid Bearer token (JWT) for authentication.
- The user ID of the user whose roles you want to retrieve.
Endpoint
GET /user/{id}/roles
| Parameter | Type | Required | Description |
|---|---|---|---|
id | string | Yes | The unique ID of the user whose roles to retrieve. |
Code Snippet
Use the following code snippet to retrieve a user's roles. Replace <userId> with the actual user ID, and <accessToken> with your API access token.
const axios = require("axios");
const userId = "<userId>";
const config = {
method: "get",
url: `https://public-api.sign.stewart.com/user/${userId}/roles`,
headers: {
Authorization: "Bearer <accessToken>",
},
};
axios(config)
.then(function (response) {
console.log("User roles retrieved successfully:", response.data);
})
.catch(function (error) {
console.log(error.response?.data || error.message);
});
Successful Response
On success, the API returns an array of role objects assigned to the user:
[
{
"id": "rol_abc123",
"name": "Admin",
"description": "Full administrative access"
},
{
"id": "rol_def456",
"name": "Notary",
"description": "Can perform notarizations"
}
]
Error Responses
| Status | Reason |
|---|---|
401 Unauthorized | Invalid or expired Bearer token |
404 Not Found | Organization or user not found |
Steps to Execute the Code Snippet
- Create a new file named
get_user_roles.js. - Copy and paste the code snippet provided above into the new file.
- Replace
<userId>and<accessToken>with the appropriate values. - Save the file and open a terminal or command prompt.
- Navigate to the folder where you saved the
get_user_roles.jsfile. - Run the following command to execute the script:
node get_user_roles.js
If the request is successful, you'll see the user's roles displayed in the console. In case of an error, the error details will be displayed instead.
Additional Resources
For more information about the Stewart Sign API, visit the official documentation.
If you need further assistance or have questions, feel free to reach out to our support team.