Aug 07 2018 05:09 AM
I have issue with Adding List Item But I can Read List Item without any issue. I will narrate full step how I did. I want to use REST API outside SharePoint Online.
After that I run below code to get Custom List items
$.ajax({
url: "https://xxxx.sharepoint.com/_api/lists/getbytitle('Feedback')/items?$select=Title,URL",
method: 'GET',
headers: {
"Accept": "application/json; odata=verbose",
"Authorization": "Bearer " + accessToken,
}
})
This works without issue, but when I try to add list item I get error Access denied. You do not have permission to perform this action or access this resource
$.ajax({
url: "https://xxxx.sharepoint.com/_api/lists/getbytitle('Feedback')/items",
method: "POST",
contentType: "application/json;odata=verbose",
data: JSON.stringify(data),
headers: {
"Authorization": "Bearer " + accessToken,
"Accept": "application/json; odata=verbose",
"Content-Type": "application/json",
},
success: function (data) {
alert('Item added successfully');
},
error: function (error) {
alert("Error: " + JSON.stringify(error));
}
})
Please help to resolve the issue of access denied and let me know what I am missing
Aug 07 2018 07:09 AM
You may check if your account has written permission. Go to Site Settings-->People & Group.
Aug 07 2018 11:32 AM - edited Aug 07 2018 11:38 PM
I am System Administrator of Office 365, So I have Full Access to the SharePoint Online
Aug 08 2018 02:40 AM
Solution@Milind Saraswala if you are using the add-in model for authentication, you probably need to define the permissions that the app need when you register at https://xxxx.sharepoint.com/_layouts/15/appregnew.aspx
After you register the app, go to /_layouts/15/appinv.aspx and use the App Id from the registration to Lookup the details. When they load, add the required permissions on the Permission Request XML field.
For your case, I suspect it will look similar to:
<AppPermissionRequests>
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web/list" Right="Write"/> </AppPermissionRequests>
You can find additional information here:
https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/add-in-permissions-in-sharepoint
Hope this helps
Sep 15 2018 04:00 PM
Is this working now for you. We are looking for a similar API setup, so wanted to check if this worked for you.
Aug 08 2018 02:40 AM
Solution@Milind Saraswala if you are using the add-in model for authentication, you probably need to define the permissions that the app need when you register at https://xxxx.sharepoint.com/_layouts/15/appregnew.aspx
After you register the app, go to /_layouts/15/appinv.aspx and use the App Id from the registration to Lookup the details. When they load, add the required permissions on the Permission Request XML field.
For your case, I suspect it will look similar to:
<AppPermissionRequests>
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web/list" Right="Write"/> </AppPermissionRequests>
You can find additional information here:
https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/add-in-permissions-in-sharepoint
Hope this helps