SP 2013: The HTTP header ACCEPT is missing or its value is invalid – solution

Author: Tobias Zimmergren
http://www.zimmergren.net | http://www.tozit.com | @zimmergren

Introduction

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.

Description & Solution

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.

You may also like...

  • http://robmd.net/ Rob McGuire-Dale

    This was my problem! I saw that ‘odata’ entry in some other documentation, and foolishly ignored it, thinking I knew better. Lesson learned ;-) Thanks!

    • http://www.zimmergren.net/ Tobias Zimmergren

      Wohoo! Glad it worked out Rob! :-)
      Tobias.

  • XavierH

    Thank you sir. Kind of after the fact for me. But nonetheless, this was a big help. Short story…I was using the SharePoint 365 environment for my development. Abandoned the REST api because I could not get it to working. Thought it had something to do with the online environment. Once we moved it in-house and I still had this problem that’s when I knew it had to be something different. I am disappointed Microsoft didn’t communicate this.

    Thanks again, for sharing the knowledge!

    • XavierH

      After searching for this exact term…I found some Microsoft articles that do mention how to do this. Using “verbose”. However, their video demos show the old way. I guess I should of dug deeper. Was on a tight schedule and just used the CSOM.

      • http://www.zimmergren.net/ Tobias Zimmergren

        Hi Xavier,

        The issue about demo videos showing the old way is unfortunately a result of the demos being recorded during the beta period, something we’ll have to take into account when working with beta products :-)

        I’m glad you worked it out in the end.

        Cheers,

        Tobias.

  • Paul Bouchon

    This saved me a lot of headache. Thanks for posting this.

    • http://www.zimmergren.net/ Tobias Zimmergren

      You’re most welcome Paul.
      Cheers,
      Tobias.

  • Pingback: SharePoint Daily » Blog Archive » Preparing for SharePoint 2013; Cloud Collaboration, Social & Docs; Make the Switch to Office 365

  • Pingback: Preparing for SharePoint 2013; Cloud Collaboration, Social & Docs; Make the Switch to Office 365 - SharePoint Daily - Bamboo Nation

  • Neha

    Lifesaver! Thanks for posting this!

    • http://www.zimmergren.net/ Tobias Zimmergren

      Rock and roll Neha!

  • Parry

    Thanks Tabis, for brilliant post!
    Saved me a lot of time, owe you a beer ;)
    Cheers,

    • http://www.zimmergren.net/ Tobias Zimmergren

      Hi Parry,
      No worries – glad you found it useful.
      Cheers,
      Tobias.

  • JP

    Excellent! Couldn’t figure out why copying exact video sample was causing an error. Thanks for sharing this!

    • http://www.zimmergren.net/ Tobias Zimmergren

      Awesome, glad it works mate.
      Cheers,
      Tob.

  • WMY

    Thanks! After 4 hours of debugging, I found this solution which saved me :) Had to fix it in my jquery1.7.1.js file.

  • Pingback: SP 2013: The HTTP header ACCEPT is missing or its value is invalid | Williams notatblog