Nano Store - Ecommerce Docs
Developer Resourcesb2b-second-inventory

B2B Second Inventory API Reference

Endpoint reference for the bb phase 1 admin API — roles, permissions, staff, customers and audit — with contracts and error codes.

B2B Second Inventory (bb) — API Reference

Audience: Admin engineers integrating with the bb phase 1 backend. Phase 1 has no storefront or public endpoint.

All endpoints are prefixed with /api, need a JWT, and need the listed permission. Superadmin passes every permission check. Reads are throttled with RATE_LIMITS.ADMIN_READ (30 per 60 s per IP) and writes with RATE_LIMITS.ADMIN_WRITE (10 per 60 s per IP).

Each POST that creates a record requires an Idempotency-Key header; without it the response is 400 IDEMPOTENCY_KEY_REQUIRED.


Route Surfaces

SurfaceBase PathAuth
Roles/api/admin/bb/rolesJWT + BB_Roles_*
Permissions/api/admin/bb/permissionsJWT + BB_Roles_READ
Staff/api/admin/bb/staffJWT + BB_Staff_*
Customers/api/admin/bb/customersJWT + BB_Customers_*
Audit/api/admin/bb/auditJWT + BB_Audit_READ

Permission codes are BB_<Module>_<ACTION>. BB_Roles and BB_Staff cannot be assigned to a bb role, so only superadmin reaches those surfaces.

Endpoint Reference

Roles

MethodPathAuthDescription
GET/api/admin/bb/rolesBB_Roles_READList bb roles. Query: search. Not paginated; capped at 100
GET/api/admin/bb/roles/:publicIdBB_Roles_READOne role with its permission codes
POST/api/admin/bb/rolesBB_Roles_CREATECreate a role. Needs Idempotency-Key. Returns 201
PATCH/api/admin/bb/roles/:publicIdBB_Roles_UPDATERename or re-describe
PUT/api/admin/bb/roles/:publicId/permissionsBB_Roles_UPDATEReplace the full permission code set
DELETE/api/admin/bb/roles/:publicIdBB_Roles_DELETEDelete a role no staff member holds

Permissions

MethodPathAuthDescription
GET/api/admin/bb/permissionsBB_Roles_READAssignable codes grouped by module

Staff

MethodPathAuthDescription
GET/api/admin/bb/staffBB_Staff_READPaginated list. Query: page, size, search, sort, order
GET/api/admin/bb/staff/:idBB_Staff_READOne staff member
POST/api/admin/bb/staffBB_Staff_CREATECreate. Needs Idempotency-Key. Returns 201
PATCH/api/admin/bb/staff/:idBB_Staff_UPDATEUpdate profile or role (banned included)
DELETE/api/admin/bb/staff/:idBB_Staff_DELETEBan. Body: reason
POST/api/admin/bb/staff/:id/unbanBB_Staff_UPDATEUnban. Returns 200

Customers

MethodPathAuthDescription
GET/api/admin/bb/customersBB_Customers_READPaginated list of live customers
GET/api/admin/bb/customers/deletedBB_Customers_RESTOREPaginated list of soft-deleted customers
GET/api/admin/bb/customers/:publicIdBB_Customers_READOne live customer
POST/api/admin/bb/customersBB_Customers_CREATECreate. Needs Idempotency-Key. Returns 201
PATCH/api/admin/bb/customers/:publicIdBB_Customers_UPDATEUpdate; null clears a field
DELETE/api/admin/bb/customers/:publicIdBB_Customers_DELETESoft delete. Returns 200 with the customer
POST/api/admin/bb/customers/:publicId/restoreBB_Customers_RESTORERestore. Returns 200 with the customer

Audit

MethodPathAuthDescription
GET/api/admin/bb/auditBB_Audit_READCursor list, newest first
GET/api/admin/bb/audit/:publicIdBB_Audit_READOne audit row

Query Parameters

