SharePointVault ~/gotchas/rest-api ⌕ Search 404 pages, error messages, scripts…Ctrl K ★ Star
M↓ README.mdM↓ folder-files-reject-a-two-level-expand.md
sharepoint-vault›gotchas›rest-api›folder-files-reject-a-two-level-expand.mdhistoryedit on GitHub
● GOTCHArest-api· 1 min read

A folder's Files collection rejects a two-level $expand

applies to: SharePoint Onlinereviewed: 2026-09-24#rest-api#files#folders#expand

$expand=ListItemAllFields/Editor — the obvious way to reach the editor through a file's list item — returns HTTP 400 on a folder's Files collection. Take the last editor and the author from the file itself — ModifiedBy and Author, one level deep.

$expand=ListItemAllFields/Editor – nejsnazší cesta k editorovi přes položku seznamu, která k souboru patří – vrátí na kolekci Files složky HTTP 400. Posledního editora a autora ber přímo ze souboru – ModifiedBy a Author, jedna úroveň.

Symptom

Listing a folder together with the name of whoever changed each file last:

GET /_api/web/GetFolderByServerRelativeUrl('/sites/projects/Shared Documents/Contracts')/Files
    ?$select=Name,TimeLastModified,ListItemAllFields/Editor/Title
    &$expand=ListItemAllFields/Editor

answers

HTTP 400 – The $expand query is not valid for field 'Editor'

Cause

On /items, the editor is one level away ($expand=Editor). Reached from a file through ListItemAllFields, it becomes a second level — and the Files collection rejects that.

Fix

The file carries its own user properties, one level deep:

GET …/Files?$select=Name,ServerRelativeUrl,TimeLastModified,ModifiedBy/Title&$expand=ModifiedBy

Author works the same way for the creator.

Notes

  • To list one level of a library, use the folder API — …/Folders and …/Files of that folder — rather than items?$filter=FileDirRef eq '…'. The filter runs over the whole list, so above the 5,000-item view threshold it gets throttled; the folder API asks about that one folder. Skip the system folders (Forms, names starting with _).
  • Moving what you listed? moveto answers with an empty body: Action endpoints return an empty body.
Was this helpful?ask or add your experience on GitHub →
Saved you an hour? A star on GitHub helps other SharePoint people find the vault.★ Star on GitHub
last reviewed: 2026-09-24last updated: 2026-09-24historyedit on GitHubview source