0

Could you please help me debug my http request. I am trying to create a user but I keep getting error: "unauthorized"

Request

Here is a snippet of my code:

app.factory('userFactory', function($http){
    return {
        signUp: function(username, password) {
            var config = {
                headers: {
                    'X-Parse-Application-Id': ParseAppId,
                    'X-Parse-REST-API-Key': ParseRestApiKey,
                    'Content-Type': 'application/json'
                },
                data: {
                    'username': username,
                    'password': password
                }
            }
            return $http.post('https://api.parse.com/1/users', config);
        },
        logIn: function(username, password) {
            var config = {
             headers: {
               'X-Parse-Application-Id': ParseAppId,
               'X-Parse-REST-API-Key': ParseRestApiKey
             },
             params: { 
                username: username ,
                password: password
              }
            }
            return $http.get('https://api.parse.com/1/login', config);
        }
    };
});

Login works fine so App Id and Rest Api key are fine. Thanks you very much!

1 Answer 1

2

I found the solution: I was sending data inside config. Here is the documentation.

Here is a snippet of the working code:

app.factory('userFactory', function($http){
    return {
        signUp: function(username, password) {
            var config = {
                headers: {
                    'X-Parse-Application-Id': ParseAppId,
                    'X-Parse-REST-API-Key': ParseRestApiKey,
                    'Content-Type': 'application/json'
                } 
            }
            return $http.post('https://api.parse.com/1/users', {'username': username, 'password': password}, config);
        },
        logIn: function(username, password) {
            var config = {
             headers: {
               'X-Parse-Application-Id': ParseAppId,
               'X-Parse-REST-API-Key': ParseRestApiKey
             },
             params: { 
                username: username ,
                password: password
              }
            }
            return $http.get('https://api.parse.com/1/login', config);
        }
    };
});

Thanks for reading!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.