Login
POST
{{server}}/api/v1/counter/loginLogin Counter
This endpoint allows users to log in to the counter API.
Request Body
-
username(string, required): The username of the user. -
password(string, required): The password of the user.
Response
-
username(string): The username of the logged-in user. -
name(string): The name of the logged-in user. -
token(string): The authentication token for the logged-in user. -
sso(boolean): Indicates if single sign-on (SSO) used for login.
Request
Headers
| Key | Value |
|---|---|
Accept | application/json |
Body (json)
{
"username": "user1",
"password": "user1"
}
Code snippets
- cURL
- JavaScript
- Python
curl -X POST '{{server}}/api/v1/counter/login' \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"username": "user1",
"password": "user1"
}'
const response = await fetch("{{server}}/api/v1/counter/login", {
method: "POST",
headers: {
"Accept": "application/json",
"Content-Type": "application/json"
},
body: JSON.stringify({
"username": "user1",
"password": "user1"
}),
});
const data = await response.json();
console.log(data);
import requests
url = "{{server}}/api/v1/counter/login"
headers = {
"Accept": "application/json",
"Content-Type": "application/json"
}
payload = {
"username": "user1",
"password": "user1"
}
response = requests.post(url, headers=headers, json=payload)
print(response.status_code)
print(response.json())
Examples (2)
- Login as user1
- Invalid username
Example request
POST
{{server}}/api/v1/counter/loginHeaders (1)
| Key | Value |
|---|---|
Accept | application/json |
Body
{
"username": "user1",
"password": "user1"
}
Example response 200 Ok
Response headers (9)
| Key | Value |
|---|---|
Access-Control-Expose-Headers | * |
Cache-Control | no-store, no-cache, must-revalidate |
Access-Control-Allow-Origin | * |
Access-Control-Allow-Methods | POST, PUT, GET, OPTIONS, DELETE |
Access-Control-Allow-Credentials | true |
Content-Length | 243 |
Access-Control-Max-Age | 86400 |
Access-Control-Allow-Headers | Content-Type, Authorization, X-Requested-With |
Content-Type | application/json;charset=utf-8 |
Body
{
"username": "user1",
"name": "User 1",
"token": "eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJxbmV0NyIsInN1YiI6IjAwMDAwMDAwLTAwMDAtNDAwMC0wMDAyLTAwMDAwMDAwMDAwNiIsImV4cCI6MTcyMDEzMDQwMCwic3NvIjpmYWxzZX0.c9-WdFMj6pWBKlyj8lgypCNtPUAs3Ihx4zwnCs9p-fM",
"sso": false
}
Example request
POST
{{server}}/api/v1/counter/loginHeaders (1)
| Key | Value |
|---|---|
Accept | application/json |
Body
{
"username": "john_doe",
"password": "104n603"
}
Example response 400 Bad Request
Response headers (9)
| Key | Value |
|---|---|
Access-Control-Expose-Headers | * |
Cache-Control | no-store, no-cache, must-revalidate |
Access-Control-Allow-Origin | * |
Access-Control-Allow-Methods | POST, PUT, GET, OPTIONS, DELETE |
Access-Control-Allow-Credentials | true |
Content-Length | 3240 |
Access-Control-Max-Age | 86400 |
Access-Control-Allow-Headers | Content-Type, Authorization, X-Requested-With |
Content-Type | application/json;charset=utf-8 |
Body
{
"name": "BadRequest",
"message": "Invalid username or password",
"nodeID": "norbi-pc3-54396",
"code": 400,
"type": "INVALID_USERNAME",
"retryable": false,
"stack": "services.moleculer.error.MoleculerClientError: Invalid username or password\r\n\tat com.qnet7.core.ErrorFactory.badRequest(ErrorFactory.java:175)\r\n\tat com.qnet7.acl.AccessController.invalidUserError(AccessController.java:583)\r\n\tat com.qnet7.acl.AccessController.lambda$32(AccessController.java:552)\r\n\tat io.datatree.Promise.lambda$0(Promise.java:403)\r\n\tat java.util.concurrent.CompletableFuture.uniHandle(CompletableFuture.java:836)\r\n\tat java.util.concurrent.CompletableFuture.uniHandleStage(CompletableFuture.java:848)\r\n\tat java.util.concurrent.CompletableFuture.handle(CompletableFuture.java:2168)\r\n\tat io.datatree.Promise.then(Promise.java:398)\r\n\tat com.qnet7.acl.AccessController.authenticateInDatabase(AccessController.java:538)\r\n\tat com.qnet7.acl.AccessController.lambda$31(AccessController.java:528)\r\n\tat io.datatree.Promise.lambda$0(Promise.java:403)\r\n\tat java.util.concurrent.CompletableFuture.uniHandle(CompletableFuture.java:836)\r\n\tat java.util.concurrent.CompletableFuture.uniHandleStage(CompletableFuture.java:848)\r\n\tat java.util.concurrent.CompletableFuture.handle(CompletableFuture.java:2168)\r\n\tat io.datatree.Promise.then(Promise.java:398)\r\n\tat com.qnet7.acl.AccessController.authenticate(AccessController.java:524)\r\n\tat com.qnet7.acl.AccessController.lambda$0(AccessController.java:312)\r\n\tat services.moleculer.service.LocalActionEndpoint.lambda$0(LocalActionEndpoint.java:90)\r\n\tat services.moleculer.metrics.MetricMiddleware$1.lambda$0(MetricMiddleware.java:74)\r\n\tat io.datatree.Promise.<init>(Promise.java:261)\r\n\tat services.moleculer.metrics.MetricMiddleware$1.handler(MetricMiddleware.java:59)\r\n\tat services.moleculer.service.ActionEndpoint.handler(ActionEndpoint.java:85)\r\n\tat services.moleculer.service.DefaultServiceInvoker.call(DefaultServiceInvoker.java:132)\r\n\tat services.moleculer.service.DefaultServiceInvoker.call(DefaultServiceInvoker.java:123)\r\n\tat services.moleculer.context.Context.call(Context.java:177)\r\n\tat services.moleculer.context.ContextSource.call(ContextSource.java:383)\r\n\tat com.qnet7.published.v1.Counter.lambda$0(Counter.java:125)\r\n\tat services.moleculer.service.LocalActionEndpoint.lambda$0(LocalActionEndpoint.java:90)\r\n\tat services.moleculer.metrics.MetricMiddleware$1.lambda$0(MetricMiddleware.java:74)\r\n\tat io.datatree.Promise.<init>(Promise.java:261)\r\n\tat services.moleculer.metrics.MetricMiddleware$1.handler(MetricMiddleware.java:59)\r\n\tat services.moleculer.service.ActionEndpoint.handler(ActionEndpoint.java:85)\r\n\tat services.moleculer.service.DefaultServiceInvoker.call(DefaultServiceInvoker.java:132)\r\n\tat services.moleculer.service.DefaultServiceInvoker.call(DefaultServiceInvoker.java:123)\r\n\tat services.moleculer.web.router.ActionInvoker.lambda$8(ActionInvoker.java:286)\r\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)\r\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)\r\n\tat java.lang.Thread.run(Thread.java:748)",
"data": {
"username": "john_doe"
}
}