Skip to main content

Search products

In this example, we demonstrate how to quickly search for products by title using the OneEntry API.

✅ Purpose of the scenario:

  • Connect to the OneEntry API
  • Search products by title text
  • Review the search results

✅ What you need:

  • A valid PROJECT_URL and APP_TOKEN for authentication with the OneEntry API.
  • Products with titles configured in OneEntry.

📌 Important:

  • searchProduct returns a plain array, not { items, total }.
  • Search is based on the title field of localizeInfos with language consideration.
  • 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:

  • Search products — In this example, we demonstrate how to quickly search for products by title using the OneEntry API.

Scenario

1. Import defineOneEntry from SDK and define PROJECT_URL and APP_TOKEN

Example:

import { defineOneEntry } from 'oneentry';

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. Search products with Products.searchProduct()

Example:

const results = await Products.searchProduct('ball', 'en_US');
console.log('Search results: ', results);
Result:
[
{
"id": 14,
"attributeSetIdentifier": "product",
"localizeInfos": {
"title": "Green ball"
},
"statusLocalizeInfos": {},
"isVisible": true,
"statusIdentifier": null,
"position": 1,
"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": 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": 13,
"attributeSetIdentifier": "product",
"localizeInfos": {
"title": "Red ball"
},
"statusLocalizeInfos": {},
"isVisible": true,
"statusIdentifier": null,
"position": 1,
"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": {}
}
]

Final example

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

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. Search products with [Products.searchProduct()](/docs/products/searchProduct)
const results = await Products.searchProduct('ball', 'en_US');
console.log('Search results: ', results);