Roles: API examples
Contract-derived requests, potential responses and API links for roles.
Generated from the public OpenAPI. Examples illustrate the contract and are not live results. Use your assigned gateway, credentials and identifiers. The snippets do not execute automatically.
Use Node.js 22 or later. Copy the setup below into an .mjs file, set QFP_BASE_URL and QFP_ACCESS_TOKEN, then append the operation snippet you need. No repository checkout or downloaded client is required. Keep secrets in your backend and persist each write key and body before sending.
Request setup
const required = name => {
const value = process.env[name];
if (!value) throw new Error(`Set ${name} before running this example`);
return value;
};
const baseUrl = required('QFP_BASE_URL').replace(/\/$/, '');
if (!/^https:\/\//.test(baseUrl)) throw new Error('Use your assigned HTTPS gateway');
const token = required('QFP_ACCESS_TOKEN');
const segment = value => encodeURIComponent(value);
async function request(method, path, body, key) {
const headers = { Authorization: `Bearer ${token}`, 'API-Version': '1.0.0', Accept: 'application/json' };
if (key) headers['Idempotency-Key'] = key;
const multipart = body instanceof FormData;
if (body !== undefined && !multipart) headers['Content-Type'] = 'application/json';
const response = await fetch(baseUrl + path, {
method, headers, body: body === undefined ? undefined : multipart ? body : JSON.stringify(body),
signal: AbortSignal.timeout(30_000), redirect: 'error',
});
const text = await response.text();
const data = text && response.headers.get('content-type')?.includes('json') ? JSON.parse(text) : text || null;
if (!response.ok) {
const error = new Error(`HTTP ${response.status}`);
Object.assign(error, { status: response.status, data, headers: response.headers });
throw error;
}
return { status: response.status, data };
}createRole
Create a custom role. API Reference · Integration guide
POST /api/tenants/{id}/roles
| Parameter | Location | Required |
|---|---|---|
id | path | Yes |
API-Version | header | Yes |
Request body: analyst
{
"name": "Analyst",
"description": "Reads policies",
"permissions": [
"policy:read"
]
}const body = {
"name": "Analyst",
"description": "Reads policies",
"permissions": [
"policy:read"
]
};
const result = await request('POST', '/api/tenants/' + encodeURIComponent('<id>') + '/roles', body, undefined);
console.log(result.status, result.data);Replace angle-bracket placeholders before calling. Persist any idempotency key with the business instruction.
Potential responses
Documented statuses: 200, 400, 401, 403, 404, 409.
Example 200 (created); see the reference for other outcomes.
{
"id": "9a7d3b61-2c48-4f90-b5e2-77c1a0d4e6f3",
"role": "Analyst",
"description": "Reads policies",
"custom": true,
"permissions": [
"policy:read"
]
}For CSV/download endpoints, the response may be text rather than JSON. The request helper preserves that distinction.
listRoles
List roles. API Reference · Integration guide
GET /api/tenants/{id}/roles
| Parameter | Location | Required |
|---|---|---|
id | path | Yes |
API-Version | header | Yes |
search | query | No |
page | query | No |
size | query | No |
sort | query | No |
const body = undefined;
const result = await request('GET', '/api/tenants/' + encodeURIComponent('<id>') + '/roles', body, undefined);
console.log(result.status, result.data);Replace angle-bracket placeholders before calling. Persist any idempotency key with the business instruction.
Potential responses
Documented statuses: 200, 400, 401, 403, 500.
Example 200 (firstPage); see the reference for other outcomes.
{
"pageNumber": 0,
"pageSize": 20,
"totalResults": 4,
"items": [
{
"id": "5c2f1e8a-91b4-4d33-8a77-0e1b6c9d2f41",
"role": "ADMIN",
"description": "Manages the tenant",
"custom": false,
"permissions": [
"admin:create",
"user:create",
"member:invite",
"member:remove",
"automation:create"
]
},
{
"id": "9a7d3b61-2c48-4f90-b5e2-77c1a0d4e6f3",
"role": "Analyst",
"description": "Reads policies",
"custom": true,
"permissions": [
"policy:read"
]
}
]
}For CSV/download endpoints, the response may be text rather than JSON. The request helper preserves that distinction.
getRole
View a role and who holds it. API Reference · Integration guide
GET /api/tenants/{id}/roles/{roleId}
| Parameter | Location | Required |
|---|---|---|
id | path | Yes |
roleId | path | Yes |
API-Version | header | Yes |
page | query | No |
size | query | No |
sort | query | No |
const body = undefined;
const result = await request('GET', '/api/tenants/' + encodeURIComponent('<id>') + '/roles/' + encodeURIComponent('<roleId>') + '', body, undefined);
console.log(result.status, result.data);Replace angle-bracket placeholders before calling. Persist any idempotency key with the business instruction.
Potential responses
Documented statuses: 200, 400, 401, 403, 404, 500.
Example 200 (customRole); see the reference for other outcomes.
{
"id": "9a7d3b61-2c48-4f90-b5e2-77c1a0d4e6f3",
"role": "Analyst",
"description": "Reads policies",
"custom": true,
"permissions": [
"policy:read"
],
"users": {
"pageNumber": 0,
"pageSize": 20,
"totalResults": 1,
"items": [
{
"id": "3f1c9e2a-5b47-4f0e-9a1d-2c8b7e6d5a40",
"firstName": "Jane",
"lastName": "Doe",
"email": "[email protected]",
"role": "Analyst",
"status": "ACTIVE"
}
]
}
}For CSV/download endpoints, the response may be text rather than JSON. The request helper preserves that distinction.
updateRolePermissions
Replace a custom role's permissions. API Reference · Integration guide
PUT /api/tenants/{id}/roles/{roleId}/permissions
| Parameter | Location | Required |
|---|---|---|
id | path | Yes |
roleId | path | Yes |
API-Version | header | Yes |
Request body: twoPermissions
{
"permissions": [
"policy:read",
"policy:approve"
]
}const body = {
"permissions": [
"policy:read",
"policy:approve"
]
};
const result = await request('PUT', '/api/tenants/' + encodeURIComponent('<id>') + '/roles/' + encodeURIComponent('<roleId>') + '/permissions', body, undefined);
console.log(result.status, result.data);Replace angle-bracket placeholders before calling. Persist any idempotency key with the business instruction.
Potential responses
Documented statuses: 200, 400, 401, 403, 404.
For CSV/download endpoints, the response may be text rather than JSON. The request helper preserves that distinction.
Updated 4 days ago

