I'm creating a Sharepoint App and i am restricted to using Javascript (jQuery included) and REST endpoints. I would like to delete an item from the host using the web app, but i'm getting an error (403: FORBIDDEN
). This is the code i have so far:
executor = new SP.RequestExecutor(appweburl);
executor.executeAsync({
url: appweburl + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('" + currentListTitle + "')/items(" + result.Id + ")/?@target='" + hostweburl + "'",
method: "POST",
headers: {
"accept": "application/json",
"X-RequestDigest": ?????
"IF-MATCH": "*",
"X-HTTP-Method": "DELETE"
},
success: onDeleteItemSuccess,
error: onDeleteItemFail
});
Now I found out this X-RequestDigest
is mandatory and i found some call to get this from REST:
$.ajax({
url: appweburl + "/_api/SP.AppContextSite(@target)/contextinfo/?@target='" + hostweburl + "'",
type: "POST",
contentType: "application/x-www-url-encoded",
dataType: "json",
success: function (data) {
if (data.d)
{
digestValue = data.d.GetContextWebInformation.FormDigestValue;
alert(digestValue);
}
},
error: function (xhr) {
alert(xhr.status + ': ' + xhr.statusText);
}
});
But it isn't working at all (this might be because this code was for Sharepoint 2010) and it will keep giving me a 403: FORBIDDEN
message.
Does anyone know how to delete a list item from one of the lists using REST (I can't use/edit any code outside of the javascript!)?
Any help is appriciated and if you need any information please don't hesitate to ask.
The code can't be for SharePoint 2010, as _api is new to SP 2013.
[Update] Maybe you mean that your code was working in SP 2013 preview? In SP2013 RTM you need to use:
"Accept": "application/json; odata=verbose"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With