SharPoint/Angular REST call returning 412 error

Hi all,

I am beating my head against the wall trying to get a delete to work via the SharePoint REST API, as I believe I have the proper headers defined in my REST call (including the If-Match), but it keeps throwing 412 errors. Here is my REST setup (using Angular):

 appServices.factory('appType', ['$resource', function ($resource) {
        return $resource("/_api/web/lists/getbytitle('Todo Types List')/Items(:Id)", { Id: "@Id" },
        {
            'query': { method: "GET", isArray: false, headers: { 'Accept': 'application/json;odata=nometadata' } },
            'update': { method: 'PATCH', headers: { 'Accept': 'application/json;odata=nometadata' } },
            'save': { method: 'POST', headers: { 'Accept': 'application/json;odata=nometadata', 'content-type': 'application/json;odata=nometadata', 'X-RequestDigest': $("#__REQUESTDIGEST").val() } },
            'delete': { method: 'DELETE', headers: { 'Accept': 'application/json;odata=nometadata', 'content-type': 'application/json;odata=nometadata', 'X-RequestDigest': $("#__REQUESTDIGEST").val() }, 'IF-MATCH': "*" },
        }
        );
    }]);

Here is my controller where the delete is called:

appControllers.controller('appSettingsCtrl', ['$scope', '$route', 'appType', 'appTypes', function ($scope, $route, appType, appTypes) {

    // Retrieve Types
    $scope.types = [];

     
    //function loadTypes() {
        appTypes.query({}, function (type) {
            $scope.types = type.value;
        })
    //};
    
    //Force load of results instead of requiring a page reload for results, also used on type entry
    //loadTypes();

    // Create Types
    var typeEntry = new appTypes;

    $scope.addType = function () {
        console.log("Clicked");
        typeEntry.Title = $scope.itemtype;
        typeEntry.$save(function () { // Ensure execuation of the save befor reloading the view
            $route.reload();
        });
    }

    // Delete types
    $scope.removeType = function (type) {
        
        appType.delete({ Id: type.Id });
    console.log("Deleted" + type.ID);
    }
}]);

March 17th, 2015 8:23pm

I have tried changing the header from 'Accept': 'application/json;odata=nometadata' to 'Accept': 'application/json;odata=verbose' but get the same error of 412.
Free Windows Admin Tool Kit Click here and download it now
March 17th, 2015 8:29pm

Hi,

According to your description, my understanding is that when you use Angularjs to delete item then it throws the 412 error.

for the IF-MATCH in the delete method, it needs to contain in the headers like below:

'delete': { method: 'DELETE', headers: { 'Accept': 'application/json;odata=verbose', 'content-type': 'application/json;odata=verbose', 'X-RequestDigest': $("#__REQUESTDIGEST").val(), 'IF-MATCH': '*' } }

Here  is a similiar thread for your reference:

SharePoint/Angular can't delete item - Error 412

Thanks

Best Regards

March 31st, 2015 1:28am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics