I followed this tutorial Create a Sharepoint List using Rest Api but I had a
message error : "Failed to load resource: the server responded with a status of 403 (Forbidden)"
when I have clicked on the bottom "Create your custom list"
I followed this tutorial Create a Sharepoint List using Rest Api but I had a
message error : "Failed to load resource: the server responded with a status of 403 (Forbidden)"
when I have clicked on the bottom "Create your custom list"
Make sure to check(highlighted below) the Allow the add-in to make app-only calls to SharePoint before you deploy the add-in to SharePoint
Forbidden when the addin tries to access the list.
Forbidden error generally occurs because of these two reason-
To solve 1 - use $('#__REQUESTDIGEST').val() to get the form digest value.
This code may be helpful for you:
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists",
type: "POST",
data: JSON.stringify({
'__metadata': { 'type': 'SP.List' }, 'AllowContentTypes': true, 'BaseTemplate': 100,
'ContentTypesEnabled': true, 'Description': 'My list description', 'Title': 'Employees'
}),
headers: {
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: onSuccess,
error: onError
});
function onSuccess(data) {
alert(data + ' List Created');
}
function onError(error) {
alert(JSON.stringify(error));
}
To solve case 2 - you have to give the requisite permission. For more Click Here