Filtering Stories by Defining a Value Range
In a common shop content structure implementation, a simple price range products filter is often necessary. A single filter_query can be crafted to retrieve products that exceed or fall below a specified price point. In this scenario, the gt_float and lt_float filters are combined to obtain all products within a given price range.
Example Request and Response
Section titled “Example Request and Response”The following example demonstrates how to receive products (stories of that story type) with a price value between 100 and 300.
curl "https://api.storyblok.com/v2/cdn/stories/?starts_with=products%2F&filter_query%5Bprice%5D%5Blt_float%5D=300&filter_query%5Bprice%5D%5Bgt_float%5D=100"// Using the Universal JavaScript Client:// https://github.com/storyblok/storyblok-js-clientStoryblok.get('cdn/stories/', { "starts_with": "products/", "filter_query[price][lt_float]": "300", "filter_query[price][gt_float]": "100"}) .then(response => { console.log(response) }).catch(error => { console.log(error) })$client = new \Storyblok\Client('YOUR_STORYBLOK_SPACE_ACCESS_TOKEN');
$client->getStories([ "starts_with" => "products/", "filter_query[price][lt_float]" => "300", "filter_query[price][gt_float]" => "100"])->getBody();HttpResponse<String> response = Unirest.get("https://api.storyblok.com/v2/cdn/stories/?starts_with=products%2F&filter_query%5Bprice%5D%5Blt_float%5D=300&filter_query%5Bprice%5D%5Bgt_float%5D=100") .asString();var client = new RestClient("https://api.storyblok.com/v2/cdn/stories/?starts_with=products%2F&filter_query%5Bprice%5D%5Blt_float%5D=300&filter_query%5Bprice%5D%5Bgt_float%5D=100");var request = new RestRequest(Method.GET);
IRestResponse response = client.Execute(request);import requests
url = "https://api.storyblok.com/v2/cdn/stories/"
querystring = {"starts_with":"products/","filter_query[price][lt_float]":"300","filter_query[price][gt_float]":"100"}
payload = ""headers = {}
response = requests.request("GET", url, data=payload, headers=headers, params=querystring)
print(response.text)require 'storyblok'client = Storyblok::Client.new(token: 'YOUR_TOKEN')
client.stories({:params => { "starts_with" => "products/", "filter_query[price][lt_float]" => "300", "filter_query[price][gt_float]" => "100"}})import Foundation
let request = NSMutableURLRequest(url: NSURL(string: "https://api.storyblok.com/v2/cdn/stories/?starts_with=products%2F&filter_query%5Bprice%5D%5Blt_float%5D=300&filter_query%5Bprice%5D%5Bgt_float%5D=100")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0)request.method = "GET"
let session = URLSession.sharedlet dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) }})
dataTask.resume(){ "stories": [ { "name": "Product A", "created_at": "2024-03-07T15:42:27.967Z", "published_at": "2024-03-07T15:59:58.325Z", "id": 457608234, "uuid": "43a86f66-0b12-4653-9ed9-6dbceb85cb60", "content": { "_uid": "2fe813f5-e86a-4f56-a4ea-e9a9bfdc354c", "image": { "id": null, "alt": null, "name": "", "focus": null, "title": null, "source": null, "filename": "", "copyright": null, "fieldtype": "asset", "meta_data": {} }, "price": "239.99", "component": "product" }, "slug": "product-a", "full_slug": "products/product-a", "sort_by_date": null, "position": 0, "tag_list": ["Product Tag"], "is_startpage": false, "parent_id": 457608232, "meta_data": null, "group_id": "7eb7a5f8-8d0b-4c4c-9404-262f7d09f910", "first_published_at": "2024-03-07T15:42:52.308Z", "release_id": null, "lang": "default", "path": null, "alternates": [], "default_full_slug": null, "translated_slugs": null } ], "cv": 1711108220, "rels": [], "links": []}Get in touch with the Storyblok community