Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
12
rated 0 times [  16] [ 4]  / answers: 1 / hits: 42237  / 9 Years ago, mon, september 7, 2015, 12:00:00

I'm trying to create a simple list item with the rest api on Sharepoint 2013.
My code:



$.ajax({
url: siteUrl + /_api/web/lists/getByTitle('internal_Listname')/items,
type: POST,
contentType: application/json;odata=verbose,
data: JSON.stringify({
'__metadata': {
'type': 'SP.Data.internal_ListnameListItem',
},
'K1F1': k1f1Result,
}),
headers: {
accept: application/json;odata=verbose,
X-RequestDigest: $(#__REQUESTDIGEST).val(),
},
success: function (data) {
console.log(done);
},
error: function (err) {
console.log(JSON.stringify(err));
}
});


When trying to send the data I get the 403 Forbidden error.



error:{
code:-2130575251, Microsoft.SharePoint.SPException,
message:{
lang:en-US,
value:The security validation for this page is invalid and might be corrupted. Please use your web browser's Back button to try your operation again.
}
}



  • I have full admin privileges on this site and the list.


More From » ajax

 Answers
54

Found the solution a few days ago:
I forgot to add the request digest form to the body. It should have the following structure;



<form runat=server>
<SharePoint:FormDigest ID=FormDigest1 runat=server></SharePoint:FormDigest>
</form>

[#65161] Friday, September 4, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
payne

Total Points: 527
Total Questions: 108
Total Answers: 88

Location: Tajikistan
Member since Thu, Apr 14, 2022
2 Years ago
;