Filter products with price range
✅ Purpose of the scenario:
- Define Price Range
- Form filters array and pass as filter
- Apply Filter and review results
✅ What you need:
- A valid PROJECT_URL and APP_TOKEN for authentication with the OneEntry API.
- Products with "price" field
- Price range data
📌 Important:
- We do not handle errors in these examples.
- You can handle errors in trycatch or in a construction like "await Promise.catch((error) => error)"
Scenario
1. Import oneEntry and define url and 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() function
Example:
const { Products } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});
3. Form array of filtering conditions
Example:
[
{
"attributeMarker": "price",
"conditionMarker": "mth",
"conditionValue": 100,
"isNested": false
},
{
"attributeMarker": "price",
"conditionMarker": "lth",
"conditionValue": 500,
"isNested": false
}
]
4. Defining the request parameters
Example:
{
"offset": 0,
"limit": 20,
"sortKey": "price",
"sortOrder": "ASC"
}
5. Receiving products data
Example:
{
"items": [
{
"id": 11,
"localizeInfos": {
"title": "Silver"
},
"statusIdentifier": null,
"statusLocalizeInfos": {},
"attributeSetIdentifier": "ticket",
"position": 3,
"templateIdentifier": null,
"shortDescTemplateIdentifier": null,
"price": 150,
"additional": {
"prices": {
"min": 100,
"max": 999
}
},
"sku": null,
"isSync": true,
"attributeValues": {
"price": {
"type": "real",
"value": "150",
"isIcon": false,
"position": 0,
"additionalFields": [],
"isProductPreview": false
},
"currency": {
"type": "string",
"value": "USD",
"isIcon": false,
"position": 1,
"additionalFields": [],
"isProductPreview": false
}
},
"isVisible": true
},
{
"id": 6,
"localizeInfos": {
"title": "Green service"
},
"statusIdentifier": null,
"statusLocalizeInfos": {},
"attributeSetIdentifier": "service",
"position": 1,
"templateIdentifier": null,
"shortDescTemplateIdentifier": null,
"price": 150,
"additional": {
"prices": {
"min": 100,
"max": 999
}
},
"sku": "",
"isSync": true,
"attributeValues": {
"price": {
"type": "real",
"value": "150",
"isIcon": false,
"position": 0,
"additionalFields": [],
"isProductPreview": false
},
"type": {
"type": "list",
"value": [],
"isIcon": false,
"position": 1,
"additionalFields": [],
"isProductPreview": false
},
"currency": {
"type": "string",
"value": "USD",
"isIcon": false,
"position": 2,
"additionalFields": [],
"isProductPreview": false
},
"sku": {
"type": "string",
"value": "",
"isIcon": false,
"position": 3,
"additionalFields": [],
"isProductPreview": false
}
},
"isVisible": true
},
{
"id": 12,
"localizeInfos": {
"title": "Gold"
},
"statusIdentifier": null,
"statusLocalizeInfos": {},
"attributeSetIdentifier": "ticket",
"position": 2,
"templateIdentifier": null,
"shortDescTemplateIdentifier": null,
"price": 200,
"additional": {
"prices": {
"min": 100,
"max": 999
}
},
"sku": null,
"isSync": true,
"attributeValues": {
"price": {
"type": "real",
"value": "200",
"isIcon": false,
"position": 0,
"additionalFields": [],
"isProductPreview": false
},
"currency": {
"type": "string",
"value": "USD",
"isIcon": false,
"position": 1,
"additionalFields": [],
"isProductPreview": false
}
},
"isVisible": true
},
{
"id": 2,
"localizeInfos": {
"title": "Red service"
},
"statusIdentifier": null,
"statusLocalizeInfos": {},
"attributeSetIdentifier": "service",
"position": 4,
"templateIdentifier": null,
"shortDescTemplateIdentifier": null,
"price": 250,
"additional": {
"prices": {
"min": 100,
"max": 999
}
},
"sku": "",
"isSync": true,
"attributeValues": {
"price": {
"type": "real",
"value": "250",
"isIcon": false,
"position": 0,
"additionalFields": [],
"isProductPreview": false
},
"type": {
"type": "list",
"value": [],
"isIcon": false,
"position": 1,
"additionalFields": [],
"isProductPreview": false
},
"currency": {
"type": "string",
"value": "USD",
"isIcon": false,
"position": 2,
"additionalFields": [],
"isProductPreview": false
},
"sku": {
"type": "string",
"value": "",
"isIcon": false,
"position": 3,
"additionalFields": [],
"isProductPreview": false
}
},
"isVisible": true
},
{
"id": 13,
"localizeInfos": {
"title": "Red ball"
},
"statusIdentifier": null,
"statusLocalizeInfos": {},
"attributeSetIdentifier": "product",
"position": 7,
"templateIdentifier": null,
"shortDescTemplateIdentifier": null,
"price": 300,
"additional": {
"prices": {
"min": 100,
"max": 999
}
},
"sku": null,
"isSync": true,
"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
}
},
"isVisible": true
},
{
"id": 14,
"localizeInfos": {
"title": "Green ball"
},
"statusIdentifier": null,
"statusLocalizeInfos": {},
"attributeSetIdentifier": "product",
"position": 6,
"templateIdentifier": null,
"shortDescTemplateIdentifier": null,
"price": 340,
"additional": {
"prices": {
"min": 100,
"max": 999
}
},
"sku": null,
"isSync": true,
"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
}
},
"isVisible": true
},
{
"id": 15,
"localizeInfos": {
"title": "Orange ball"
},
"statusIdentifier": null,
"statusLocalizeInfos": {},
"attributeSetIdentifier": "product",
"position": 5,
"templateIdentifier": null,
"shortDescTemplateIdentifier": null,
"price": 400,
"additional": {
"prices": {
"min": 100,
"max": 999
}
},
"sku": null,
"isSync": true,
"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
}
},
"isVisible": true
},
{
"id": 7,
"localizeInfos": {
"title": "Blue service"
},
"statusIdentifier": null,
"statusLocalizeInfos": {},
"attributeSetIdentifier": "service",
"position": 8,
"templateIdentifier": null,
"shortDescTemplateIdentifier": null,
"price": 450,
"additional": {
"prices": {
"min": 100,
"max": 999
}
},
"sku": "",
"isSync": true,
"attributeValues": {
"price": {
"type": "real",
"value": "450",
"isIcon": false,
"position": 0,
"additionalFields": [],
"isProductPreview": false
},
"type": {
"type": "list",
"value": [],
"isIcon": false,
"position": 1,
"additionalFields": [],
"isProductPreview": false
},
"currency": {
"type": "string",
"value": "USD",
"isIcon": false,
"position": 2,
"additionalFields": [],
"isProductPreview": false
},
"sku": {
"type": "string",
"value": "",
"isIcon": false,
"position": 3,
"additionalFields": [],
"isProductPreview": false
}
},
"isVisible": true
}
],
"total": 8
}
Final example
// 1. Import oneEntry 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
const { FileUploading, FormData } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});
// 3. Form array of filtering conditions
const body: any = [
{
attributeMarker: 'price',
conditionMarker: 'mth', // more than
conditionValue: 100,
isNested: false,
},
{
attributeMarker: 'price',
conditionMarker: 'lth', // less than
conditionValue: 500,
isNested: false,
},
];
// 4. Defining the request parameters
const userQuery: IProductsQuery = {
offset: 0,
limit: 20,
sortKey: 'price',
sortOrder: 'ASC',
};
// 5. Receiving products data
const products = await Products.getProducts(body, 'en_US', userQuery);
console.log(products);