Account S2S Integration
Server-to-server integration for account systems over REST and WebSocket.
The integration surface is production-ready. Build on top of api.niyantha.in using this guide as the stable contract for your backend integration.
https://api.niyantha.inwss://api.niyantha.in/wsAuthentication
API Keys
- •Keys are issued per account and required for S2S REST + WS.
- •Default expiry is 24 hours. Override with
ttl_seconds(relative) orexpires_at(absolute Unix seconds). - •Expired or revoked keys are rejected immediately.
REST Authentication
Use either approach:
Option A — Headers
X-API-Key: <public_key>
X-API-Secret: <secret>Option B — HTTP Basic Auth
username = <public_key>
password = <secret>WebSocket Authentication
Connect to wss://api.niyantha.in/ws and send auth.login with authType: "s2s":
{
"type": "auth.login",
"requestId": "s2s-auth-1",
"payload": {
"authType": "s2s",
"token": "<public_key>",
"metadata": {
"secret": "<secret>",
"app": "anystore",
"storeId": "<optional>"
}
}
}{
"type": "auth.success",
"requestId": "s2s-auth-1",
"payload": {
"identityId": "account-<accountId>",
"role": "account",
"context": { "accountId": "<id>" }
}
}Key Management (REST + WS)
Authorization: Bearer <token>). These endpoints are not S2S-key protected.REST
/api/v1/session/keysCreate a new API key
{ "name": "primary", "ttl_seconds": 86400 }{
"id": 10,
"name": "primary",
"username": "<public_key>",
"secret": "<secret>",
"expires_at": 1739580000
}/api/v1/session/keysList all API keys
{
"items": [
{
"id": 10,
"name": "primary",
"username": "<public_key>",
"created_at": 1739493600,
"expires_at": 1739580000,
"revoked_at": 0,
"last_used_at": 1739497200
}
]
}/api/v1/session/keys/:id/expireRevoke / expire a key
Response: key summary (same shape as list item)
WebSocket
account.keys.createPayload: { name, ttl_seconds } → account.keys.create.ok with { id, name, username, secret, expires_at }
account.keys.listPayload: {} → account.keys.list.ok with { items: [...] }
account.keys.expirePayload: { key_id } → account.keys.expire.ok with key summary
Sample Payload Cookbook
Create Store
{
"type": "grocery",
"name": "Fresh Mart Hub",
"description": "Neighborhood store connected to Niyantha logistics",
"location_id": 101,
"owner_aadhaar_front_file_id": 12,
"owner_aadhaar_back_file_id": 13,
"shop_body_type": "stationary_shop"
}Create Store Product
{
"store_item_id": 501,
"name": "Tomato Crate",
"type": "vegetable",
"unit": "kg",
"price_per_unit": 24,
"min_order_unit": 1,
"max_order_unit": 100,
"stock_type": "limited",
"stock": 400
}Create Shipment
{
"from_location_id": 101,
"to_location_id": 205,
"vehicle_type": "truck",
"load_weight": 1250,
"notes": "Handle with care"
}Driver Location Update
{
"latitude": 12.9716,
"longitude": 77.5946,
"measured_at": 1736768400,
"accuracy": 9
}S2S REST Endpoints
Base path: https://api.niyantha.in/api/v1/s2s/accounts — API key auth required on all endpoints.
Account Profile
/Get account profile
/updateUpdate profile
/update_passwordUpdate password
/initiate_contact_updateStart contact update flow
/update_contactConfirm contact update
/initiate_email_updateStart email update flow
/update_emailConfirm email update
Account Apps
/appsList apps
/appsCreate app
/apps/logoUpload app logo
/apps/:idGet app
/apps/:idUpdate app
/apps/settingsApp settings bootstrap
Stores
/storesList stores
/stores/:idGet store
/storesCreate store
/stores/:idUpdate store
/stores/:id/settingsStore settings
Store Products
/stores/:id/productsCreate store product
/stores/:id/productsList store products
/stores/:id/products/:product_idGet store product
/stores/:id/products/:product_idUpdate store product
/stores/:id/products/:product_idDelete store product
Base Products (read-only)
/base-productsList base products
Catalog Products
/productsCreate catalog product
/products/:idUpdate catalog product
/products/:idGet catalog product
/productsList catalog products
Orders
/ordersList orders
/orders/:idGet order
/orders/:id/acceptAccept order
/orders/:id/declineDecline order
/orders/:id/mark-paid-and-deliveredMark paid and delivered
/stores/:store_id/ordersList store orders
Locations
/locations/estimateEstimate distance/time
/locations/address/coordinatesGeocode address
/locations/coordinates/addressReverse geocode
/locationsCreate location
/locationsList locations
/locations/:idGet location
/locations/:idUpdate location
Files
/filesUpload file (multipart)
/files/:idGet file
Networks
/networksCreate network
/networksList networks
/networks/:idGet network
Shipments
/shipmentsCreate shipment
/shipmentsList shipments
/shipments/:idGet shipment
AI Characters
/stores/:store_id/charactersList store AI characters
/stores/:store_id/charactersCreate store AI character
/characters/:character_idPatch AI character
/charactersList account AI characters
Drivers
/driversGet driver profile
/drivers/update-licensesUpdate driver licenses
/drivers/locationReport driver location
/drivers/shipmentsList assigned shipments
/drivers/shipments/:id/acceptAccept assigned shipment
/drivers/shipments/:id/rejectReject assigned shipment
/drivers/shipments/:id/completeComplete shipment
Wallet
/walletGet wallet
/walletCreate wallet
AFA Parity
/afasCreate AFA / OTP flow for S2S parity use cases
S2S WebSocket APIs
Connect to wss://api.niyantha.in/ws and authenticate with auth.login using authType: "s2s". After auth.success, use the same message types as the normal account WS API.
Account Profile
account.getaccount.updateaccount.logoutStores
store.createstore.fetchstore.getstore.updatestore.status.updatestore.attachaccount.stores.fetchaccount.store.getProducts
product.createproduct.updateproduct.getproduct.listaccount.store.products.createaccount.store.products.listaccount.store.products.getaccount.store.products.updateOrders
account.orders.fetchaccount.store.orders.fetchaccount.order.getaccount.store.order.getorder.acceptorder.rejectorder.preparingorder.preparedorder.pickedorder.deliveredLocations
location.createlocation.fetchlocation.searchlocation.getlocation.updateaccount.location.estimateaccount.location.address.coordinatesaccount.location.coordinates.addressFiles
account.files.createaccount.files.getfile.stream.startfile.stream.completeReviews
account.reviews.createaccount.reviews.updateaccount.reviews.listaccount.reviews.getaccount.review.replies.listaccount.review.like.addaccount.review.like.removestore.reviews.liststore.reviews.getstore.review.replies.listNetworks
account.network.createaccount.network.updateaccount.network.fetchaccount.network.getaccount.network.vehicle.requestaccount.network.vehicle.request.reviewaccount.network.vehicle.attachaccount.network.vehicles.listVehicles
account.vehicle.createaccount.vehicle.getaccount.vehicle.fetchShipments
account.shipment.createaccount.shipment.fetchaccount.shipment.getAI Characters
ai.threads.listai.threads.createai.threads.getai.thread.sendai.thread.send.streamnitha.thread.send.streamDrivers
account.driver.shipments.pending.fetchNotes
- 1S2S keys are scoped to an account and inherit store ownership checks.
- 2If you include
metadata.storeIdduring WS auth, the socket also attaches that store identity when it exists and belongs to the account. - 3Expiring a key immediately revokes access for both REST and WS.
- 4The integration surface is a stable, production contract. Platform updates are auto-deployed without breaking existing API clients.
Need Help Launching on Niyantha?
Build on api.niyantha.in using this guide as the production contract for your backend integration.