matthewyarlett / AngularJS-Directive-for-SharePoint-People-Picker

An AngularJS directive that wraps up the Microsoft Client-side people picker
http://matthewyarlett.blogspot.com/2015/04/using-microsoft-client-side-people.html
9 stars 12 forks source link

Can't POST to SharePoint list #5

Open jonny9 opened 7 years ago

jonny9 commented 7 years ago

Hi Everything seems to work just fine. I pass any of the values (Name, Title or Id) and they all appear to be correct. However, whether together or separately (e.g. "Id") I always get a 400 failure error.

Request Body {"__metadata":{"type":"SP.Data.myListItem"},"Item1":"145","Item2":"2017-04-27T07:00:00.000Z","Item3":"sample value","Item4":"sample value","AssignedTo":35}

Angular JS Service this.addBackFixItem = function (listTitle, newItem,varUserID) { var dfd = $q.defer(); $http.defaults.headers.post['X-HTTP-Method'] = "POST"; var restUrl = spAppWebUrl + "_api/web/lists/getbytitle('" + listTitle + "')/items"; var data = { __metadata: { type: 'SP.Data.myListItem' }, PID: varPID, //Title: newItem.Tile, Item1: newItem.Item1, Item2: newItem.Item2, Item3: newItem.Item3, Item4: newItem.Item4, Item5: newItem.Item5, Item6: newItem.Item6, Item7: newItem.Item7, AssignedTo: varUserID }; $http.post(restUrl, data) .success(function (data) { dfd.resolve(data.d); //alert('Your comment data was successfully entered. This page will refresh for your next entry.'); }).error(function (data) { dfd.reject("failed to add item"); alert('An error has occurred. Please try again or contact the web administrator.'); }); return dfd.promise; }

jonny9 commented 7 years ago

Note: I did test with added quotation marks (string) around the AssignedTo value and still no joy.

knaveenstar commented 5 years ago

you have to mention the property name as 'AssingnToId'