String Functions

Modified on Wed, 11 Mar at 1:15 PM

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


FunctionDescriptionExample Usage
containsChecks if a string contains a substring.contains(property, 'substring')
startswithChecks if a string starts with a prefix.startswith(property, 'prefix')
endswithChecks 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 name property 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 title property 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 color property 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

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article