Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

REST update item returns 403 forbidden

$
0
0

Hi

I have been struggling to update a list item through the REST api and JS. I'm working on Sharepoint 2013 on-premise install.

Code:

var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('SiteDB')/items(50)";
var itemType = GetItemTypeForListName('SiteDB');
$.ajax({
    url: requestUri,
    type: "POST",
    data: JSON.stringify({
        '__metadata': {
            'type': itemType
        },
        'Tags': 'My Item-New Title'
    }),
    headers: {"accept": "application/json;odata=verbose","content-type": "application/json;odata=verbose","X-RequestDigest": $("#_REQUESTDIGEST").val(),"X-HTTP-Method": "MERGE","IF-MATCH": "*"
    },
    success: onSuccess,
    error: onError
});

function onSuccess(data) {
    alert(data + ' List Item Updated');
}

function onError(error) {
    alert(JSON.stringify(error));
}

function GetItemTypeForListName(name) {
    return "SP.Data." + name.charAt(0).toUpperCase() + name.split(" ").join("").slice(1) + "ListItem";
}

I receive 403 forbidden error message - any suggestions? 

Viewing all articles
Browse latest Browse all 7589

Trending Articles