Skip to Content
REST API

REST API

Inventario poskytuje REST API dokumentované cez OpenAPI 3.1 špecifikáciu. API je single source of truth pre všetky klienti (Next.js web, mobilné aplikácie, MCP server, integrácie).

OpenAPI spec bude dostupný na produkčnej URL: https://api.inventario.sportup.sk/openapi.json (po deploy slice #4).

V dev móde s ENABLE_SWAGGER=true máte Swagger UI na http://localhost:3000/docs.

Authentication

Všetky API endpointy (okrem /health) vyžadujú Bearer token v Authorization headeri:

GET /v1/assets HTTP/1.1 Host: api.inventario.sportup.sk Authorization: Bearer eyJhbGciOiJSUzI1NiIs...

Token získate z Microsoft Entra ID OAuth2 toku. Detaily v Architektúra.

API konvencie

URL structure

/v1/{resource} → list / create /v1/{resource}/{id} → get / update / delete /v1/{resource}/{id}/{rel} → vnorené resources

Aktuálna verzia API je v1. Pri breaking changes pridáme v2 paralelne.

HTTP metódy

MetódaPoužitieIdempotent
GETNačítanie dátáno
POSTVytvorenie nového resourcenie
PATCHPartial updatenie
PUTNepoužívame (preferujeme PATCH)
DELETEZmazanieáno

Status kódy

KódVýznam
200 OKÚspešné GET / PATCH
201 CreatedÚspešné POST (vrátime aj Location header)
204 No ContentÚspešné DELETE
400 Bad RequestValidation error (s Zod error details v body)
401 UnauthorizedChýbajúci alebo neplatný token
403 ForbiddenAuth OK ale nemáte permissions
404 Not FoundResource neexistuje (alebo nie je v tvojom tenant)
409 ConflictConflict (napr. duplikát inventárneho čísla)
429 Too Many RequestsRate limit prekročený
500 Internal Server ErrorServer error (logovaný v Sentry)

Error response formát

{ "error": { "code": "ASSET_NOT_FOUND", "message": "Asset with id 65f... not found in your organisation", "details": { "assetId": "65f...", "organisationId": "65a..." } } }

Hlavné endpointy (Slice #2)

Assets

EndpointMetódaRolaPopis
/v1/assetsGETEMPLOYEE+List všetkých assetov v tenant scope
/v1/assetsPOSTASSET_MANAGER+Vytvorenie nového assetu
/v1/assets/{id}GETEMPLOYEE+Detail assetu
/v1/assets/{id}PATCHASSET_MANAGER+Update assetu
/v1/assets/{id}DELETEADMINZmazanie assetu

Categories

EndpointMetódaRolaPopis
/v1/categoriesGETEMPLOYEE+List kategórií
/v1/categoriesPOSTASSET_MANAGER+Vytvorenie kategórie
/v1/categories/{id}GETEMPLOYEE+Detail kategórie
/v1/categories/{id}PATCHASSET_MANAGER+Update kategórie
/v1/categories/{id}DELETEADMINZmazanie (iba ak nie sú referencované)

Locations

Rovnaký pattern ako Categories.

Users (Slice #3 K10, čoskoro)

EndpointMetódaRolaPopis
/v1/usersGETADMINList používateľov v org
/v1/users/{id}GETADMINDetail používateľa
/v1/users/{id}PATCHADMINUpdate role / isActive

Pagination

List endpoints podporujú cursor-based pagination:

GET /v1/assets?limit=20&cursor=eyJfaWQiOiI2NWYi...

Response:

{ "data": [...], "pagination": { "limit": 20, "total": 1234, "nextCursor": "eyJfaWQiOiI2NjAi...", "hasMore": true } }
GET /v1/assets?status=AVAILABLE&categoryId=65f...&q=lopta

Rate limiting

Default limity (per organisation):

TierRequests/minRequests/day
Free6010 000
Pro Small30050 000
Pro Standard1 000200 000
Pro Plus3 0001 000 000
Enterprisecustomcustom

Limit headers v každej response:

X-RateLimit-Limit: 300 X-RateLimit-Remaining: 287 X-RateLimit-Reset: 1746387600

Testovanie API

cURL examples

# Health check (no auth) curl https://api.inventario.sportup.sk/health # Get assets (with auth) curl -H "Authorization: Bearer $TOKEN" \ https://api.inventario.sportup.sk/v1/assets # Create asset curl -X POST \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{ "name": "Lopta Adidas Tiro Pro", "categoryId": "65f...", "locationId": "65g..." }' \ https://api.inventario.sportup.sk/v1/assets

Postman / Insomnia

OpenAPI spec môžete importovať do Postmana alebo Insomnie pre automatické generovanie všetkých requestov.

MCP Server (Slice #6, plánované)

Inventario bude mať MCP (Model Context Protocol) server ktorý dovolí AI agentom (Claude, ChatGPT, vlastné agenty) priamo pracovať s API. Plánované endpointy:

  • inventario_list_assets — list majetku
  • inventario_create_loan — vytvorenie výpožičky
  • inventario_get_audit_log — query audit logu

Pre dev kontext si pozrite Roadmap .

Ďalšie zdroje

  • OpenAPI spec (production): https://api.inventario.sportup.sk/openapi.json (čoskoro)
  • Swagger UI (production): https://api.inventario.sportup.sk/docs (čoskoro)
  • Backend source code 
  • Zod schemas 
Last updated on