Create Multiple CPNs
This POST API allows you to create multiple Customer Part Numbers (CPNs) in bulk.
It validates company status, product existence, removes duplicates, and automatically syncs valid entries with Elasticsearch.
Endpoint Details
- URL:
/api/cpn/multiple - Method:
POST - Authentication: Bearer Token (required)
Authentication
You must provide a valid accessToken in the request headers to authenticate and access this endpoint.
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 include all required CPN data.
| Field | Type | Description |
|---|---|---|
partNumbers | array | Array of CPN objects to be created. Each object must contain company, product, and CPN details. |
Each CPN Object (partNumbers[])
| Field | Type | Required | Description |
|---|---|---|---|
companyId | string | Yes | The unique identifier of the company. |
productId | string | Yes | The unique identifier of the product or variant. |
cpn | string | Yes | The customer part number. |
Sample Request Body
{
"partNumbers": [
{
"companyId": "683808ee2b054dc60961637c",
"productId": "687a84a7958d6a5c0d0c7a35",
"cpn": "BULK-CPN-001"
},
{
"companyId": "683808ee2b054dc60961637c",
"productId": "687a84a7958d6a5c0d0c7a36",
"cpn": "BULK-CPN-002"
}
]
}
Response
Success Response
| Status Code | Description |
|---|---|
| 200 OK | The CPNs were successfully inserted into the database. |
Example Success Response
{
"success": true,
"message": "Inserted 2 CPN records successfully",
"data": [
{
"id": "64ffb2e84b5d3c6a0a4e1e1a",
"companyId": "683808ee2b054dc60961637c",
"productId": "687a84a7958d6a5c0d0c7a35",
"cpn": "BULK-CPN-001"
},
{
"id": "64ffb2e84b5d3c6a0a4e1e1b",
"companyId": "683808ee2b054dc60961637c",
"productId": "687a84a7958d6a5c0d0c7a36",
"cpn": "BULK-CPN-002"
}
]
}
Error Responses
| Status Code | Description |
|---|---|
| 400 Bad Request | Missing required fields, invalid IDs, or no valid entries found. |
| 401 Unauthorized | Invalid or missing access token. |
| 403 Forbidden | Access denied. |
| 404 Not Found | Company not found. |
| 500 Internal Server Error | An unexpected server error occurred. |
Notes
- Companies must exist and must not be locked (
isLock: false). - Invalid company or product IDs are ignored.
- Duplicate entries are automatically skipped without halting the process.
- If all records already exist, the response will indicate no new inserts.
- Successfully created CPNs are synced to Elasticsearch automatically.