nmomn
nmomn

Reputation: 275

Parse.com Rest Api - Sign Up - error: "unauthorized"

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!

Upvotes: 0

Views: 1948

Answers (1)

nmomn
nmomn

Reputation: 275

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!

Upvotes: 2

Related Questions