Getting 405 Error When calling post request on user/custom (angularJS)


#1

First time poster! I am using dreamfactory for a school project revolving around the selling of textbooks. When a user creates an account, they will enter their basic user credentials and a post request is made to user/register and the user is logged in. They are then taken to a second webpage where they enter their twitter credentials, and the school they go to. These are then supposed to be posted to user/custom, however I am getting these errors when I try:

When doing this directly in the API docs with a user of the app, it works, but not in the app! Here is the relevant code:
.config([

'$routeProvider', 

function ($routeProvider) {
	$routeProvider
		.when('/login', {
			title		: 'Login',
			controller	: 'LoginCtrl',
			templateUrl	:  'app/login/login.html'
		})

		.when('/register', {
			title		: 'Register',
			controller	: 'RegisterController',
			templateUrl	:  'app/login/register.html'
		})
		
		.when('/register2',{
		    title       : 'RegisterCustoms',
		    controller  : 'RegisterCustomsController',
		    templateUrl : 'app/login/register2.html',
		    resolve     :   {
		         custom: function () {
	    			return { };
	    		}

		    }
		});
}

])

.factory('Customs', [
'$resource',

function ($resource) {
	return $resource('api/v2/user/custom/:id', { id: '@id' }, {
		query: {
			method: 'GET',
			isArray: false
		},
		create: {
			method: 'POST'
		},
		update: {
			method: 'PUT'
		},
		remove: {
			method: 'DELETE'
		}
	});
}

])

.controller('RegisterCustomsController', [
'$scope', 'Customs', 'custom','$location', '$mdToast', '$mdDialog',

function($scope, Customs, custom, $location, $mdToast, $mdDialog, $mdScope){
    $scope.states = ['States go He'];
    $scope.schools =['1'];
    $scope.register = function(){
        
        //$scope.custom = angular.copy(custom);
        console.log($scope.custom)
        Customs.create({
            twitterUsername: $scope.custom.twitterUsername,
            twitterPassword: $scope.custom.twitterPassword,
            schoolID: $scope.custom.selectedSchool
        }).$promise.then(function(){
            $location.path('/hompeage');
             
            $mdToast.show($mdToast.simple().content('Welcome new user!'));
              $mdDialog.hide($mdScope.book);
        });
    }
}

])


#2

The 405 method seems to be suggesting that you can’t POST to /user/custom for whatever reason. It’s possible that testing in the API docs works because it’s you (an administrator), and the app doesn’t work because it’s using an app key or a different user group and that role doesn’t have permissions to POST to the endpoint.

405 Not Allowed seems likely to be a permissions issue.


#3

My bad, I should of been more clear! I logged into the API docs with a user of the application, and it did work fine there, so I’m pretty sure it’s not a permissions issue.