New in 2.4: Test runs you can trust See what's new →

Logs in and sets the apibee_session cookie

POSThttps://api.testingapis.com/api/cookies/login

Logs in and sets the apibee_session cookie.

Test accounts: test / test123 (role user) and admin / admin123 (role admin). The cookie is HttpOnly, SameSite=Lax, Path=/, valid for one hour, and Secure only over HTTPS.

Request body

Optional. application/json, text/json, application/*+json, application/xml, text/xml, application/*+xml. Model: CookiesControllerLoginBody. Username and password.

Example body
{"username": "test", "password": "test123"}

Responses

200
Logged in; the session cookie is set.
400
Missing or malformed body.
401
Wrong username or password.

Example

Request
curl -X POST "https://api.testingapis.com/api/cookies/login" \
  -H "Content-Type: application/json" \
  -d '{"username": "test", "password": "test123"}'
Run in Studio
Response200 OK
Set-Cookie: apibee_session=f997b2a740419847f105b6b322e857dd; max-age=3600; path=/; samesite=lax; httponly

{
  "message": "Logged in. The session cookie is sent automatically on later requests.",
  "username": "test",
  "cookie": "apibee_session",
  "expiresAt": "2026-09-30T19:26:44Z"
}

Code examples

JavaScript (fetch)
const response = await fetch("https://api.testingapis.com/api/cookies/login", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
  },
  body: "{\"username\": \"test\", \"password\": \"test123\"}",
});
console.log(response.status, await response.text());
Python (requests)
import requests

response = requests.request(
    "POST",
    "https://api.testingapis.com/api/cookies/login",
    headers={
        "Content-Type": "application/json",
    },
    data="{\"username\": \"test\", \"password\": \"test123\"}".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/cookies/login"))
            .header("Content-Type", "application/json")
            .method("POST", HttpRequest.BodyPublishers.ofString("{\"username\": \"test\", \"password\": \"test123\"}"))
            .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.statusCode() + " " + response.body());
    }
}