Roles & Permissions
API

API

Introduction

ROQ Platform provides access management API to easily get and apply the access and permission data for the user application. Please refer to the roles and permission for feature guides, tutorials, and more information.

User roles querys

These APIs are available on generated SDK and can be used on the client-side.

role()

ROQ provides the role() API to get the role for the specific role id. For example, to get a role data with the role id.

import { roqBrowserClient } from "lib/roq/roq-client";
 
const roleData = await roqBrowserClient.roqPlatform.role({
	id: "8f8a676b-7dea-4a06-a249-55e7f899aeeb", 
	withUserCount: true
})

The output for the code example above is a simple JavaScript object:

{
  role: {
    id: '8f8a676b-7dea-4a06-a249-55e7f899aeeb',
    reference: null,
    description: '',
    isSystemManaged: false,
    key: 'marketing',
    name: 'Marketing',
    users: { totalCount: 1 }
  }
}
ParameterTypeDescription
idstringThe role id
withUserCountbooleanWhether to include the user count or not

roles()

The roles() API will return all the available roles on the ROQ Platform. You can filter roles based on the key and limit the result.

import { roqBrowserClient } from "lib/roq/roq-client";
 
const rolesData = await roqBrowserClient.roqPlatform.roles({
	limit: 10,
	withUserCount: true,
    filter: {
	    key: {
        like: "mar%"
      }
  }
})
ParameterTypeDescription
limitintegerLimit the results
withUserCountbooleanInclude the user count for this role
filterobjectFilter the result

User roles managements

These APIs are available on the generated SDK and can be used on the server-side only.

assignRolesToUser()

The `assignRolesToUser() API will assign a role or roles to a user.

import { roqServerClient } from "lib/roq/roq-server-client";
 
const assignStatus = await roqServerClient.roqPlatform.asSuperAdmin().assignRolesToUser({
	userId: "7877d2d0-dea7-473e-a158-57eca3123906",
	roleKeys: [" channel-owner", "marketing"]
})
ParameterTypeDescription
userIdstringThe user id which roles to be applied
roleKeysarrayKey roles

unassignRolesFromUser()

The unassignRolesFromUser() will unassign a role or roles from the user.

import { roqServerClient } from "lib/roq/roq-server-client";
 
const unassignStatus = await roqServerClient.roqPlatform.asSuperAdmin().unassignRolesFromUser({
	userId: "7877d2d0-dea7-473e-a158-57eca3123906",
	roleKeys: ["marketing"]
})
ParameterTypeDescription
userIdstringThe user id which a role or roles to be removed
roleKeysarrayKey roles