Reputation: 1
I am trying to create a new list item in a SharePoint list on SPO.
I am getting forbidden 403 error.
var listURL = webURL + "/_api/web/lists/GetByTitle('Departments')/items";
$.ajax({
url: listURL,
type: "POST",
headers: {
"accept": "application/json;odata=verbose",
"content-Type": "application/json;odata=verbose"
},
data: JSON.stringify({
'__metadata': { 'type': 'SP.Data.' + pListName + 'ListItem' },
'Title': 'Test1'}),
success: function(data) {
console.log(data.d.results);
alert("Item added")
},
error: function(error) {
alert(JSON.stringify(error));
}
});
Upvotes: 0
Views: 641
Reputation: 12245
SharePoint does not allow anonymous requests (your request appears to be anonymous). You need to be authenticated (logged in).
Upvotes: 0