Get products by IDs
In this example, we demonstrate how to retrieve multiple products at once by passing a comma-separated list of product IDs using the OneEntry API.
✅ Purpose of the scenario:
- Connect to the OneEntry API
- Pass a comma-separated list of product IDs
- Retrieve the matched products and review the results
✅ What you need:
- A valid PROJECT_URL and APP_TOKEN for authentication with the OneEntry API.
- Known product IDs that exist in your OneEntry project.
📌 Important:
- getProductsByIds returns a plain array IProductsEntity[], NOT
{ items, total }. - These examples do not include error handling.
- You can manage errors using a try-catch block or by employing a construction like await Promise.catch((error) => error).
📚 See in documentation:
📦 SDK reference:
Try it live
Run this method interactively in the JS SDK sandbox — connect your Project URL and App Token on first visit, then open:
- Get products by IDs — In this example, we demonstrate how to retrieve multiple products at once by passing a comma-separated list of product IDs using the OneEntry API.
Scenario
1. Import defineOneEntry from SDK and define PROJECT_URL and APP_TOKEN
Example:
import { defineOneEntry } from 'oneentry';
import type { IProductsEntity } from 'oneentry/dist/products/productsInterfaces';
const PROJECT_URL = 'your-project-url';
const APP_TOKEN = 'your-app-token';
2. Creating an API client with defineOneEntry()
Example:
const { Products } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});
3. Call Products.getProductsByIds() with Products.getProductsByIds()
Example:
const products = await Products.getProductsByIds('13,14,15', 'en_US');
console.log('Products: ', products);
Result:
[
{
"id": 15,
"attributeSetIdentifier": "product",
"localizeInfos": {
"title": "Orange ball"
},
"statusLocalizeInfos": {},
"isVisible": true,
"statusIdentifier": null,
"position": 1,
"templateIdentifier": null,
"shortDescTemplateIdentifier": null,
"price": 400,
"additional": {
"prices": {
"min": 100,
"max": 999
}
},
"sku": null,
"isSync": true,
"categories": [
"products"
],
"paymentStages": null,
"rating": {},
"attributeValues": {
"price": {
"type": "real",
"value": "400",
"isIcon": false,
"position": 0,
"additionalFields": {},
"isProductPreview": false
},
"currency": {
"type": "string",
"value": "USD",
"isIcon": false,
"position": 1,
"additionalFields": {},
"isProductPreview": false
},
"image": {
"type": "image",
"value": [],
"isIcon": false,
"position": 2,
"additionalFields": {},
"isProductPreview": true
}
},
"productPages": [
{
"id": 17,
"pageId": 49,
"productId": 15,
"positionId": 1287,
"categoryPath": "products"
}
],
"blocks": [],
"moduleFormConfigs": [],
"discountConfig": {}
},
{
"id": 14,
"attributeSetIdentifier": "product",
"localizeInfos": {
"title": "Green ball"
},
"statusLocalizeInfos": {},
"isVisible": true,
"statusIdentifier": null,
"position": 2,
"templateIdentifier": null,
"shortDescTemplateIdentifier": null,
"price": 340,
"additional": {
"prices": {
"min": 100,
"max": 999
}
},
"sku": null,
"isSync": true,
"categories": [
"products"
],
"paymentStages": null,
"rating": {},
"attributeValues": {
"price": {
"type": "real",
"value": "340",
"isIcon": false,
"position": 0,
"additionalFields": {},
"isProductPreview": false
},
"currency": {
"type": "string",
"value": "USD",
"isIcon": false,
"position": 1,
"additionalFields": {},
"isProductPreview": false
},
"image": {
"type": "image",
"value": [],
"isIcon": false,
"position": 2,
"additionalFields": {},
"isProductPreview": true
}
},
"productPages": [
{
"id": 18,
"pageId": 49,
"productId": 14,
"positionId": 1288,
"categoryPath": "products"
}
],
"blocks": [],
"moduleFormConfigs": [],
"discountConfig": {}
},
{
"id": 13,
"attributeSetIdentifier": "product",
"localizeInfos": {
"title": "Red ball"
},
"statusLocalizeInfos": {},
"isVisible": true,
"statusIdentifier": null,
"position": 3,
"templateIdentifier": null,
"shortDescTemplateIdentifier": null,
"price": 300,
"additional": {
"prices": {
"min": 100,
"max": 999
}
},
"sku": null,
"isSync": true,
"categories": [
"products"
],
"paymentStages": null,
"rating": {},
"attributeValues": {
"price": {
"type": "real",
"value": "300",
"isIcon": false,
"position": 0,
"additionalFields": {},
"isProductPreview": false
},
"currency": {
"type": "string",
"value": "USD",
"isIcon": false,
"position": 1,
"additionalFields": {},
"isProductPreview": false
},
"image": {
"type": "image",
"value": [],
"isIcon": false,
"position": 2,
"additionalFields": {},
"isProductPreview": true
}
},
"productPages": [
{
"id": 19,
"pageId": 49,
"productId": 13,
"positionId": 1289,
"categoryPath": "products"
}
],
"blocks": [],
"moduleFormConfigs": [],
"discountConfig": {}
}
]
4. Returns a plain array, NOT { items, total }
Example:
const titles = (products as IProductsEntity[]).map((p) => p.localizeInfos?.title);
console.log('titles: ', titles);
Result:
[
"Orange ball",
"Green ball",
"Red ball"
]
Final example
// 1. Import defineOneEntry from SDK and define PROJECT_URL and APP_TOKEN
import { defineOneEntry } from 'oneentry';
import type { IProductsEntity } from 'oneentry/dist/products/productsInterfaces';
const PROJECT_URL = 'your-project-url';
const APP_TOKEN = 'your-app-token';
// 2. Creating an API client with [defineOneEntry()](/docs/index/#Installation)
const { Products } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});
// 3. Call Products.getProductsByIds() with [Products.getProductsByIds()](/docs/products/getProductsByIds)
const products = await Products.getProductsByIds('13,14,15', 'en_US');
console.log('Products: ', products);
// 4. Returns a plain array, NOT `{ items, total }`
const titles = (products as IProductsEntity[]).map((p) => p.localizeInfos?.title);
console.log('titles: ', titles);