Users API
Introduction
With this Users API you can create, update, and deactivate users. Other than that you can get all the information about users.
Mutations
createUser()
The createUser
API is used to synchronize user data to ROQ. You can find the full API documentation of this mutation here (opens in a new tab).
It's important to save the returned user ID in your database because the API needs it for other functionalities.
roqClient.asSuperAdmin().createUser({
user: {
reference: '8d04d09a-8ff8-4393-840d-c69f3f1f7dfa',
email: 'xyz789@gmail.com',
phone: '+15550001234',
firstName: 'Anna',
lastName: 'W',
locale: 'en-Us',
timezone: 'Asia/Bangkok',
isOptedIn: false,
active: true
},
});
Parameter | Type | Description |
---|---|---|
reference | string | Here you can set your identifier (e.g. the UUID of the user entity in your database). This way you can filter users by your own identifier. |
email | string | Email of the user |
firstName | string | First name of the user |
lastName | string | Last name of the user |
isOptedIn | boolean | Set to true after the user confirm the email. |
active | boolean | Set to true if the user is activate and able to login to your application. |
locale | string | The locale represents the language and the country of the user, e.g. en-US means “english in US”. The locale is used for translations of all UI components as well as for sending notifications. |
active | boolean | Set to true if the user is activate and able to login to your application. |
tenantId | UUID | ID of the tenant which you created using the createTenant() API |
updateUser()
To modify user data, simply use the updateUser()
(opens in a new tab) API. The mutation process is similar to that of createUser()
, but instead of creating a new user, updateUser()
will alter the existing user data.
const updateUser = await roqClient.asSuperAdmin().updateUser({
id: "4c94b763-9021-499f-8ea3-b01adcdafe57",
user: {
}
})
Parameter | Type | Description |
---|---|---|
id | uuid | The user ID |
user | object | The user data that needs to be updated. Please refer to the link (opens in a new tab) for the necessary details. |
Deactivating a User
To deactivate a user, just use the updateUser()
mutation and set the active
user option to false
.
This is only possible from the server side of your application.
roqClient.asSuperAdmin().updateUser({
id: "4c94b763-9021-499f-8ea3-b01adcdafe57"
user: {
active: false
},
});
Queries
users()
You can fetch all users using the users()
(opens in a new tab) query.
roqClient.asSuperAdmin().users({
limit: 10
});
All the GraphQL query parameters in this documentation can be applied here to narrow down the results.
Filter By Reference
With users()
API method you can filter users by reference
. For example, if you want to filter the user using reference 8d04d09a-8ff8-4393-840d-c69f3f1f7dfa
:
const usersResponse = await roqClient.asSuperAdmin().users({
filter: {
reference: {
equalTo: '8d04d09a-8ff8-4393-840d-c69f3f1f7dfa'
}
}
})
The output result from the code above is:
{ users: { data: [
{
id: '2d8763f8-ab49-40d1-b989-372bcdd88189',
reference: '8d04d09a-8ff8-4393-840d-c69f3f1f7dfa',
firstName: '',
lastName: '',
active: true,
email: 'xyz789@gmail.com',
phone: null,
locale: 'en-US',
isOptedIn: false,
synced: true,
tenantId: 'ee764883-f2c3-4486-9de6-070345e350af',
customData: {},
timezone: null,
avatarUrl: '',
createdAt: '2023-08-08T01:25:38.821Z',
updatedAt: '2023-08-08T01:25:38.821Z'
}
], totalCount: 1 } }
user()
You can fetch a specific user information using the user()
query. The API documentation is here (opens in a new tab).
roqClient.asSuperAdmin().user({
id: '80c81294-f338-4819-9b1f-acc314babd5f'
});
Parameter | Type | Description |
---|---|---|
id | uuid | The user ID. You can get the id by filter the users() response or use the repsonse of the createUser() API. |