Is there an API to add validate permission for a user to a form

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

1 Like

I have explain below as follows as:-

  1. 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.

  1. 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”
}

  1. 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’ }));
});

  1. 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.

1 Like