I'm just trying to submit a simple item to a sharepoint online list. Here's the code I have to do this.
- app.factory("organizationsSrvc", ['$rootScope', '$http',
- function($rootScope, $http) {
- var listName = "Organizations";
-
- var organizationsService = {};
-
-
- var organizations = null;
-
- organizationsService.add = function(organization) {
- var data = JSON.stringify(organization);
- data = data.replace(/[{}]/g, '');
- var datavalue = "{__metadata:{'type':'SP.Data.'" + listName + "'.ListItem'}," + data + "}";
- console.log(datavalue);
- $http({
- url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('" + listName + "')/items",
- method: 'POST',
- headers: {
- "Accept": "application/json;odata=verbose",
- "Content-Type": "application/json;odata=verbose",
- "X-RequestDigest": $("#__REQUESTDIGEST").val(),
- "X-HTTP-Method": "POST"
- },
- data: datavalue
- }).then(function success(response) {
- console.log("[add Organization] POST worked");
- console.log("[add Organization] New Id = " + response.Id);
- debugger;
- }, function error(response) {
- console.log("[add Organization] Error = " + response);
- debugger;
- })
- console.log($http);
- debugger;
- };
-
- return organizationsService;
- }]);
When running this I get the following output in console.
{__metadata:{'type':'SP.Data.'Organizations'.ListItem'},"title":"test"}
organizations.controller.js:69 ƒ $http(requestConfig) {
if (!angular.isObject(requestConfig)) {
throw minErr('$http')('badreq', 'Http request configuration must be an object. Received: {0}', requestConfig);
…
POST ....... 400
From what I'm seeing in this output, it looks like It's outputting line 14, then line 33, then hits the error on line 31. It's saying it's a 400 error.
Any help is appreciated!!