Skip to main content

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

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 include all required CPN data.

FieldTypeDescription
partNumbersarrayArray of CPN objects to be created. Each object must contain company, product, and CPN details.

Each CPN Object (partNumbers[])

FieldTypeRequiredDescription
companyIdstringYesThe unique identifier of the company.
productIdstringYesThe unique identifier of the product or variant.
cpnstringYesThe 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 CodeDescription
200 OKThe 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 CodeDescription
400 Bad RequestMissing required fields, invalid IDs, or no valid entries found.
401 UnauthorizedInvalid or missing access token.
403 ForbiddenAccess denied.
404 Not FoundCompany not found.
500 Internal Server ErrorAn 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.