How to Build an OData Query for SharePoint Online
The SharePoint Online REST API uses OData query parameters to filter, sort, and shape the data it returns. The syntax is powerful but easy to get wrong, especially with lookup fields and date filters.
The core parameters
$select— choose which fields to return, e.g.$select=Title,Author/Title$filter— filter rows, e.g.$filter=Status eq 'Active'$expand— pull in related fields from lookups/people fields, e.g.$expand=Author$orderby— sort results, e.g.$orderby=Created desc$top— limit the number of results returned
A working example
To get the title and author of active items, newest first:
https://yourtenant.sharepoint.com/sites/yoursite/_api/web/lists/getbytitle('YourList')/items?$select=Title,Author/Title&$expand=Author&$filter=Status eq 'Active'&$orderby=Created desc&$top=50
Common mistakes
-
Filtering on lookup fields directly —
$filter=Author eq 'Jane'won't work; you need$filter=Author/Title eq 'Jane'combined with$expand=Author. -
Date comparisons — dates need to be in ISO 8601 format, e.g.
$filter=Created ge datetime'2026-01-01T00:00:00Z'. -
Forgetting
$expandwhen using$selecton a lookup field —$selectalone won't pull related data through; you need both together. - Special characters in field internal names — if a field name contains a space, you'll hit the internal name issue before you can filter on it correctly.
Testing queries safely
Always test with $top=1 first before running a broader query, especially against
large lists — a malformed $filter against a list with list view threshold issues can
time out or return unhelpful errors that don't point at the actual syntax problem.
Building queries visually
Getting the syntax right — especially combining $expand and $select on
lookup fields — is the most common source of trial and error.
SPO-Assist's OData query builder lets you construct the
query visually against the list you're actually viewing, so you can see field internal names and
build valid $filter/$select/$expand combinations without
memorizing the syntax.