Creating and managing multiple profiles
You can also create multiple user profiles at once using the Batch create user profiles endpoint. To do so, we'll:
- Save a user profile once it is created
- Batch and send our profiles by groups of 20 (according to the API's limit)
- Use user interaction to trigger both events, based on real-world scenarios
We'll create a user profile the same way we did in previous steps, using user input to build our user object. Once created, we'll add the new object into our array of users.
undefined sample
const [pendingUsers, setPendingUsers] = useState([]);
const addUser = () => {
const newUser = {
user_email: userEmail,
role_name: userRole;
country_iso_code: userCountry,
client_integration: userCompany,
};
setPendingUsers((prevUsers) => [...prevUsers, newUser])
}
When working with multiple users at once, we want to ensure we appropiately assign all users. To do so, we'll use each users's input to find the appropiate role ID, fitlering through the roles we saved earlier.
undefined sample
const newUser = () => {
// ...
role_id: roles.find((role) => role.role_name === userRole).role_id;
// ...
};