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
| Header | Type | Description |
|---|---|---|
Content-Type | string | Must be set to application/json. |
accessToken | string | A 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:
| Field | Type | Description |
|---|---|---|
companyId | string | The unique identifier of the company for which the CPN is being created. |
productId | string | The unique identifier of the product or variant. |
cpn | string | The custom Customer Part Number to assign. |
Sample Request Body
{
"companyId": "683808ee2b054dc60961637c",
"productId": "687a84a7958d6a5c0d0c7a35",
"cpn": "TEST-CPN-001"
}
Response
Success Response
| Status Code | Description |
|---|---|
| 200 OK | The request was successful, and the new CPN was created. |
Success Response Body Structure
| Field | Type | Description |
|---|---|---|
success | boolean | Indicates if the request was successful. |
message | string | Message indicating the result of the operation. |
data | object | Contains 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 Code | Description |
|---|---|
| 400 Bad Request | Invalid request format, missing data, or validation failure. |
| 401 Unauthorized | Invalid or missing access token. |
| 403 Forbidden | Access denied. |
| 404 Not Found | Company or product not found. |
| 500 Internal Server Error | Server encountered an unexpected error. |
Notes
- The company must exist and must not be locked (
isLock: false) for CPN creation to succeed. - The
productIdcan represent either a product or one of its variants. - Ensure the provided
cpnis unique per company-product combination. - A valid access token is required for authentication.