Notion API - Public Beta (English)
  1. Databases
Notion API - Public Beta (English)
  • Introduction
  • Integration capabilities
  • Request limits
  • Status codes
  • ENDPOINTS
    • Authentication
      • Authentication
      • Token
    • Blocks
      • Delete a block
      • Append block children
      • Retrieve a block
      • Update a block
      • Retrieve block children
    • Databases
      • Filter database entries
      • Sort database entries
      • Update database properties
      • Retrieve a database
        GET
      • Update a database
        PATCH
      • Query a database
        POST
    • Pages
      • Archive a page
      • Retrieve a page property item
      • Create a page
      • Retrieve a Page
      • Update Page properties
    • Users
      • List all users
      • Retrieve your token's bot user
      • Retrieve a user
    • Comments
      • Create comment
      • Retrieve comments
    • Search
      • Search optimizations and limitations
      • Search by title
  • OBJECTS
    • Block
    • Comment
    • Unfurl attribute object for Link Previews
    • Page
      • Page
      • Page properties
    • Database
      • Database
      • Database properties
    • User
      • User
      • Comment
    • Other
      • Emoji object
      • File object
      • Parent object
      • Rich text object
  • Versioning
    • Versioning
    • Changes by version
  • ENDPOINTS Copy
    • Authentication
      • Authentication
      • Token
    • Blocks
      • Retrieve a block
      • Update a block
      • Retrieve block children
      • Delete a block
      • Append block children
    • Databases
      • Filter database entries
      • Sort database entries
      • Update database properties
      • Retrieve a database
      • Update a database
      • Query a database
      • Create a database
    • Pages
      • Archive a page
      • Retrieve a Page
      • Update Page properties
      • Retrieve a page property item
      • Create a page
    • Users
      • Retrieve a user
      • List all users
      • Retrieve your token's bot user
    • Comments
      • Create comment
      • Retrieve comments
  1. Databases

Sort database entries

A sort is a condition used to order the entries returned from a database query.
A database query can be sorted by a property and/or timestamp and in a given direction. For example, a library database can be sorted by the "Name of a book" (i.e. property) and in ascending (i.e. direction).
Here is an example of a sort on a database property.
Sorting by "Name" property in ascending direction
{
    "sorts": [
        {
            "property": "Name",
            "direction": "ascending"
        }
    ]
}
Database queries can also be sorted by two or more properties, which is formally called a nested sort. The sort object listed first in the nested sort list takes precedence.
Here is an example of a nested sort.
JSON
{
    "sorts": [
                {
            "property": "Food group",
            "direction": "descending"
        },
        {
            "property": "Name",
            "direction": "ascending"
        }
    ]
}
In this example, the database query will first be sorted by "Food group" and the set with the same food group is then sorted by "Name".

Sort object#

Property value sort#

This sort orders the database query by a particular property.
The sort object must contain the following properties:
PropertyTypeDescriptionExample value
propertystringThe name of the property to sort against."Ingredients"
directionstring (enum)The direction to sort. Possible values include "ascending" and "descending"."descending"

Entry timestamp sort#

This sort orders the database query by the timestamp associated with a database entry.
The sort object must contain the following properties:
PropertyTypeDescriptionExample value
timestampstring (enum)The name of the timestamp to sort against. Possible values include "created_time" and "last_edited_time"."last_edited_time"
directionstring (enum)The direction to sort. Possible values include "ascending" and "descending"."descending"
Modified at 2023-04-28 08:26:40
Previous
Filter database entries
Next
Update database properties
Built with