Skip to main content

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

ParameterTypeDescription
productGroup_idstringThe unique identifier of the product group to update.

Request Headers

HeaderTypeDescription
Content-TypestringMust be application/json.
accessTokenstringAccess 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:

FieldTypeDescription
namestringThe updated name of the product group.
statusbooleanThe updated status of the product group.
restrictAccessbooleanWhether access to this group should be restricted.
productsarrayArray of product IDs to ADD to the group.
productsToRemovearrayArray 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

FieldTypeDescription
successbooleanIndicates the success status of the request, typically true for a successful operation.
messagestringA message conveying the outcome of the operation, e.g., "ProductGroup updated Successfully".
dataobjectThe updated product group object with all current details.

Error Responses

Status CodeDescription
400Bad Request: Invalid input data or products don't exist.
401Unauthorized: Access token is invalid or missing.
404Not Found: The specified product group could not be found.
500Internal Server Error: An error occurred on the server.

Notes

  • Adding Products: Use the products array to add new products to the group. Products that are already in the group will not be duplicated.
  • Removing Products: Use the productsToRemove array 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 products and productsToRemove arrays.
  • Product Validation: The API validates that all product IDs in the products array 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 productGroups array. Similarly, when products are removed, the group's ID is removed from the product's productGroups array.
  • 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.