Fixing: The HTTP header ACCEPT is missing or its value is invalid - SharePoint 2013

Tobias Zimmergren
Tobias Zimmergren
💡🤖TIP: Check out the guidance for AI adoption on Azure!

So just a simple tip in case anyone bumps into the same issue as I had a while back. Going from Beta to RTM, some things changed in the way you retrieve values using REST in the SharePoint 2013 client object model.

In the older versions of the object model, you could simply use something like this in your REST call:

$.ajax( { url: SPSearchResults.url, method: "GET", headers: { "accept": "application/json", }, success: SPSearchResults.onSuccess, error: SPSearchResults.onError } );

As you can see the headers is specifying application/json.

The fix is simply to swap that statement into this:

$.ajax( { url: SPSearchResults.url, method: "GET", headers: { "accept": "application/json;odata=verbose", }, success: SPSearchResults.onSuccess, error: SPSearchResults.onError } );

And that’s a wrap.

Summary

I hope this can save someone a few minutes (or more) of debugging for using old example code or ripping up older projects. I’ve found that a lot of examples online, based on the beta of SharePoint 2013, are using the older version of the headers-statement which inevitably will lead to this problem. So with that said, enjoy.

SharePointDevelopment

Tobias Zimmergren Twitter

Hi, I'm Tobias! 👋 I write about Microsoft Azure, security, cybersecurity, compliance, cloud architecture, Microsoft 365, and general tech!

Reactions and mentions


Hi, I'm Tobias 👋

Tobias Zimmergren profile picture

Find out more about me.

Recent comments

Mastodon