EndpointParameterRule
Staff listpageInteger, min 1, default 1
Staff listsizeInteger 1 to 100, default 20
Staff listsearchMax 100 characters
Staff listsortupdatedAt (default), createdAt, name, email
Staff listorderasc, desc (default)
Customer listpage, size, search, orderAs staff. search matches name, phone, email and company name
Customer listsortupdatedAt (default), createdAt, name
Customer liststatusactive, disabled
Deleted customerspage, size, searchAs above. Order is fixed: deleted_at descending, then id descending
Audit listlimitDefault 20, max 100
Audit listbefore_seqReturn rows with id below this; pass the previous nextCursor
Audit listentityTyperole, staff, customer
Audit listentityPublicId, actorIdUUID
Audit listactionPattern ^bb\.[a-z_]+\.[a-z_]+$, max 64 characters, for example bb.customer.update
Audit listfrom, toInclusive ISO 8601 with a timezone offset, for example 2026-10-30T00:00:00Z

An unknown query key, size over 100, an unknown sort, or ?pagination=false on a customer list is 400.


Key Contracts

POST /api/admin/bb/roles

Header: Idempotency-Key: 5d0c6c52-2b1e-4a1a-9f43-6c1d9a3e8b10

Request:

{
  "name": "Sales Desk",
  "description": "Handles B2B customers",
  "permissionCodes": ["BB_Customers_READ", "BB_Customers_CREATE"]
}

name is 1 to 100 characters. description is up to 500. permissionCodes holds up to 50 unique assignable codes.

Response 201:

{
  "message": "Bb role created successfully",
  "errorCode": null,
  "data": {
    "publicId": "0193a5c0-6d6c-7b0e-8a39-1f2f6f7a9c11",
    "name": "Sales Desk",
    "description": "Handles B2B customers",
    "staffCount": 0,
    "permissions": ["BB_Customers_CREATE", "BB_Customers_READ"]
  }
}

Role list returns data as { "roles": [ ...without permissions ], "totalCount": 1 }.

PUT /api/admin/bb/roles/:publicId/permissions

Request ([] removes every code):

{
  "permissionCodes": ["BB_Customers_READ", "BB_Audit_READ"]
}

Response 200 is the same role shape as above, with permissions sorted ascending.

Rejected code response, 400:

{
  "message": "These permission codes cannot be assigned to a bb role.",
  "errorCode": "BB_PERMISSION_NOT_ASSIGNABLE",
  "details": { "codes": ["BB_Staff_READ"] }
}

GET /api/admin/bb/permissions

{
  "message": "Bb permissions fetched successfully",
  "errorCode": null,
  "data": {
    "BB_Audit": [
      { "code": "BB_Audit_READ", "module": "BB_Audit", "action": "READ", "description": null }
    ],
    "BB_Customers": [
      { "code": "BB_Customers_READ", "module": "BB_Customers", "action": "READ", "description": null }
    ]
  }
}

Only BB_Audit and BB_Customers modules appear. data is {} when none are synced. The description values shown are illustrative.

POST /api/admin/bb/staff

Header: Idempotency-Key: 8e0a1b9c-3f41-4d7b-a0a5-52c7e9d4f3a2

{
  "name": "Asha Rai",
  "email": "asha@example.com",
  "password": "Str0ngPassw0rd",
  "phone": "+9779800000000",
  "rolePublicId": "0193a5c0-6d6c-7b0e-8a39-1f2f6f7a9c11"
}

name is 2 to 100 characters. password is 8 to 128 characters with an uppercase letter, a lowercase letter and a digit. phone is optional E.164. rolePublicId must be a bb role.

Response 201:

{
  "message": "Bb staff created successfully",
  "errorCode": null,
  "data": { "id": "0193a5c4-0a11-7c3d-b6d1-8e5f2a4c7b90" }
}

GET /api/admin/bb/staff/:id

