Auth
Login

Login

Registered users can login using the API described below. The login operation requires two properties: one marked as user identity and the second is password.

Method : POST

URL : /api/login

Body : JSON

{
  "username": "username",
  "password": "secret"
}

Request :

var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
 
var raw = JSON.stringify({
	"username": "username",
	"password": "secret"
});
 
var requestOptions = {
	method: 'POST',
	headers: myHeaders,
	body: raw,
	redirect: 'follow'
};
 
fetch("/api/login", requestOptions)
	.then(response => response.text())
	.then(result => console.log(result))
	.catch(error => console.log('error', error));

Response : 200 - OK

{
  "id": 1,
  "username": "admin",
  "name": "Admin",
  "type": "admin",
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwicGFzc3dvcmQiOiJBZG1pbiIsImlhdCI6MTY3MzU5MDY1NH0.z8Bc26vhWGICs78KyujSWXY5S98qoccYl9pBVWEFYBY"
}

Response :

{
    "error_code": "422",
    "message": "Unprocessable Content",
    "error": "Username required",
    "error": "Password required"
}