Log in and receive a JWT for the Admin endpoint
POST
https://api.testingapis.com/api/User/LoginCredentials: Michael / Thompson (role Admin). The token expires after 15 minutes. Send it as Authorization: Bearer <token> to GET /api/Admin/authorize.
Request body
Optional. application/json, text/json, application/*+json, application/xml, text/xml, application/*+xml. Model: UserLogin. Username and password.
Example body
{"username": "Michael", "password": "Thompson"}Responses
- 200
- Token and login time.
- 404
- Unknown username or wrong password (plain-text body).
Example
Request
curl -X POST "https://api.testingapis.com/api/User/Login" \
-H "Content-Type: application/json" \
-d '{"username": "Michael", "password": "Thompson"}'Response200 OK
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6Ik1pY…
"loginTime": "2026-09-30 23:56:45
}Code examples
JavaScript (fetch)
const response = await fetch("https://api.testingapis.com/api/User/Login", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: "{\"username\": \"Michael\", \"password\": \"Thompson\"}",
});
console.log(response.status, await response.text());Python (requests)
import requests
response = requests.request(
"POST",
"https://api.testingapis.com/api/User/Login",
headers={
"Content-Type": "application/json",
},
data="{\"username\": \"Michael\", \"password\": \"Thompson\"}".encode("utf-8"),
allow_redirects=False,
)
print(response.status_code, response.text)Java (HttpClient)
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
HttpClient client = HttpClient.newBuilder()
.followRedirects(HttpClient.Redirect.NEVER)
.build();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.testingapis.com/api/User/Login"))
.header("Content-Type", "application/json")
.method("POST", HttpRequest.BodyPublishers.ofString("{\"username\": \"Michael\", \"password\": \"Thompson\"}"))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode() + " " + response.body());
}
}