Sorting by Story Object Property
Stories can be sorted based on custom or predefined properties by employing the sort_by parameter, with field:asc or field:desc as values, allowing for ascending or descending order, respectively.
sort_by=name:asc: Sort by the story object propertynamesort_by=position:desc: Sort stories in the order determined in the Content tabsort_by=first_published_at:desc: Sort by the story object propertyfirst_published_at
Example request and response
Section titled “Example request and response”The following example demonstrates how to sort stories in descending order by their first published date.
curl "https://api.storyblok.com/v2/cdn/stories\?sort_by=first_published_at%3Adesc\&token=ask9soUkv02QqbZgmZdeDAtt\&starts_with=authors"// storyblok-js-client@>=7, node@>=18import Storyblok from "storyblok-js-client";
const storyblok = new Storyblok({ accessToken: "ask9soUkv02QqbZgmZdeDAtt",});
try { const response = await storyblok.get('cdn/stories', { "sort_by": "first_published_at:desc", "starts_with": "authors" }) console.log({ response })} catch (error) { console.log(error)}$client = new \Storyblok\Client('YOUR_STORYBLOK_SPACE_ACCESS_TOKEN');
$client->getStories([ "sort_by" => "first_published_at =>desc", "starts_with" => "authors"])->getBody();HttpResponse<String> response = Unirest.get("https://api.storyblok.com/v2/cdn/stories?sort_by=first_published_at%3Adesc&token=ask9soUkv02QqbZgmZdeDAtt&starts_with=authors") .asString();var client = new RestClient("https://api.storyblok.com/v2/cdn/stories?sort_by=first_published_at%3Adesc&token=ask9soUkv02QqbZgmZdeDAtt&starts_with=authors");var request = new RestRequest(Method.GET);
IRestResponse response = client.Execute(request);import requests
url = "https://api.storyblok.com/v2/cdn/stories"
querystring = {"sort_by":"first_published_at:desc","token":"ask9soUkv02QqbZgmZdeDAtt","starts_with":"authors"}
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 => { "sort_by" => "first_published_at =>desc", "starts_with" => "authors"}})// .package(url: "https://github.com/storyblok/storyblok-swift.git", from: "1.1.0")// Requires a `Block` content model — see https://www.storyblok.com/docs/quickstarts/apple-platforms/content-modelinglet client = StoryblokClient( library: Block.self, accessToken: "ask9soUkv02QqbZgmZdeDAtt", version: .published, region: .eu)
let stories: Page<Story<Block>>? = try await client .stories { @Sendable (query: inout StoriesQuery<Block>) in query.sort(by: .firstPublishedAt, .descending) query.startsWith = "authors" } .last() .values .first { @Sendable _ in true }
print(stories!)// implementation("com.storyblok:content-api-client:0.7.1")val client = StoryblokClient( accessToken = "ask9soUkv02QqbZgmZdeDAtt", version = Published,)
val stories = client .stories { sortByDescending(Story<*>::firstPublishedAt) startsWith = "authors" } .flow .asItemSnapshotListFlow() .first()
println(stories){ "stories": [ { "name": "Jane Doe", "created_at": "2018-04-24T11:57:29.378Z", "published_at": "2026-10-13T09:03:07.816Z", "updated_at": "2026-10-13T09:03:07.829Z", "id": 107354, "uuid": "c47be9f0-47c3-4315-a95a-550f0c560eb5", "content": { "_uid": "b8b14760-b7a7-49f9-9e60-e3f8da23ad7b", "name": "Jane Doe", "avatar": "//a.storyblok.com/f/44162/1211x822/c73551377a/john-doe.png", "component": "author" }, "slug": "jane-doe", "full_slug": "authors/jane-doe", "sort_by_date": null, "position": -10, "tag_list": [], "is_startpage": false, "parent_id": 107352, "meta_data": null, "group_id": "e70ef646-5de2-42d6-acb3-0cda9f3388be", "first_published_at": "2018-08-23T08:18:08.196Z", "release_id": null, "lang": "default", "path": null, "alternates": [], "default_full_slug": null, "translated_slugs": null }, { "name": "John Doe", "created_at": "2018-04-24T11:57:29.365Z", "published_at": "2018-04-23T11:02:02.203Z", "updated_at": "2018-10-02T07:55:23.985Z", "id": 107353, "uuid": "22f4fb1b-50b3-4bf2-816e-7d589e307421", "content": { "_uid": "b8b14760-b7a7-49f9-9e60-e3f8da23ad7b", "name": "John Doe", "avatar": "//a.storyblok.com/f/44162/1211x822/c73551377a/john-doe.png", "component": "author" }, "slug": "john-doe", "full_slug": "authors/john-doe", "sort_by_date": null, "position": 0, "tag_list": [], "is_startpage": false, "parent_id": 107352, "meta_data": null, "group_id": "792ef2d2-2a7a-498c-87a9-8facc8fac3f5", "first_published_at": "2018-04-23T11:02:02.203Z", "release_id": null, "lang": "default", "path": null, "alternates": [], "default_full_slug": null, "translated_slugs": null } ], "cv": 1792059567, "rels": [], "links": []}Was this page helpful?
This site uses reCAPTCHA and Google's Privacy Policy (opens in a new window).Terms of Service (opens in a new window) apply.
Get in touch with the Storyblok community