Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppressing SharePoint REST metadata using odata=nometadata fails #644

Closed
1 of 4 tasks
waldekmastykarz opened this issue Jun 14, 2017 · 5 comments
Closed
1 of 4 tasks
Assignees
Labels
status:by-design Topic described is by design & not considered an issue. type:bug-suspected Suspected bug (not working as designed/expected). See “type:bug-confirmed” for confirmed bugs.

Comments

@waldekmastykarz
Copy link
Collaborator

Category

  • Question
  • Typo
  • Bug
  • Additional article idea

Expected or Desired Behavior

Originally, whenever you wanted to suppress the metadata in the JSON response of SharePoint REST APIs, you would include the Accept: application/json;odata=nometadata request header.

Observed Behavior

If you add the Accept: application/json;odata=nometadata request header to a request to the SharePoint REST API, the request will fail with a 406 Not Acceptable response. Instead you have to use the Accept: application/json;odata.metadata=none header. This has to do with the SPHttpClient using the odata-version: 4.0 request header. Without this header, or with the odata version being set to 2.0 you can use odata=nometadata to suppress metadata. In the previous versions of the SharePoint Framework you could use odata=nometadata but in the latest version it fails. It could be that this is caused not by a change in the SharePoint Framework but in how SharePoint REST API handles the data-version: 4.0 request header.

Steps to Reproduce

import { SPHttpClient, SPHttpClientResponse } from '@microsoft/sp-http';

export default class HelloWorldWebPart extends BaseClientSideWebPart<IHelloWorldWebPartProps> {
  public render(): void {
    this.domElement.innerHTML = `
      <div class="${styles.helloWorld}">...</div>`;

    this.context.spHttpClient.get(`${this.context.pageContext.web.serverRelativeUrl}/_api/web?$select=Title`, SPHttpClient.configurations.v1, {
      headers: {
        'Accept': 'application/json;odata=nometadata'
      }
    })
    .then((response: SPHttpClientResponse) => {
      return response.json();
    })
    .then((data) => {
      alert(data.Title);
    });
  }
  // ...
}
@octogonz
Copy link

@chackman FYI

@octogonz
Copy link

It could be that this is caused not by a change in the SharePoint Framework but in how SharePoint REST API handles the data-version: 4.0 request header.

Hey @waldekmastykarz, I don't know of any changes made to SPHttpClient since the 1.0 release. It seems likely that this was a server change. Do you happen to have an example of code that used to work before?

@octogonz
Copy link

From what we can tell, the server code has not changed either.

Looking at the standards docs, ODATA V4 uses a different notation odata.metadata=none. The odata= notation is from ODATA V3. The JSON Light odata=nometadata setting itself is not mentioned in that doc (maybe it is specific to Microsoft's implementation?).

The server certainly supported it prior to ODATA_V4:

#if ODATA_V4
                    if (contentType.IndexOf("none", StringComparison.OrdinalIgnoreCase) >= 0)
#else
                    if (contentType.IndexOf("nometadata", StringComparison.OrdinalIgnoreCase) >= 0)
#endif
                    {
                        return ODataMetadataLevel.NoMetadata;
                    }

@waldekmastykarz based on this, I am resolving this bug as "by design". Please reopen it if you can find a counterexample. Thanks!

@octogonz octogonz added status:by-design Topic described is by design & not considered an issue. type:bug-suspected Suspected bug (not working as designed/expected). See “type:bug-confirmed” for confirmed bugs. labels Jun 27, 2017
@octogonz octogonz self-assigned this Jun 27, 2017
@waldekmastykarz
Copy link
Collaborator Author

@pgonzal as far as I can tell it was exactly the same code. Not sure at which point it changed (ie. v1.0.0, v1.0.2 or v1.1.x) but in the latest release I noticed that what used to work in the past, isn't working anymore. Totally understood if this is by design, but in that case the documentation should reflect it.

@msft-github-bot
Copy link
Collaborator

Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues

@SharePoint SharePoint locked as resolved and limited conversation to collaborators Jan 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status:by-design Topic described is by design & not considered an issue. type:bug-suspected Suspected bug (not working as designed/expected). See “type:bug-confirmed” for confirmed bugs.
Projects
None yet
Development

No branches or pull requests

3 participants