Skip to main content

Get a single product by ID

This method allows you to retrieve a single product by its numeric ID, returning the full product object including attributes, price, and localized content.

✅ Purpose of the scenario:

  • Fetch a single product by its numeric ID
  • Access product price and localized title
  • Read attribute values such as currency from the product

✅ What you need:

  • A valid PROJECT_URL and APP_TOKEN for authentication with the OneEntry API.
  • A known numeric product ID

📌 Important:

  • 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 a single product by ID — This method allows you to retrieve a single product by its numeric ID, returning the full product object including attributes, price, and localized content.

Scenario

1. Import defineOneEntry from SDK and define PROJECT_URL and APP_TOKEN

Example:

import { defineOneEntry } from 'oneentry';
import { IAttributeValues } from 'oneentry/dist/base/utils';

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.getProductById() with getProductById() method

Example:

const product = await Products.getProductById(15, 'en_US');

if ('statusCode' in product) {
throw new Error(product.message);
}
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": {}
}

4. Access product fields

Example:

const title = product.localizeInfos?.title;
const price = product.price;
const attrs = product.attributeValues as IAttributeValues;
const currency = attrs.currency?.value;

console.log('Product: ', product);
console.log('Title: ', title);
console.log('Price: ', price);
console.log('Currency: ', currency);
Result:
{
"product": {
"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": {}
},
"title": "Orange ball",
"price": 400,
"currency": "USD"
}

Final example

// 1. Import defineOneEntry from SDK and define PROJECT_URL and APP_TOKEN
import { defineOneEntry } from 'oneentry';
import { IAttributeValues } from 'oneentry/dist/base/utils';

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.getProductById() with [getProductById() method](/docs/products/#getProductById)
const product = await Products.getProductById(15, 'en_US');

if ('statusCode' in product) {
throw new Error(product.message);
}

// 4. Access product fields
const title = product.localizeInfos?.title;
const price = product.price;
const attrs = product.attributeValues as IAttributeValues;
const currency = attrs.currency?.value;

console.log('Product: ', product);
console.log('Title: ', title);
console.log('Price: ', price);
console.log('Currency: ', currency);