restAngular using method customPOST. text:[object%20Object] is getting added on to the end of URL

raging_subs picture raging_subs · Nov 5, 2013 · Viewed 12.3k times · Source

The goal I'm trying to accomplish is doing a post in restAngular. I keep trying the code below, but I receive a status code 400 with a customPost. This is the URL I send my request to...http://localhost/api/api/index.php/auth/token/[object%20Object]. As you can see [object%20Object] is gettting added on. How do I get rid of this? Should I be doing another method besides a customPOST? Why is this getting added on?

  var login = Restangular.one('auth/token').customPOST(
    {grant_type:"password", username:"[email protected]",password:"666666",scope:"app"},{},{},
    {Authorization:'Basic ' + client,
    ContentType:'application/x-www-form-urlencoded'});

Answer

Jedidiah Hurt picture Jedidiah Hurt · Nov 6, 2013

The second argument to customPOST should be a string representing the path. Try this instead:

var login = Restangular.one('auth/token').customPOST(
    {grant_type:'password', username:'[email protected]', password:'666666', scope:'app'},
    '',
    {},
    {
        Authorization:'Basic ' + client,
        ContentType:'application/x-www-form-urlencoded'
    }
);

Or this:

var login = Restangular.one('auth').customPOST(
    {grant_type:'password', username:'[email protected]', password:'666666', scope:'app'},
    'token',
    {},
    {
        Authorization:'Basic ' + client,
        ContentType:'application/x-www-form-urlencoded'
    }
);