Skip to main content

Get a single product by ID

Fetches a single product by its numeric ID, with its attributes, price and localized content.

What this example does:

  • Fetches a single product by its numeric ID
  • Accesses product price and localized title
  • Reads attribute values such as currency from the product

Prerequisites:

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

Notes:

  • By default (isShell: true) the SDK returns an error object instead of throwing, so check the result, e.g. 'statusCode' in result. With isShell: false it throws, and you handle errors with try/catch. See Errors.

Platform docs:

SDK reference:

Try it live​

Run this example in the JS SDK sandbox. Connect your Project URL and App Token on first visit, then open:

Scenario​

1. Import defineOneEntry and define PROJECT_URL and APP_TOKEN​

import { defineOneEntry } from 'oneentry';

const PROJECT_URL = 'https://your-project.oneentry.cloud';
const APP_TOKEN = 'your-app-token';

2. Create an API client with defineOneEntry()​

const { Products } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});

3. Get the product with Products.getProductById()​

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": {},
"isPositionLocked": false,
"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​

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

console.log('Title: ', title);
console.log('Price: ', price);
console.log('Currency: ', currency);
Result:
Title: Orange ball
Price: 400
Currency: USD

Final example​

// 1. Import defineOneEntry and define PROJECT_URL and APP_TOKEN
import { defineOneEntry } from 'oneentry';

const PROJECT_URL = 'https://your-project.oneentry.cloud';
const APP_TOKEN = 'your-app-token';

// 2. Create an API client with defineOneEntry()
const { Products } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});

// 3. Get the product with 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 currency = product.attributeValues.currency?.value;

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