API problem logging in

IPCortex API version 1.9.1

I’m having trouble logging in to the API. I’m running a Ruby on Rails application.

I can use the Javascript libraries to log in just fine:

IPCortex.PBX.Auth.setHost('https://my.ip.address'); IPCortex.PBX.Auth.login(function () { console.log('logged in!'); }, { 'username': 'username', 'password': 'password' });

But I cannot get my application to log in. When I send a POST request to
with the following arguments:

{ auth: { type: 'auth', username: 'admin', password: 'password' } }

I keep getting “failure - not logged in”.

I’m not sure where this is coming from.


Hi Anthony,
What JSON result do you get from the POST transaction to https://my.ip.address/rest/auth ?

Using the admin account with a password is probably fine just to try out API calls, but we would strongly recommend that you don’t do this in production code or against a real system. What you should do is create a user and put it into a roles which has the bare minimum permission set for the operations you want to perform and then use these credentials only for API calls (either username/password or preferably API key).

Hi Rob,
Thanks for your response.

These are the headers of the response I get:
{"server"=>["nginx/1.6.2"], "date"=>["Thu, 22 Sep 2016 11:32:12 GMT"], "content-type"=>["text/json"], "content-length"=>["44"], "connection"=>["close"], "access-control-allow-credentials"=>["true"], "access-control-allow-origin"=>["*"], "access-control-allow-headers"=>["Content-Type"], "access-control-allow-methods"=>["GET, POST"], "cache-control"=>["no-cache"], "pragma"=>["no-cache"], "expires"=>["Thu, 01 Jan 1970 00:00:00 GMT"], "vary"=>["*"], "last-modified"=>["Thu, 22 Sep 2016 11:32:12 GMT"], "set-cookie"=>["Red60urne=uRnLKptuP3+nHsxbLlpyH+4s;HttpOnly;Max-Age=86400;path=/;"]}

And this is the body:
{"result"=>"fail", "message"=>"Not logged in."}

I won’t be using the same admin user for production. I just need to test out the implementation for now.

Hi Anthony,
Could you paste a dump of exactly the JSON data you are posting. As far as I can tell you can only hit that error if there is no auth.password or auth.type in the posted JSON.
Also, what PBX software version are you using.

Hi Rob,

I am using version 6.1.6 of the software.

This is the output of my console. Hope this helps:

opening connection to opened starting SSL for SSL established <- "POST /rest/auth HTTP/1.1\r\nAccept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\nAccept: */*\r\nUser-Agent: Ruby\r\nConnection: close\r\nHost:\r\nContent-Length: 60\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n" <- "auth[type]=auth&auth[username]=admin&auth[password]=password" -> "HTTP/1.1 200 OK\r\n" -> "Server: nginx/1.6.2\r\n" -> "Date: Thu, 22 Sep 2016 13:21:46 GMT\r\n" -> "Content-Type: text/json\r\n" -> "Content-Length: 44\r\n" -> "Connection: close\r\n" -> "Access-Control-Allow-Credentials: true\r\n" -> "Access-Control-Allow-Origin: *\r\n" -> "Access-Control-Allow-Headers: Content-Type\r\n" -> "Access-Control-Allow-Methods: GET, POST\r\n" -> "Cache-Control: no-cache\r\n" -> "Pragma: no-cache\r\n" -> "Expires: Thu, 01 Jan 1970 00:00:00 GMT\r\n" -> "Vary: *\r\n" -> "Last-Modified: Thu, 22 Sep 2016 13:21:46 GMT\r\n" -> "Set-Cookie: Red60urne=UXjJkmK88vbGY9TMpzIKzaSK;HttpOnly;Max-Age=86400;path=/;\r\n" -> "\r\n" reading 44 bytes... -> "{\"result\":\"fail\",\"message\":\"Not logged in.\"}" read 44 bytes Conn close

OK, I can see your problem. I think you are sending a toString() dump of your auth object rather than JSON postdata.

You need to call JSON.stringify() to convert your auth object into JSON before making a REST call with the result.

Hi Rob,

You’re right. That did the trick.

Thanks for your help!

Do you think you could take a look at this issue here: API problem with call data
I’m still getting a 404.