---
title: Sorting by Story Object Property
description: Learn how to sort stories by default story properties like name, position, and publication dates using the Content Delivery API.
url: https://storyblok.com/docs/api/content-delivery/v2/stories/examples/sorting-by-story-object-property
---

# 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 property `name`
-   `sort_by=position:desc`: Sort stories in the order determined in the **Content** tab
-   `sort_by=first_published_at:desc`: Sort by the story object property `first_published_at`

## Example request and response

The following example demonstrates how to sort stories in descending order by their first published date.

-   cURL
    
    ```shellscript
    curl "https://api.storyblok.com/v2/cdn/stories\
    ?token=krcV6QGxWORpYLUWt12xKQtt\
    &sort_by=first_published_at%3Adesc"
    ```
    
-   JS
    
    ```javascript
    // storyblok-js-client@>=7, node@>=18
    import Storyblok from "storyblok-js-client";
    
    const storyblok = new Storyblok({
      accessToken: "krcV6QGxWORpYLUWt12xKQtt",
    });
    
    try {
      const response = await storyblok.get('cdn/stories', {
        "sort_by": "first_published_at:desc"
      })
      console.log({ response })
    } catch (error) {
      console.log(error)
    }
    ```
    
-   PHP
    
    ```php
    $client = new \Storyblok\Client('YOUR_STORYBLOK_SPACE_ACCESS_TOKEN');
    
    $client->getStories([
      "sort_by" => "first_published_at =>desc"
    ])->getBody();
    ```
    
-   Java
    
    ```java
    HttpResponse<String> response = Unirest.get("https://api.storyblok.com/v2/cdn/stories?token=krcV6QGxWORpYLUWt12xKQtt&sort_by=first_published_at%3Adesc")
      .asString();
    ```
    
-   C#
    
    ```csharp
    var client = new RestClient("https://api.storyblok.com/v2/cdn/stories?token=krcV6QGxWORpYLUWt12xKQtt&sort_by=first_published_at%3Adesc");
    var request = new RestRequest(Method.GET);
    
    IRestResponse response = client.Execute(request);
    ```
    
-   Python
    
    ```python
    import requests
    
    url = "https://api.storyblok.com/v2/cdn/stories"
    
    querystring = {"token":"krcV6QGxWORpYLUWt12xKQtt","sort_by":"first_published_at:desc"}
    
    payload = ""
    headers = {}
    
    response = requests.request("GET", url, data=payload, headers=headers, params=querystring)
    
    print(response.text)
    ```
    
-   Ruby
    
    ```ruby
    require 'storyblok'
    client = Storyblok::Client.new(token: 'YOUR_TOKEN')
    
    client.stories({:params => {
      "sort_by" => "first_published_at =>desc"
    }})
    ```
    
-   Swift
    
    ```swift
    let storyblok = URLSession(storyblok: .cdn(accessToken: "krcV6QGxWORpYLUWt12xKQtt"))
    var request = URLRequest(storyblok: storyblok, path: "stories")
    request.url!.append(queryItems: [
        URLQueryItem(name: "sort_by", value: "first_published_at:desc")
    ])
    let (data, _) = try await storyblok.data(for: request)
    print(try JSONSerialization.jsonObject(with: data))
    ```
    
-   Kotlin
    
    ```kotlin
    val client = HttpClient {
        install(Storyblok(CDN)) {
            accessToken = "krcV6QGxWORpYLUWt12xKQtt"
        }
    }
    
    val response = client.get("stories") {
        url {
            parameters.append("sort_by", "first_published_at:desc")
        }
    }
    
    println(response.body<JsonElement>())
    ```

Response

```json
{
  "stories": [
    {
      "name": "Jimmy Moons",
      "created_at": "2024-02-16T14:35:02.379Z",
      "published_at": "2024-02-16T14:35:04.658Z",
      "id": 445021953,
      "uuid": "51eed33d-855f-415c-ac0d-4404e03b89e1",
      "content": {
        "bio": "Jimmy is a front-end engineer who loves crafting beautiful and fast websites. His favorite technologies include Nuxt, Astro, Tailwind, and Storyblok. As a kid, Jimmy wanted to be the first man on Mars, but he discovered his love for developing. Thus, starting his journey toward his true passion.",
        "_uid": "98811439-d739-4886-a99f-fd2c9ebcf293",
        "component": "author"
      },
      "slug": "jimmy-moons",
      "full_slug": "authors/jimmy-moons",
      "sort_by_date": null,
      "position": -10,
      "tag_list": [],
      "is_startpage": false,
      "parent_id": 445020177,
      "meta_data": null,
      "group_id": "367ab023-f911-4810-b3d3-3fb0d6847ce1",
      "first_published_at": "2024-02-16T14:35:04.658Z",
      "release_id": null,
      "lang": "default",
      "path": null,
      "alternates": [],
      "default_full_slug": null,
      "translated_slugs": null
    },
    {
      "name": "Sarah Saturn",
      "created_at": "2024-02-16T14:34:46.888Z",
      "published_at": "2024-02-16T14:34:49.802Z",
      "id": 445020772,
      "uuid": "e7307a9e-a3c5-47ad-8f6c-a1a36fe528e2",
      "content": {
  "bio": "We like to say Sarah is, "One with marketing." She is a guru when it comes to copy-editing, page ideation, and design. Best of all, she always executes flawlessly. In her free time, she likes to read about space, update Wiki space articles and work on her mini diorama of the Apollo Lunar Module.",
        "_uid": "e83f15e0-27e3-436c-97b9-1ea163804c8d",
        "component": "author"
      },
      "slug": "sarah-saturn",
      "full_slug": "authors/sarah-saturn",
      "sort_by_date": null,
      "position": 0,
      "tag_list": [],
      "is_startpage": false,
      "parent_id": 445020177,
      "meta_data": null,
      "group_id": "caa63bbb-87cc-4f53-bde8-5efb74ef8b97",
      "first_published_at": "2024-02-16T14:34:49.802Z",
      "release_id": null,
      "lang": "default",
      "path": null,
      "alternates": [],
      "default_full_slug": null,
      "translated_slugs": null
    }
  ],
  "cv": 1711108220,
  "rels": [],
  "links": []
}
```

## Pagination

-   [Previous: Sorting by Fields Associated with a Story Type](/docs/api/content-delivery/v2/stories/examples/sorting-by-fields-associated-with-a-story-type)
-   [Next: Retrieve a Single Link](/docs/api/content-delivery/v2/links/retrieve-single-link)
