Skip to main content

Create CPN

This POST API allows you to create a new Customer Part Number (CPN) for a specific company and product (or variant). The endpoint ensures validation for company status, product existence, and prevents duplicate CPNs.

Endpoint Details

  • URL: /api/cpn/create
  • Method: POST
  • Authentication: Bearer Token (required)

Authentication

You must provide a valid accessToken in the request headers to authenticate and access this endpoint.

Authentication Headers

HeaderTypeDescription
Content-TypestringMust be set to application/json.
accessTokenstringA valid access token is required.

Request Body

The request body must be in JSON format and should contain the details of the new CPN entry as follows:

FieldTypeDescription
companyIdstringThe unique identifier of the company for which the CPN is being created.
productIdstringThe unique identifier of the product or variant.
cpnstringThe custom Customer Part Number to assign.

Sample Request Body

{
"companyId": "683808ee2b054dc60961637c",
"productId": "687a84a7958d6a5c0d0c7a35",
"cpn": "TEST-CPN-001"
}

Response

Success Response

Status CodeDescription
200 OKThe request was successful, and the new CPN was created.

Success Response Body Structure

FieldTypeDescription
successbooleanIndicates if the request was successful.
messagestringMessage indicating the result of the operation.
dataobjectContains the newly created CPN details.

Sample Response Body

{
"success": true,
"message": "Created successfully",
"data": {
"companyId": "683808ee2b054dc60961637c",
"productId": "687a84a7958d6a5c0d0c7a35",
"cpn": "TEST-CPN-001",
"createdBy": {
"id": "64f0a70c6212cdcbe89a2402",
"name": "store",
"type": "api"
},
"_id": "690444673ac9418030097b80",
"createdAt": "2025-10-31T05:08:55.931Z",
"updatedAt": "2025-10-31T05:08:55.931Z",
"__v": 0
}
}

Error Responses

Status CodeDescription
400 Bad RequestInvalid request format, missing data, or validation failure.
401 UnauthorizedInvalid or missing access token.
403 ForbiddenAccess denied.
404 Not FoundCompany or product not found.
500 Internal Server ErrorServer encountered an unexpected error.

Notes

  • The company must exist and must not be locked (isLock: false) for CPN creation to succeed.
  • The productId can represent either a product or one of its variants.
  • Ensure the provided cpn is unique per company-product combination.
  • A valid access token is required for authentication.