0

I'm trying to create a SharePoint-hosted Add-In for our SharePoint Online site. I'm using AngularJS as well to help with the front-end.

Using REST API, I have absolutely no trouble reading from a list. However, when I try to write onto that same list, I kept getting a 403.

Here is the code for my WritePage.js file:

app.controller('spListController', function ($scope, $http) {
console.log("In NewPage!");

this.startInsert = function () {
    var promise = this.insertItems($scope);
    promise.then(function (data, status, headers, config) {

    },
    function (data, status, headers, config) {
        alert("Error:\n" + status);
    });
};

this.insertItems = function ($scope) {
    var url = window.location.protocol + "//" + window.location.host + _spPageContextInfo.webServerRelativeUrl + "/_api/web/lists/getByTitle('My List')/items";
    var requestBody = JSON.stringify({
        '__metadata': { 'type': 'SP.Data.MyListListItem' },
        'Title': this.Title,
    });
    return $http({
        method: 'POST',
        url: url,
        body: requestBody,
        headers: {
            //"Authorization": "Bearer " + accessToken // <-- I keep seeing these in online examples. Is this what I need?
            //"X-RequestDigest": $("#__REQUESTDIGEST").val(), // <-- Keeping this turns the 403 into a 500.
            "accept": "application/json; odata=verbose",
            "content-type": "application/json; odata=verbose"
        }
    });
};
});
0

1) Ensure that the user has write access to the SharePoint list by checking permission.

2) If above is true, then ensure that SP hosted add-in has permission to write data to list. Check the appmanifest.xml .

enter image description here

  • I'm still getting a 403 even with all those three in FullControl. I tried checking the Allow the app to... option and it makes no difference. (Yes, I've selected the list I want to give Write permissions to.) – Christian Wico Dec 28 '16 at 3:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.