Having issues logging in over the API

Boris J7 years ago

I'm having issues logging over the API. I'm sending a POST request to the API with email and password, but Im getting 415 error. Ive tried removing headers, setting headers, but either I get Bad Request error or 415 error. I'm using Angular.

I set headers like this:

     let headers = new HttpHeaders({
       "Content-Type": "application/json",
     });

And do POST request like this:

return this.http.post(`${this.API_URL}/session`, data, {headers});

Data object has email and password.
https://i.imgur.com/KI3KZ8o.png

Anton Tananaev7 years ago

Why are you using JSON for session endpoint? Please carefully read API documentation.

Boris J7 years ago

I've tried setting Content Type to form-data, x-www-form-urlencoded etc and I always get either 415, or Bad Request.

https://i.imgur.com/edPdlnu.png

This is returning 400 Bad Request, NullPointerException (DataManager:312 < PermissionsManager:439 < SessionResource:103 < ...)

Anton Tananaev7 years ago

You need to do some more reading. You are still sending JSON body.

Boris J7 years ago

Had to format data differently.
Correct way is something like this:
let body = email=${data.email}&password=${data.password};