Nano Store - Ecommerce Docs
Developer Resourcesb2b-second-inventory

B2B Second Inventory Reports API Reference

Endpoint reference for the bb phase 6 admin report API — summary reads, the table catalogue and runner, and CSV or XLSX export jobs — with permissions, throttles, limits and error codes.

B2B Second Inventory (bb) — Reports API Reference

Audience: Admin engineers integrating with the bb phase 6 backend. Reports are read-only views over orders, refunds, returns, stock and customers. The only write is queuing, cancelling and downloading an export.

All endpoints are prefixed with /api, need a JWT, and need BB_Reports_READ. Superadmin passes every permission check. Every JSON response uses the ResponseDto envelope (message, errorCode, data); a download streams the file.

Base path: /api/admin/bb/reports. Every :publicId is a UUID (a malformed one is a 400).

Routes

Every route checks BB_Reports_READ and nothing else, including export queue and cancel. No other BB_Reports_ code is checked by any route.

Method and pathThrottleWhat it returns
GET overview60 per 60 s, per user (ADMIN_ANALYTICS_READ)The overview figures
GET kpissameKPI figures for the window and its comparison window
GET trendssameOne row per day of the window
GET payment-methodssameRevenue by payment method
GET top-productssameTop products; limit 1 to 20 (default 5), sortBy default units
GET refunds-returnssameRefund and return figures
GET tablessameThe report catalogue; takes no query
GET tables/:reportIdsameOne report's rows; sortBy, sortDirection, page, size
POST exports5 per 3600 s, per user (ADMIN_ANALYTICS_EXPORT)Queues a file; needs Idempotency-Key
POST exports/:publicId/cancel10 per 60 s, per IP (ADMIN_WRITE)Cancels the caller's own queued or running export
GET exports60 per 60 s, per userThe caller's own exports; page (max 1000, default 1), size (max 100, default 20)
GET exports/:publicIdsameOne of the caller's own exports
GET exports/:publicId/downloadsameThe file, Cache-Control: no-store

The summary routes take period, from and to (BbReportPeriodQueryDto). With no query the window is last_30_days. from and to are YYYY-MM-DD in Asia/Kathmandu, to is inclusive and may not be later than today, and both are allowed only with period=custom. A query key the DTO does not list answers 400.

Create an export

POST /api/admin/bb/reports/exports queues a CSV or XLSX of one report. Exports reuse the bb_catalog queue as bb_catalog_job rows with entity = 'report'.

Request, with the header Idempotency-Key: 5b0c3f7e-6a1d-4f0e-9d52-2c7f1a9e4b10:

{
  "reportId": "orders_list",
  "format": "xlsx",
  "period": "custom",
  "from": "2026-10-01",
  "to": "2026-10-31",
  "sortBy": "placedAt",
  "sortDirection": "desc"
}

Only reportId and format are required. A point-in-time report ignores the period and stores null period keys.

Response, 201:

{
  "message": "Bb report export queued",
  "errorCode": null,
  "data": {
    "publicId": "019a2f10-7c1e-7a3b-9c11-3f2a1b4c5d6e",
    "reportId": "orders_list",
    "reportTitle": "Orders",
    "format": "xlsx",
    "status": "queued",
    "periodFrom": "2026-10-01",
    "periodTo": "2026-10-31",
    "requestedAt": "2026-11-01T04:00:00.000Z",
    "completedAt": null,
    "expiresAt": null,
    "rowCount": null,
    "error": null
  }
}

The envelope above shows the shape, built from ResponseDto and BbReportExport; the example values are illustrative. completedAt is set only on a completed export. expiresAt is completedAt plus 48 hours. error is set only on a failed export and is one of a closed set of sentences, never a raw error.

Idempotency

SituationAnswer
Same key, same body, againThe same job is returned
Same key, different body409 IDEMPOTENCY_KEY_CONFLICT
No key400 IDEMPOTENCY_KEY_REQUIRED

Download

GET exports/:publicId/download answers 200 with the file as text/csv or the XLSX type application/vnd.openxmlformats-officedocument.spreadsheetml.sheet. Another admin's export, and a catalog job's id, are both 404 BB_JOB_NOT_FOUND. A job with no finished file is 409 BB_JOB_RESULT_NOT_AVAILABLE. A file past 48 hours is 410, whether or not the daily sweep has deleted it yet.

Limits

LimitValueSource
Longest window366 * 3 daysBB_REPORT_MAX_PERIOD_DAYS
Export formatscsv, xlsxBB_REPORT_EXPORT_FORMATS
XLSX rows10,000BB_REPORT_EXCEL_EXPORT_MAX_ROWS
Export rows, any format50,000BB_CATALOG_EXPORT_MAX_ROWS
File retention48 hours from finished_atBB_REPORT_EXPORT_RETENTION_MS
Active export or import jobs per admin2BB_CATALOG_JOB_MAX_ACTIVE_PER_ADMIN
Read statement budget10 s per statementBB_REPORT_READ_STATEMENT_TIMEOUT_MS
Export worker statement budget60 sBB_REPORT_WORKER_STATEMENT_TIMEOUT_MS
Concurrent read snapshots per process3, then a 5 s wait for a permitBB_REPORT_MAX_CONCURRENT_SNAPSHOTS, BB_REPORT_PERMIT_WAIT_MS

The row caps are enforced by the worker, not at queue time. A report with more rows than the cap ends the job failed with BB_JOB_EXPORT_TOO_LARGE (the worker raises it as a permanent error) and the export's error carries a closed sentence naming the cap.

The active-job cap counts catalog and inventory jobs too, so its message says "export or import jobs".

Error codes

From common/types/error-codes.ts and the controller's @ApiResponse list.

StatusCodeWhen
400BB_REPORT_PERIOD_INVALIDperiod, from or to is unknown, not a calendar date, or past today in Asia/Kathmandu
400BB_REPORT_PERIOD_TOO_LONGA custom range longer than the window limit
400BB_REPORT_SORT_INVALIDsortBy is not a key the report sorts by. A bad sortDirection gets the validation pipe's generic 400
400BB_REPORT_NOT_FOUNDAn export names a report id that does not exist. On a read route the same code is a 404
400IDEMPOTENCY_KEY_REQUIREDExport queued without the header
403BB_Reports_READ is missing
404BB_JOB_NOT_FOUNDExport not found, or not the caller's
409BB_JOB_TOO_MANY_ACTIVEA third active job for this admin
409BB_JOB_NOT_CANCELLABLECancel on a finished export
409BB_JOB_RESULT_NOT_AVAILABLEDownload before a file exists
409BB_CATALOG_BUSYQueue or cancel while the catalog is busy
409IDEMPOTENCY_KEY_CONFLICTSame key, different body
410BB_JOB_RESULT_GONEDownload past retention
429Rate limit exceeded
503BB_REPORT_TIMEOUTA read ran out of time, or waited too long for a snapshot permit

Guardrail summary

  • BB_Reports_READ shows buyer names and what each buyer spent, with or without BB_Customers_READ. Grant it on purpose.
  • An export is the caller's own. Cancel and download both treat another admin's export as not found.
  • A CSV cell that starts with =, +, -, @, TAB, CR, LF or ' gets a leading '. A negative money cell therefore prints as the text '-1000.01. This is a known limit.
  • An export file is deleted 48 hours after it finishes; the job row stays.
  • Money is bigint paisa. The rules are in Reports backend.

See Also