Skip to Content
rentall API byla vydána 🎉
Autentizace, hlavičky (headers) a chyby

Autentizace, hlavičky (headers) a chyby

K autorizaci používejte Bearer tokeny. Pokud vaše konfigurace neříká jinak, zahrňte následující hlavičky:

  • Base URL: https://rentall.cz

Povinné hlavičky

  • Authorization: Bearer <token> — přístupový token
  • Content-Type: application/json — pro JSON těla (POST/PATCH)
  • Accept: application/json

Ukázka volání:

curl -s -X GET \ -H "Authorization: Bearer $RENTALL_TOKEN" \ -H "Accept: application/json" \ https://rentall.cz/api/products

Poznámka k Node.js: V Node 18+ je fetch globálně dostupný. V Node 16 použijte knihovnu jako node-fetch.

Limity požadavků

  • Omezení rychlosti je specifické pro projekt. Pokud je aktivní, můžete dostat 429 Too Many Requests s hlavičkou Retry-After.

Formát chyb

Většina endpointů vrací chyby v konzistentním tvaru:

{ "errors": [ { "message": "Validation failed: basic.product_name is required", "field": "basic.product_name" } ] }

Běžné kódy:

  • 400 Bad Request — validační chyba nebo špatný vstup
  • 401 Unauthorized — chybějící/neplatný token
  • 403 Forbidden — nepovolené dle přístupových pravidel
  • 404 Not Found — prostředek nenalezen
  • 409 Conflict — konfliktní stav (např. duplicitní ID)
  • 429 Too Many Requests — překročený limit
  • 5xx — serverové chyby

Kontakt: info@rentall.cz

Přihlášení a správa sezení (autentizace přes Rents)

Pokud váš projekt používá pro autentizaci kolekci Rents, autentizační routy jsou pod /api/rents. Tyto endpointy vydávají a spravují Bearer tokeny a podle konfigurace mohou využívat i httpOnly cookies.

Endpointy:

  • POST /api/rents/login — přihlášení e‑mailem a heslem; vrací token a aktuálního uživatele (rent)
  • GET /api/rents/me — vrátí aktuálně autentizovaného uživatele (rent)
  • POST /api/rents/refresh — obnoví (refresh) auth token
  • POST /api/rents/logout — ukončí sezení a případně smaže cookies

Poznámky:

  • Při volání me nebo refresh přikládejte Authorization: Bearer <token>, pokud používáte header‑based přístup. U cookie‑based přístupu se token řeší přes httpOnly cookies automaticky.
  • Expirace tokenu (exp) je, pokud je uvedena, UNIX čas (sekundy).

POST /api/rents/login

  • Tělo: { "email": string, "password": string }
  • Úspěch: 200 OK s autentizovaným uživatelem a tokenem

Ukázkový požadavek:

curl -s -X POST \ -H "Content-Type: application/json" \ -d '{"email":"info@rentall.cz","password":"<password>"}' \ https://rentall.cz/api/rents/login

Ukázková odpověď:

{ "user": { "id": "684dcbb7a60636d5a2618584", "email": "info@rentall.cz", "rentNameSystem": "Example Rentals s.r.o." }, "token": "<JWT>", "exp": 1767225600 }

JavaScript (fetch):

const res = await fetch("https://rentall.cz/api/rents/login", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ email: "info@rentall.cz", password: "<password>" }) }); const { user, token } = await res.json();

TypeScript (fetch):

interface LoginResponse { user: { id: string; email: string }, token: string, exp?: number } const res = await fetch("https://rentall.cz/api/rents/login", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ email: "info@rentall.cz", password: "<password>" }) }); const data: LoginResponse = await res.json();

GET /api/rents/me

Vrátí aktuálně přihlášeného uživatele (rent dokument).

curl -s \ -H "Authorization: Bearer $RENTALL_TOKEN" \ https://rentall.cz/api/rents/me

Ukázková odpověď:

{ "user": { "id": "684dcbb7a60636d5a2618584", "email": "info@rentall.cz" } }

JavaScript (fetch):

const token = process.env.RENTALL_TOKEN; const res = await fetch("https://rentall.cz/api/rents/me", { headers: { Authorization: `Bearer ${token}` } }); const me = await res.json(); console.log(me.user?.id);

TypeScript (fetch):

interface MeResponse { user?: { id: string; email?: string } } const token = process.env.RENTALL_TOKEN as string; const res = await fetch("https://rentall.cz/api/rents/me", { headers: { Authorization: `Bearer ${token}` } }); const me: MeResponse = await res.json(); console.log(me.user?.id);

POST /api/rents/refresh

Vydá nový token. Podle konfigurace může fungovat přes hlavičku nebo přes cookie‑based sezení.

curl -s -X POST \ -H "Authorization: Bearer $RENTALL_TOKEN" \ https://rentall.cz/api/rents/refresh

Ukázková odpověď:

{ "token": "<JWT>", "exp": 1767225600, "user": { "id": "684dcbb7a60636d5a2618584" } }

JavaScript (fetch):

const token = process.env.RENTALL_TOKEN; const res = await fetch("https://rentall.cz/api/rents/refresh", { method: "POST", headers: { Authorization: `Bearer ${token}` } }); const data = await res.json(); console.log(data.token, data.exp);

TypeScript (fetch):

interface RefreshResponse { token: string; exp?: number; user?: { id: string } } const token = process.env.RENTALL_TOKEN as string; const res = await fetch("https://rentall.cz/api/rents/refresh", { method: "POST", headers: { Authorization: `Bearer ${token}` } }); const refreshed: RefreshResponse = await res.json(); console.log(refreshed.token);

POST /api/rents/logout

Ukončí aktuální sezení a vymaže cookies, pokud se používají.

curl -s -X POST \ -H "Authorization: Bearer $RENTALL_TOKEN" \ https://rentall.cz/api/rents/logout

Ukázková odpověď:

{ "message": "Logged out" }

JavaScript (fetch):

const token = process.env.RENTALL_TOKEN; await fetch("https://rentall.cz/api/rents/logout", { method: "POST", headers: { Authorization: `Bearer ${token}` } });

TypeScript (fetch):

const token = process.env.RENTALL_TOKEN as string; await fetch("https://rentall.cz/api/rents/logout", { method: "POST", headers: { Authorization: `Bearer ${token}` } });