Overview
String functions allow filtering based on text content within properties of the root resource. These functions are especially useful when working with string-based fields, enabling precise searches and filtering.
Supported Functions
| Function | Description | Example Usage |
|---|---|---|
| contains | Checks if a string contains a substring. | contains(property, 'substring') |
| startswith | Checks if a string starts with a prefix. | startswith(property, 'prefix') |
| endswith | Checks if a string ends with a suffix. | endswith(property, 'suffix') |
Syntax
String functions follow this general syntax:
FUNCTION_NAME(property_name, 'value')
Examples
Filter items where a property contains a specific value:
$filter=contains(property_name, 'value')
- Example: Retrieve items where the
nameproperty contains'smart':
$filter=contains(name, 'smart')
Filter items where a property starts with a specific value:
$filter=startswith(property_name, 'value')
- Example: Retrieve items where the
titleproperty starts with'Pro':
$filter=startswith(title, 'Pro')
Filter items where a property ends with a specific value:
$filter=endswith(property_name, 'value')
- Example: Retrieve items where the
colorproperty ends with'Red':
$filter=endswith(color, 'Red')
How to Use String function Contains in a Request
- When constructing your API request, add the Contians functions on filter parameter.
http://api2.saleslayer.com/rest/Catalog/Products?$select=prod_ref,cat_ref,prod_title,prod_color&$expand=Variants&$filter=contains(prod_color,'B')
Response Format
{
"value": [
{
"prod_ref": "CuMoApp",
"prod_title": {
"en": "Custom Mobile Apps"
},
"prod_color": {
"en": "Black"
},
"Variants@count": 0,
"cat_ref": [
"OMA"
]
},
{
"prod_ref": "Atrius",
"prod_title": {
"en": "Atrius"
},
"prod_color": {
"en": "Blue"
},
"Variants@count": 0,
"cat_ref": [
"OMA"
]
},
{
"prod_ref": "EC-gfx",
"prod_title": {
"en": "EC-gfxProgram"
},
"prod_color": {
"en": "Blue"
},
"Variants@count": 0,
"cat_ref": [
"LPG"
]
}
],
"@count": 3,
"@readLink": "http://api2.saleslayer.com/rest/Catalog/Products?$select=prod_ref,cat_ref,prod_title,prod_color&$expand=Variants&$filter=contains(prod_color,'B')"
}Using String Functions with Logical Operators
String functions can be combined with logical operators for complex filtering:
$filter=startswith(name, 'Pro') and contains(description, 'advanced')
Notes
- To ensure accurate usage of string functions, refer to the metadata of the root resource. Metadata provides details about the properties available for filtering.
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article