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

Incorrect value for the content-type for Update list item #6636

Open
mahajangaurav opened this issue Jan 26, 2021 · 7 comments · May be fixed by #6661
Open

Incorrect value for the content-type for Update list item #6636

mahajangaurav opened this issue Jan 26, 2021 · 7 comments · May be fixed by #6661
Labels
area:docs Category: SharePoint developer/development documentation related area:docs-comment Category: Comment left on bottom of a docs page here: https://docs.microsoft.com/sharepoint/dev Good First Issue 🏆 Great suggestion for someone from the community to jump in as their first issue to address / fix! help wanted Looking for someone to help with this issue (documentation fix, etc). type:bug-suspected Suspected bug (not working as designed/expected). See “type:bug-confirmed” for confirmed bugs.

Comments

@mahajangaurav
Copy link

The value of the Content-Type header in the Update list item example is incorrect.
It should be: "application/json;odata=verbose"
instead of "application/json"

Sending just application/json results in an error as mentioned in this stack exchange: https://sharepoint.stackexchange.com/questions/239169/the-property-metadata-does-not-exist-on-type-sp-data


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

@ghost
Copy link

ghost commented Jan 26, 2021

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

@ghost ghost added Needs: Triage 🔍 Awaiting categorization and initial review. area:docs-comment Category: Comment left on bottom of a docs page here: https://docs.microsoft.com/sharepoint/dev labels Jan 26, 2021
@Jerry0527
Copy link

Jerry0527 commented Jan 27, 2021

Yes, should use contentType: "application/json;odata=verbose", otherwise will return 400 error:

            var listName = "Employee";
            var listItemId = 8;
            var item = {
                "__metadata": { "type": 'SP.Data.'+ listName +'ListItem' },
                "Title": "value change"
            };

            $.ajax({
                url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists/getbytitle('" + listName + "')/items(" + listItemId + ")",
                type: "POST",
                contentType: "application/json;odata=verbose",
                data: JSON.stringify(item),
                headers: {
                    "Accept": "application/json;odata=verbose",
                    "X-RequestDigest": $("#__REQUESTDIGEST").val(),
                    "X-HTTP-Method": "MERGE",
                    "If-Match": "*"
                },
                success: function (data) {
                    alert('Success');
                    
                },
                error: function (data) {
                    alert("Error");

                }
            });


@mahajangaurav
Copy link
Author

Hi Jerry!
Yes, I am aware of the fix now but the issue was more directed towards fixing the documentation here: Update list item

Thanks!

@Jerry0527
Copy link

May need moderator to push update in the documentation.

@andrewconnell andrewconnell added area:docs Category: SharePoint developer/development documentation related Good First Issue 🏆 Great suggestion for someone from the community to jump in as their first issue to address / fix! help wanted Looking for someone to help with this issue (documentation fix, etc). type:bug-suspected Suspected bug (not working as designed/expected). See “type:bug-confirmed” for confirmed bugs. and removed Needs: Triage 🔍 Awaiting categorization and initial review. labels Jan 27, 2021
@andrewconnell
Copy link
Collaborator

Sharing is caring :) we welcome community contributions to the docs ;) Care you submit a PR fixing the issue?

@mahajangaurav
Copy link
Author

would love to! Thanks @andrewconnell

mahajangaurav added a commit to mahajangaurav/sp-dev-docs that referenced this issue Jan 30, 2021
… item - updated the doumentation with the correct value
@mahajangaurav mahajangaurav linked a pull request Jan 30, 2021 that will close this issue
1 task
@mahajangaurav
Copy link
Author

@andrewconnell PR is submitted and is awaiting a merge :) Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:docs Category: SharePoint developer/development documentation related area:docs-comment Category: Comment left on bottom of a docs page here: https://docs.microsoft.com/sharepoint/dev Good First Issue 🏆 Great suggestion for someone from the community to jump in as their first issue to address / fix! help wanted Looking for someone to help with this issue (documentation fix, etc). type:bug-suspected Suspected bug (not working as designed/expected). See “type:bug-confirmed” for confirmed bugs.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants