StockManager’s API uses Flask session cookies for authentication — there are no API keys, bearer tokens, or JWTs. When you log in successfully, the server creates a server-side session and responds with aDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/InnoDev69/StockManager/llms.txt
Use this file to discover all available pages before exploring further.
Set-Cookie header. Every subsequent request must present that cookie; without it the server returns 401 Unauthenticated. This model works transparently in browser contexts and is straightforward to replicate with any HTTP client that supports cookie jars.
Login
Send credentials as JSON toPOST /api/login. The endpoint accepts either a username or an email address in the username field.
200 OK
Set-Cookie header containing the Flask session cookie. Store and send this cookie with every subsequent request.
Error responses
| Status | Condition |
|---|---|
400 | username or password field is missing or empty |
401 | Credentials do not match any account |
403 | Account is disabled (status = 0) or the account’s role is not a recognised system role |
Session Cookie
After a successful login the server sets aSet-Cookie response header. The session stores three values:
| Key | Description |
|---|---|
user_id | Integer primary key of the authenticated user |
username | Username string as supplied at login |
role | Role string — one of root, admin, or vendedor |
session.permanent = True is set during the HTML-based login flow (POST /login). The API endpoint (POST /api/login) does not set session.permanent, so the resulting session cookie carries no explicit expiry and will be discarded when the browser (or HTTP client) ends its session. For long-lived automation sessions, log in via the browser-based login flow instead.Making Authenticated Requests
curl
Use-c to save the cookie jar after login and -b to send it with subsequent requests:
JSON error responses for non-browser clients
By default, unauthenticated requests to non-API routes return an HTML redirect to the login page. Routes under/api/ always return JSON errors. If you are calling a non-/api/ route from a script and want a JSON 401 instead of an HTML redirect, include the following header:
_is_api_request() helper in api/auth_utils.py checks for this header and returns {"error": "No autenticado"} with status 401 instead of rendering login.html.
Roles
Therole field returned at login determines which endpoints are accessible. Roles are defined in data/roles.py:
| Role string | Constant | Access level |
|---|---|---|
root | ROLES.ROOT | Full access to all endpoints |
admin | ROLES.ADMIN | Administrative access; can manage users and products |
vendedor | ROLES.VENDOR | Vendor access; limited to sales and product reads |
@require_role(...) decorator from api/auth_utils.py. Requests from authenticated users whose role is not in the allowed list receive 403 Forbidden.
Logout
There is noDELETE /api/session or dedicated API logout endpoint. To invalidate the session, call:
routes/auth.py that calls session.clear() and redirects to the login page. For scripted clients, call this route with your cookie jar to clear the server-side session:
Register a New Account
New users can submit a registration request without being logged in.- All three fields are required.
passwordmust be at least 6 characters.emailmust pass theUserValidator.validate_emailformat check.usernameandemailmust not already exist in the database.
201 Created
status = 0 (pending) and the vendedor role. They cannot log in until an administrator approves them.
Approval workflow — registrations created via
POST /api/register are placed in a pending state (status = 0). An administrator must review the application and set status = 1 before the account can be used to log in. Attempting to log in with a pending or disabled account returns 403 Forbidden.Password Reset
Users who have lost their password can initiate a self-service reset without a session. The flow involves three steps:Request a reset code
Send the registered email address to Response —
POST /api/users/reset-password. A 6-digit code is emailed to that address and stored server-side with a 15-minute expiry.200 OKVerify the code
Submit both the email and the received code to Response — Returns
POST /api/users/validate-code.200 OK401 if the code is invalid or expired.