Users and User Groups

Managing User Group Membership

This guide demonstrates how to manage user membership in groups through the Venddor API. You'll learn how to view user group memberships, add users to groups, and remove users from groups.

Note: Proper user group management is essential for controlling access, applying special pricing rules, and providing customized experiences.

View User's Group Memberships

To retrieve information about which groups a user belongs to, use the GET method with the user ID:

GET /users/{id}/usergroups

Retrieves all user group memberships for the specified user, along with their status in each group.

Example Request

curl -X GET 'https://www.venddor.com.br/api/users/3/usergroups'

This request returns all groups that the user with user_id=3 is associated with, except those with the Available status.

Response Parameters

Parameter Description
link_id The ID of the link that assigns the user to the group
usergroup_id The ID of the user group
status The user's status in the group

Status Values

Code Status Description
A Active The user is a member of the group
F Available The user is not a member of the group
P Pending The user has requested to join the group
D Declined The user's request to join the group has been declined
Note: Groups with the Available status will not be returned in the response.

Add User to a Group

To add a user to a group, change their status in the group to Active:

PUT /users/{user_id}/usergroups/{group_id}

Updates a user's status in a specific group.

Example Request

curl --header 'Content-type: text/plain' -X PUT 'https://www.venddor.com.br/api/users/3/usergroups/5' --data-binary 'status=A'

This request adds the user with user_id=3 to the group with usergroup_id=5 by setting their status to Active.

Successful Response

If the user is successfully added to the group, you will receive the message: Status has been changed.

Error Responses

Status Code Description
400 Bad Request The user group doesn't exist or you're trying to add a customer to an administrator group
404 Not Found The user doesn't exist

Remove User from a Group

There are two methods to remove a user from a group:

PUT /users/{user_id}/usergroups/{group_id}

Method 1: Change the user's status to Available using the PUT method:

curl --header 'Content-type: text/plain' -X PUT 'https://www.venddor.com.br/api/users/3/usergroups/5' --data-binary 'status=F'
DELETE /users/{user_id}/usergroups/{group_id}

Method 2: Use the DELETE method to remove the user from the group:

curl -X DELETE 'https://www.venddor.com.br/api/users/3/usergroups/5'
Tip: Both methods achieve the same result. Choose the one that best fits your implementation.