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);
}
}]);Personal Blog: http://thebitsthatbyte.com