Get All CPNs
This API endpoint retrieves a list of Customer Part Numbers (CPNs) from the server, allowing you to filter results by various criteria such as companyId, search, sorting, and pagination parameters.
HTTP Request
- URL:
/api/cpn - Method:
GET - Headers:
accessToken: Required. This is your access token for authenticating the request.
Query Parameters
To effectively retrieve and manage Customer Part Numbers (CPNs), you can include the following query parameters:
| Parameter | Type | Description |
|---|---|---|
page | Integer | The page number to retrieve; defaults to 1 if not specified. |
limit | Integer | The number of items to retrieve per page; defaults to 10. |
companyId | String | The unique identifier of the company whose CPNs you want to retrieve. |
search | String | Search keyword to filter by CPN (case-insensitive partial match). |
sortBy | String | Field to sort by (e.g., cpn, createdAt, _id). |
sortOrder | String | Sorting order: "asc" for ascending, "desc" for descending. |
CURL Example
Below is a sample cURL command that demonstrates how to make a request to the API endpoint:
curl --location '<BASE_URL>/api/cpn?page=1&limit=10&companyId=<COMPANY_ID>&search=<SEARCH_TEXT>&sortBy=cpn&sortOrder=asc' --header 'accessToken: <ACCESS_TOKEN>'
Response
- 200 OK: The request was successful, and the server returned a list of CPNs.
- 4XX: Client errors indicating issues such as an invalid access token or missing parameters.
- 5XX: Server errors indicating that something went wrong on the server's end.
Sample JSON Response
Below is an example of the JSON response you might receive from making a request to this endpoint:
{
"success": true,
"data": [
{
"_id": "69021dec6f3d8d4a6ebf8dba",
"companyId": "683808ee2b054dc60961637c",
"productId": "687a84a7958d6a5c0d0c7a35",
"cpn": "testing",
"createdBy": {
"id": "69019a38743e239a3f8f8be7",
"name": "Evangeline Schmidt",
"email": "eva@gmail.com",
"type": "store"
},
"createdAt": "2025-10-29T14:00:12.567Z",
"updatedAt": "2025-10-29T14:01:17.363Z"
}
// Additional CPNs omitted for brevity...
],
"pagination": {
"page": 1,
"limit": 10,
"total": 100,
"pages": 10
}
}
Response Details
| Key | Type | Description |
|---|---|---|
success | Boolean | Indicates if the request was successful. |
data | Array of Objects | List of Customer Part Numbers (CPNs). |
pagination | Object | Provides pagination details. |
Customer Part Number (CPN) Data
| Field | Type | Description |
|---|---|---|
_id | String | The unique identifier of the CPN. |
companyId | String | The unique identifier of the company associated with the CPN. |
productId | String | The product or variant ID associated with the CPN. |
cpn | String | The Customer Part Number value. |
createdBy | Object | Information about the user who created the CPN. |
createdAt | String | Date and time when the record was created (ISO 8601 format). |
updatedAt | String | Date and time when the record was last updated (ISO 8601 format). |
createdBy Object
| Field | Type | Description |
|---|---|---|
id | String | The ID of the user who created it. |
name | String | The name of the creator. |
email | String | The email of the creator. |
type | String | The creator's user type (e.g. store). |
Pagination Details
| Key | Type | Description |
|---|---|---|
page | Integer | Current page number. |
limit | Integer | Number of items returned per page. |
total | Integer | Total number of items available. |
pages | Integer | Total number of available pages. |
Notes
- Ensure that the
accessTokenprovided is valid and not expired. - The
searchparameter performs a case-insensitive partial match on thecpnfield. - The
productIdfield can refer to either a product or a product variant. - Use pagination parameters (
page,limit) for efficient data retrieval. - Sorting parameters (
sortBy,sortOrder) allow flexible ordering of results.