{
  "message": "Bb staff fetched successfully",
  "errorCode": null,
  "data": {
    "id": "0193a5c4-0a11-7c3d-b6d1-8e5f2a4c7b90",
    "name": "Asha Rai",
    "email": "asha@example.com",
    "phone": "+9779800000000",
    "image": null,
    "banned": false,
    "banReason": null,
    "role": { "publicId": "0193a5c0-6d6c-7b0e-8a39-1f2f6f7a9c11", "name": "Sales Desk" },
    "createdAt": "2026-10-30T09:12:44.000Z",
    "updatedAt": "2026-10-30T09:12:44.000Z"
  }
}

The list endpoint returns an array of this object plus count, currentPage and totalPage.

PATCH /api/admin/bb/staff/:id

All fields optional. phone and image accept null to clear. image is up to 2048 characters.

{
  "name": "Asha K. Rai",
  "phone": null,
  "rolePublicId": "0193a5c0-6d6c-7b0e-8a39-1f2f6f7a9c11"
}

DELETE /api/admin/bb/staff/:id (ban)

{ "reason": "Left the company" }
{
  "message": "Bb staff banned successfully",
  "errorCode": null
}

reason is 1 to 500 characters.

POST /api/admin/bb/customers

Header: Idempotency-Key: 2a7c4e10-91b3-4f1d-8c55-7d0b6a1e3f44

{
  "name": "Himal Traders",
  "phone": "9841234567",
  "email": "Orders@Himal.example",
  "companyName": "Himal Traders Pvt. Ltd.",
  "address": "Kathmandu",
  "panVatNumber": "123456789",
  "notes": "Net 30 terms",
  "status": "active"
}

Every field is optional, but one of name, phone, companyName is required. Blank strings become null. phone is normalised to E.164 (+9779841234567 here) and email is lower-cased.

Response 201:

{
  "message": "Bb customer created successfully",
  "errorCode": null,
  "data": { "publicId": "0193a5c8-2d4e-7f10-9a6b-3c8d1e5f7a20" }
}

GET /api/admin/bb/customers/:publicId

{
  "message": "Bb customer fetched successfully",
  "errorCode": null,
  "data": {
    "publicId": "0193a5c8-2d4e-7f10-9a6b-3c8d1e5f7a20",
    "name": "Himal Traders",
    "phone": "+9779841234567",
    "email": "orders@himal.example",
    "companyName": "Himal Traders Pvt. Ltd.",
    "address": "Kathmandu",
    "panVatNumber": "123456789",
    "notes": "Net 30 terms",
    "status": "active",
    "createdAt": "2026-10-30T09:20:01.000Z",
    "updatedAt": "2026-10-30T09:20:01.000Z",
    "deletedAt": null
  }
}

PATCH /api/admin/bb/customers/:publicId

An omitted key is left unchanged; null clears it. status cannot be null.

{ "notes": null, "status": "disabled" }

POST /api/admin/bb/customers/:publicId/restore

Body is optional. Use the flags after a 409 to restore without the contested value.

{ "clearPhone": true, "clearEmail": false }

Phone conflict, 409:

{
  "message": "...",
  "errorCode": "BB_CUSTOMER_PHONE_TAKEN",
  "details": {
    "field": "phone",
    "conflictingPublicId": "0193a5c9-7a10-7e22-8b13-4d6e0f2a9c33"
  }
}

The message text is not a contract; branch on errorCode.

GET /api/admin/bb/audit

Example: GET /api/admin/bb/audit?entityType=customer&limit=2

{
  "message": "Bb audit fetched successfully",
  "errorCode": null,
  "data": [
    {
      "publicId": "0193a5ca-1b2c-7d3e-8f40-5a6b7c8d9e01",
      "createdAt": "2026-10-30T09:25:10.000Z",
      "actor": {
        "id": "0193a5b0-0000-7000-8000-000000000001",
        "name": "Super Admin",
        "role": "superadmin"
      },
      "action": "bb.customer.update",
      "entityType": "customer",
      "entityPublicId": "0193a5c8-2d4e-7f10-9a6b-3c8d1e5f7a20",
      "summary": "...",
      "changes": [
        { "field": "status", "changed": true, "before": "active", "after": "disabled" },
        { "field": "notes", "changed": true }
      ]
    }
  ],
  "nextCursor": "42"
}

