SharePointVault ~/gotchas/rest-api ⌕ Search 404 pages, error messages, scripts…Ctrl K ★ Star
M↓ README.mdM↓ search-api-needs-odata-version-3.md
sharepoint-vault›gotchas›rest-api›search-api-needs-odata-version-3.mdhistoryedit on GitHub
● GOTCHArest-api· 1 min read

Search REST API needs odata-version: 3.0

applies to: SharePoint Onlinereviewed: 2026-07-15#rest-api#search#spfx

The SharePoint search endpoint still speaks OData 3.0, so a modern client that defaults to odata-version: 4.0 gets a hard 500 — add odata-version: 3.0 to every /_api/search/* call and it works.

Vyhledávací endpoint SharePointu stále mluví OData 3.0, takže moderní klient s výchozí hlavičkou odata-version: 4.0 dostane tvrdou 500 – přidej odata-version: 3.0 do každého volání /_api/search/* a je to.

Symptom

Calls to /_api/search/query fail with an unhelpful 500 Internal Server Error — typically from SPFx (SPHttpClient) or another modern HTTP client, while the very same query works when pasted into the browser's address bar.

Cause

The search endpoint still speaks OData 3.0. Modern clients — SPFx SPHttpClient in particular — send odata-version: 4.0 by default, and the search service fails hard on it instead of degrading gracefully.

Fix

Send the header explicitly on every /_api/search/* call:

const res = await this.context.spHttpClient.get(
  `${webUrl}/_api/search/query?querytext='${encodeURIComponent(query)}'`,
  SPHttpClient.configurations.v1,
  {
    headers: {
      'odata-version': '3.0',
      'Accept': 'application/json;odata=nometadata'
    }
  }
);

Plain fetch or any other client: same idea — add odata-version: 3.0.

Notes

  • POST /_api/search/postquery needs the same header.
  • Diagnostic shortcut: if search calls 500 while the rest of /_api works fine, check this header first — it is almost always the answer.
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-07-15last updated: 2026-09-24historyedit on GitHubview source