Developer

API Reference

All endpoints are under /api and accessed through the frontend proxy at http://<machine>:1994/api. The backend is never directly reachable.

Authentication

All routes except /auth/status, /auth/login, /auth/register, and the one-time POST /settings require the nodedr_session HttpOnly cookie. Admin-only routes additionally require the admin role on the authenticated account.

To authenticate: POST /api/auth/login with { "email": "...", "password": "..." }. The session cookie is set automatically on success and included in all subsequent requests by the browser.

Base URL

http://<machine>:1994/api

All requests go to the Next.js frontend, which server-side proxies /api/* to the internal backend. The backend is never directly accessible from the network.

Response format

All responses are JSON. Errors return a { "error": "message" } body with an appropriate HTTP status code (400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 422 Validation Error, 500 Internal Server Error).

Endpoint table

MethodPathAuthDescription
GET/api/auth/statusNoneWhether an admin account has been created yet (drives onboarding redirect)
POST/api/auth/registerNoneCreate the first admin account (one-time, disabled once an admin exists)
POST/api/auth/loginNoneAuthenticate with email + password; sets nodedr_session cookie
POST/api/auth/logoutSessionInvalidate the current session cookie
POST/api/auth/change-passwordSessionChange the authenticated user's password
GET/api/auth/usersAdminList all staff accounts
POST/api/auth/usersAdminCreate a new staff account
PUT/api/auth/users/:idAdminUpdate a staff account (name, role, active state, password reset)
GET/api/settingsSessionRead shop settings (currency, tax, loyalty, receipt config)
POST/api/settingsNoneInitial onboarding — create shop settings (one-time)
PUT/api/settingsAdminUpdate shop settings
GET/api/productsSessionList all products; supports ?search=&category= query params
POST/api/productsAdminCreate a new product
GET/api/products/:idSessionGet a single product by ID
PUT/api/products/:idAdminUpdate a product
DELETE/api/products/:idAdminDelete a product
GET/api/products/barcode/:codeSessionLook up a product by barcode
GET/api/products/low-stockSessionProducts at or below the low-stock threshold
GET/api/customersSessionList customers; supports ?search= and ?page= params
POST/api/customersSessionCreate a customer
PUT/api/customers/:idSessionUpdate a customer
GET/api/customers/phone/:phoneSessionLook up a customer by phone number
GET/api/customers/top-loyaltySessionTop customers ranked by current loyalty point balance
POST/api/customers/:id/settle-dueSessionRecord a payment against a customer's due balance
GET/api/customers/:id/due-paymentsSessionList all due payments for a customer
POST/api/invoicesSessionFinalize a sale — server computes price, tax, discount, loyalty. Can include returns for exchange.
GET/api/invoicesSessionPaginated sales history; supports ?search=&from=&to=&paymentMethod= params
GET/api/invoices/summarySessionDashboard stat cards — today's revenue, count, average order value
GET/api/invoices/analyticsSessionChart data — revenue trend, top products, payment method mix
GET/api/invoices/export.csvAdminFull sales history as CSV; supports ?from=&to= date range
GET/api/invoices/:idSessionGet a single invoice with all line items
POST/api/returnsSessionStandalone return against a past invoice — restocks items, issues refund or store credit
GET/api/returns/by-invoice/:invoiceIdSessionAll returns made against an invoice (used to compute remaining returnable quantity)
GET/api/print/:invoiceId/receiptSessionSelf-printing HTML receipt — opens a page and calls window.print()
GET/api/print/:invoiceId/pdfSessionServer-generated PDF receipt download
GET/api/masters/summaryAdminRow counts for all reference data tables
POST/api/masters/tax-codes/importAdminImport HSN/SAC CSV — replaces existing rows
GET/api/masters/tax-codes/searchSessionAutocomplete HSN/SAC codes; ?q=&type=HSN|SAC
POST/api/masters/pincodes/importAdminImport PIN code CSV — replaces existing rows
GET/api/masters/pincodes/:codeSessionLook up a PIN code for city/state autofill
POST/api/masters/ifsc/importAdminImport IFSC code CSV — replaces existing rows
GET/api/masters/ifsc/:codeSessionLook up an IFSC code for bank/branch details

Example — finalize a sale

POST /api/invoices
Content-Type: application/json
Cookie: nodedr_session=<your-session-cookie>

{
  "customerId": 42,
  "items": [
    { "productId": 7, "quantity": 2 },
    { "productId": 15, "quantity": 1 }
  ],
  "paymentMethod": "UPI",
  "amountPaid": 250.00,
  "discountPercent": 5,
  "loyaltyRedeemed": 10.00
}

// The server computes final price, tax, discount, loyalty deduction
// from the catalog and settings — client values are never trusted for money.

Example — export sales CSV

GET /api/invoices/export.csv?from=2026-07-01&to=2026-07-25
Cookie: nodedr_session=<admin-session-cookie>

# Returns Content-Type: text/csv with filename attachment header