Pass nextCursor back as before_seq for the next page. nextCursor is null on the last page. The response never carries the integer id or the client IP. summary is free text and is shown as "..." here.


Error Reference

CodeHTTPEndpointMeaning
BB_ROLE_NOT_FOUND404Role get, update, permissions, deleteRole is missing or is a retail role
BB_ROLE_NOT_FOUND400Staff create, staff updaterolePublicId is missing or is a retail role
BB_STAFF_NOT_FOUND404Staff get, update, ban, unbanMissing, or a retail admin
BB_PERMISSION_NOT_ASSIGNABLE400Role create, set permissionsCode is not BB_Audit_* or BB_Customers_*, or is not synced; see details.codes
ROLE_NAME_RESERVED403Role create, updatesuperadmin, admin or customer
ROLE_NAME_ALREADY_EXISTS409Role create, updateName in use
ROLE_SELF_TARGET_FORBIDDEN403Role update, set permissions, deleteActor holds this role
ROLE_IN_USE409Role deleteAt least one staff member holds it
TEAM_EMAIL_ALREADY_IN_USE409Staff createEmail taken
TEAM_PHONE_ALREADY_IN_USE409Staff create, updatePhone taken
TEAM_SELF_ROLE_CHANGE_FORBIDDEN403Staff updateActor changed their own role
TEAM_SELF_BAN_FORBIDDEN403Staff banActor is the target
TEAM_SUPERADMIN_PROTECTED403Staff banTarget is superadmin
BB_CUSTOMER_NOT_FOUND404Customer get, update, delete, restoreMissing, or not in the required live/deleted state
BB_CUSTOMER_IDENTITY_REQUIRED400Customer create, updateNo name, phone or company would remain
BB_CUSTOMER_PHONE_INVALID400Customer create, updatePhone is not a valid number
BB_CUSTOMER_EMAIL_INVALID400Customer create, updateEmail fails the email CHECK
BB_CUSTOMER_FIELD_INVALID400Customer create, updateAnother field CHECK failed
BB_CUSTOMER_PHONE_TAKEN409Customer create, update, restoreA live customer holds the phone
BB_CUSTOMER_EMAIL_TAKEN409Customer create, update, restoreA live customer holds the email
BB_AUDIT_NOT_FOUND404Audit getUnknown publicId
BB_AUDIT_RANGE_INVALID400Audit listfrom is after to
PAGINATION_LIMIT_INVALID / PAGINATION_LIMIT_TOO_LARGE / PAGINATION_CURSOR_INVALID422Audit listBad limit or before_seq
IDEMPOTENCY_KEY_REQUIRED400The three create routesHeader missing
ROLE_PERMISSION_BB_CODE_NOT_ALLOWED400Retail role-permissions writeA BB_* code was sent to a retail role
ROLE_NOT_FOUND / TEAM_USER_NOT_FOUND / TEAM_ROLE_NOT_FOUND404 / 404 / 400Retail role, team routesA bb role or bb staff member was addressed through a retail route

A path parameter that is not a UUID is 400 from ParseUUIDPipe.


Guardrail Summary

  • Never send a BB_* code to a retail role endpoint. It is refused.
  • Never address a bb role or bb staff member through /api/roles or /api/team. They answer as not found.
  • Do not offer BB_Roles_* or BB_Staff_* in a bb role editor. Use GET /api/admin/bb/permissions as the only source of assignable codes.
  • Send a fresh Idempotency-Key per create intent, and reuse it only when retrying that same request.
  • Treat PUT .../permissions as a full replace, not a merge.
  • Page the audit list with nextCursor; do not compute offsets.
  • Do not rely on audit changes carrying values. Only status, name, description and banned do.
  • Branch on errorCode, never on message.

See Also