Update Product Group
The PUT endpoint updates the details of an existing product group specified by the productGroup_id, including the ability to add or remove products from the group.
Endpoint
- URL:
productGroup/{productGroup_id} - Method:
PUT
Authentication
- Header:
accessToken - Type: Bearer Token
- Value:
<ACCESS-TOKEN>
Path Parameters
| Parameter | Type | Description |
|---|---|---|
productGroup_id | string | The unique identifier of the product group to update. |
Request Headers
| Header | Type | Description |
|---|---|---|
Content-Type | string | Must be application/json. |
accessToken | string | Access token for authentication. (required) |
Request Body
The request body should include the details to be updated for the product group. Below are the fields that can be updated:
| Field | Type | Description |
|---|---|---|
name | string | The updated name of the product group. |
status | boolean | The updated status of the product group. |
restrictAccess | boolean | Whether access to this group should be restricted. |
products | array | Array of product IDs to ADD to the group. |
productsToRemove | array | Array of product IDs to REMOVE from the group. |
Sample Request Bodies
Update basic information only:
{
"name": "Updated Electronics Group",
"status": true,
"restrictAccess": false
}
Add products to the group:
{
"products": ["64f123abc456789012345678", "64f123abc456789012345679"]
}
Remove products from the group:
{
"productsToRemove": ["64f123abc456789012345678"]
}
Add and remove products in the same request:
{
"name": "Updated Group Name",
"products": ["64f123abc456789012345680"],
"productsToRemove": ["64f123abc456789012345678"],
"status": true
}
Response
- Status Code: 200 OK
Sample Response Body
{
"success": true,
"message": "ProductGroup updated Successfully",
"data": {
"id": "66d220c8f57178681728212e",
"name": "Updated Electronics Group",
"status": true,
"restrictAccess": false,
"createdAt": "2024-08-30T19:43:04.216Z",
"updatedAt": "2024-08-31T18:18:28.191Z"
}
}
Success Response Fields
| Field | Type | Description |
|---|---|---|
success | boolean | Indicates the success status of the request, typically true for a successful operation. |
message | string | A message conveying the outcome of the operation, e.g., "ProductGroup updated Successfully". |
data | object | The updated product group object with all current details. |
Error Responses
| Status Code | Description |
|---|---|
| 400 | Bad Request: Invalid input data or products don't exist. |
| 401 | Unauthorized: Access token is invalid or missing. |
| 404 | Not Found: The specified product group could not be found. |
| 500 | Internal Server Error: An error occurred on the server. |
Notes
- Adding Products: Use the
productsarray to add new products to the group. Products that are already in the group will not be duplicated. - Removing Products: Use the
productsToRemovearray to remove products from the group. If a product is not in the group, it will be ignored. - Combined Operations: You can add and remove products in the same request by including both
productsandproductsToRemovearrays. - Product Validation: The API validates that all product IDs in the
productsarray exist before adding them to the group. - Data Consistency: When products are added to a group, the group's ID is automatically added to the product's
productGroupsarray. Similarly, when products are removed, the group's ID is removed from the product'sproductGroupsarray. - Ensure you replace
{productGroup_id}in the URL with the actual unique identifier of the product group being updated. - Provide a valid and active access token in the request header to authenticate your request.