Currently it is possible to assign users to a form with different role such as dataentry, editor, manager. As there is a new permission to validate the data, how can we give the role to validate to a user using API.
I found out that it is possible using the new KPI API. KoBo API examples, using new KPI endpoints
I have explain below as follows as:-
- Define the New Role in Your System
Ensure your backend/DB supports the new role validator for forms.
Add this role to your roles/permissions table or enum if necessary.
- API Endpoint to Assign Roles
You probably have an API to assign roles. It might look like this:
POST /api/forms/{formId}/users/{userId}/roles
Request body:
{
“role”: “validator”
}
Example Response:
{
“success”: true,
“message”: “Role ‘validator’ assigned to user 123 on form 456”
}
- Example Implementation
Backend pseudocode (e.g., Node.js/Express):
app.post(‘/api/forms/:formId/users/:userId/roles’, (req, res) => {
const { formId, userId } = req.params;
const { role } = req.body;
// Validate role is one of allowed roles (including ‘validator’)
if (![‘dataentry’, ‘editor’, ‘manager’, ‘validator’].includes(role)) {
return res.status(400).json({ error: ‘Invalid role’ });
}
// Assign the role to the user for the given form in DB
assignRoleToUserOnForm(userId, formId, role)
.then(() => res.json({ success: true }))
.catch(err => res.status(500).json({ error: ‘Failed to assign role’ }));
});
- If You’re Using RBAC or Permission Libraries
Add the validator role in your roles config.
Assign permissions related to validating data to the validator role.