Billing
Function-calling namespace: billing
- Base URL:
https://api.aivida.in - Engine endpoint:
POST /api - Auth: Stack token middleware enabled in
optionalmode. - Send token in header:
x-stack-access-token: <access_token>(orAuthorization: Bearer <access_token>). - In
optionalmode: no token is allowed; invalid token is rejected with401.
applyDiscount
Source: backend/endpoints/billing/apply-discount
Input Fields
| Field | Type | Required | Constraints |
|---|---|---|---|
stackTeamId | string | No | - |
organizationId | string | No | - |
invoiceId | string | Yes | - |
discount | number | Yes | - |
discountReason | string | No | - |
Example Request
curl -X POST https://api.aivida.in/api \
-H "Content-Type: application/json" \
-H "x-stack-access-token: <access_token_optional>" \
-d '{
"namespace": "billing",
"apiName": "applyDiscount",
"data": {
"invoiceId": "invoice_123",
"discount": 1
}
}'Example Response
{ "status": "ok", "data": {} }createInvoice
Source: backend/endpoints/billing/create-invoice
Input Fields
| Field | Type | Required | Constraints |
|---|---|---|---|
organizationId | string | Yes | - |
patientId | string | Yes | - |
billType | string | No | - |
description | string | No | - |
lineItems | array<object> | No | - |
notes | string | No | - |
appointmentId | string | No | - |
admissionId | string | No | - |
bloodRequestId | string | No | - |
doctorId | string | No | - |
payment | object | No | nullable |
Nested Field Structures
lineItems item
| Field | Type | Required | Constraints |
|---|---|---|---|
description | string | Yes | - |
quantity | integer | No | - |
unitPrice | number | No | - |
total | number | No | - |
productId | string | No | - |
payment
| Field | Type | Required | Constraints |
|---|---|---|---|
amount | number | No | - |
paymentMethod | string | No | - |
transactionId | string | No | - |
notes | string | No | - |
Example Request
curl -X POST https://api.aivida.in/api \
-H "Content-Type: application/json" \
-H "x-stack-access-token: <access_token_optional>" \
-d '{
"namespace": "billing",
"apiName": "createInvoice",
"data": {
"organizationId": "org_123",
"patientId": "patient_123"
}
}'Example Response
{ "status": "ok", "data": {} }deleteRow
Source: backend/endpoints/billing/delete-row
Input Fields
| Field | Type | Required | Constraints |
|---|---|---|---|
organizationId | string | Yes | - |
id | string | Yes | - |
kind | string | No | - |
filter | string | No | - |
Example Request
curl -X POST https://api.aivida.in/api \
-H "Content-Type: application/json" \
-H "x-stack-access-token: <access_token_optional>" \
-d '{
"namespace": "billing",
"apiName": "deleteRow",
"data": {
"organizationId": "org_123",
"id": "id_123"
}
}'Example Response
{ "status": "ok", "data": {} }getDashboard
Source: backend/endpoints/billing/get-dashboard
Input Fields
| Field | Type | Required | Constraints |
|---|---|---|---|
organizationId | string | Yes | - |
Example Request
curl -X POST https://api.aivida.in/api \
-H "Content-Type: application/json" \
-H "x-stack-access-token: <access_token_optional>" \
-d '{
"namespace": "billing",
"apiName": "getDashboard",
"data": {
"organizationId": "org_123"
}
}'Example Response
{ "status": "ok", "data": {} }getDetail
Source: backend/endpoints/billing/get-detail
Input Fields
| Field | Type | Required | Constraints |
|---|---|---|---|
organizationId | string | Yes | - |
id | string | Yes | - |
source | string | Yes | - |
Example Request
curl -X POST https://api.aivida.in/api \
-H "Content-Type: application/json" \
-H "x-stack-access-token: <access_token_optional>" \
-d '{
"namespace": "billing",
"apiName": "getDetail",
"data": {
"organizationId": "org_123",
"id": "id_123",
"source": "value"
}
}'Example Response
{ "status": "ok", "data": {} }getTable
Source: backend/endpoints/billing/get-table
Input Fields
| Field | Type | Required | Constraints |
|---|---|---|---|
organizationId | string | Yes | - |
page | integer | No | - |
pageSize | integer | No | - |
search | string | No | - |
filter | string | Yes | - |
paymentStatus | string | No | paid or unpaid; aliases: pending, success |
status | string | No | Backward-compatible alias for paymentStatus |
tab | string | No | Backward-compatible alias for paymentStatus |
statuses | array<string> | No | - |
Billing Management Paid/Unpaid Tabs
The billing management page can use the same getTable API for the new two-tab UI.
- Paid tab: send
filter: "paid"or send a category filter withpaymentStatus: "paid". - Unpaid tab: send
filter: "unpaid"or send a category filter withpaymentStatus: "unpaid". - Existing category filters still work:
consultations,discharges,bloodRequests,labTest,pharmacy,other. - Existing
statusespayload still works for invoice status filtering.
Backend Supported Filters
| Field | Supported Values | Description |
|---|---|---|
filter | paid, unpaid | Billing management tab filters across all billing buckets. |
filter | consultations, consultancy | Consultation billing rows. |
filter | discharges, discharge | Discharge billing rows. |
filter | bloodRequests, blood, bloodBank | Blood bank billing rows. |
filter | labTest, lab | Lab invoice rows. |
filter | pharmacy | Pharmacy invoice rows. |
filter | other | Other invoice rows. |
paymentStatus, status, tab | paid, success, successful, waived | Paid rows. |
paymentStatus, status, tab | unpaid, pending, not_paid, due, overdue, partial, partially_paid | Unpaid rows. |
statuses[] | pending, paid, partially_paid, cancelled, overdue | Existing invoice status filter. |
Billing Management Request Body
{
"namespace": "billing",
"apiName": "getTable",
"data": {
"organizationId": "org_123",
"filter": "paid",
"page": 1,
"pageSize": 20,
"search": ""
}
}{
"namespace": "billing",
"apiName": "getTable",
"data": {
"organizationId": "org_123",
"filter": "unpaid",
"page": 1,
"pageSize": 20,
"search": ""
}
}Category-specific tab filtering is also supported:
{
"namespace": "billing",
"apiName": "getTable",
"data": {
"organizationId": "org_123",
"filter": "labTest",
"paymentStatus": "unpaid",
"page": 1,
"pageSize": 20
}
}Example Request
curl -X POST https://api.aivida.in/api \
-H "Content-Type: application/json" \
-H "x-stack-access-token: <access_token_optional>" \
-d '{
"namespace": "billing",
"apiName": "getTable",
"data": {
"organizationId": "org_123",
"filter": "paid",
"page": 1,
"pageSize": 20
}
}'Example Response
{
"success": true,
"statusCode": 200,
"message": "Request completed successfully",
"data": {
"consultations": [],
"consultationInvoices": [],
"discharges": [],
"dischargeInvoices": [],
"bloodRequests": [],
"labInvoices": [
{
"_id": "invoice_123",
"invoiceNumber": "INV-000610",
"status": "paid",
"subtotal": 1000,
"tax": 0,
"discount": 0,
"total": 1000,
"totalPaid": 1000,
"balance": 0,
"createdAt": 1782700000000,
"updatedAt": 1782700000000,
"notes": "Bill Type: lab_test",
"lineItems": [
{
"description": "Lab test",
"quantity": 1,
"unitPrice": 1000,
"total": 1000
}
],
"latestPaymentId": "payment_123",
"latestPaymentMethod": "cash",
"patient": {
"_id": "patient_123",
"fullName": "Ganesh",
"phone": "9999999999"
}
}
],
"otherInvoices": [],
"pharmacyInvoices": [],
"meta": {
"total": 1,
"page": 1,
"pageSize": 20,
"totalPages": 1,
"filter": "billingManagement",
"paymentStatus": "paid"
}
}
}getWorkbench
Source: backend/endpoints/billing/get-workbench
Input Fields
| Field | Type | Required | Constraints |
|---|---|---|---|
organizationId | string | Yes | - |
page | integer | No | - |
pageSize | integer | No | - |
search | string | No | - |
filter | string | No | - |
Example Request
curl -X POST https://api.aivida.in/api \
-H "Content-Type: application/json" \
-H "x-stack-access-token: <access_token_optional>" \
-d '{
"namespace": "billing",
"apiName": "getWorkbench",
"data": {
"organizationId": "org_123"
}
}'Example Response
{ "status": "ok", "data": {} }listPayments
Source: backend/endpoints/billing/list-payments
Input Fields
| Field | Type | Required | Constraints |
|---|---|---|---|
organizationId | string | Yes | - |
search | string | No | - |
page | integer | No | - |
pageSize | integer | No | - |
paymentMethod | string | No | cash, card, upi; all returns all methods |
method | string | No | Backward-compatible alias for paymentMethod |
tab | string | No | Backward-compatible alias for paymentMethod |
Payment Page Tabs
The payment page can use the same listPayments API for All Payments, Cash, Card, and UPI.
Each payment record is returned as a separate row. Multiple cash, card, UPI, or gateway transactions for the same patient or invoice are not collapsed. Use search with patient details, invoice number, payment ID, or source ID to show all matching transactions.
Backend Supported Payment Filters
| Field | Supported Values | Description |
|---|---|---|
paymentMethod, method, tab | all, all_payments, payments | Return all payment methods. |
paymentMethod, method, tab | cash | Return cash payments. |
paymentMethod, method, tab | card, credit_card, debit_card | Return card payments. |
paymentMethod, method, tab | upi | Return UPI payments. |
paymentMethod, method, tab | online, razorpay | Return online/gateway payments. |
{
"namespace": "billing",
"apiName": "listPayments",
"data": {
"organizationId": "org_123",
"tab": "all",
"page": 1,
"pageSize": 20,
"search": ""
}
}{
"namespace": "billing",
"apiName": "listPayments",
"data": {
"organizationId": "org_123",
"paymentMethod": "cash",
"page": 1,
"pageSize": 20,
"search": ""
}
}{
"namespace": "billing",
"apiName": "listPayments",
"data": {
"organizationId": "org_123",
"paymentMethod": "card",
"page": 1,
"pageSize": 20,
"search": ""
}
}{
"namespace": "billing",
"apiName": "listPayments",
"data": {
"organizationId": "org_123",
"paymentMethod": "upi",
"page": 1,
"pageSize": 20,
"search": ""
}
}Example Request
curl -X POST https://api.aivida.in/api \
-H "Content-Type: application/json" \
-H "x-stack-access-token: <access_token_optional>" \
-d '{
"namespace": "billing",
"apiName": "listPayments",
"data": {
"organizationId": "org_123",
"paymentMethod": "cash",
"page": 1,
"pageSize": 20
}
}'Example Response
{
"success": true,
"statusCode": 200,
"message": "Request completed successfully",
"data": [
{
"_id": "payment_123",
"amount": 1000,
"paymentMethod": "cash",
"status": "paid",
"createdAt": 1782700000000,
"source": "invoice",
"sourceId": "invoice_123",
"patientId": "patient_123",
"manualReferenceNumber": "CASH-610",
"patient": {
"_id": "patient_123",
"patientCode": "PAT-001",
"fullName": "Ganesh",
"phone": "9999999999"
},
"sourceInfo": {
"_id": "invoice_123",
"invoiceNumber": "INV-000610",
"total": 1000
}
},
{
"_id": "payment_124",
"amount": 1000,
"paymentMethod": "upi",
"status": "paid",
"createdAt": 1782690000000,
"source": "invoice",
"sourceId": "invoice_122",
"patientId": "patient_123",
"patient": {
"_id": "patient_123",
"patientCode": "PAT-001",
"fullName": "Ganesh",
"phone": "9999999999"
},
"sourceInfo": {
"_id": "invoice_122",
"invoiceNumber": "INV-000609",
"total": 1000
}
}
]
}recordPayment
Source: backend/endpoints/billing/record-payment
Input Fields
| Field | Type | Required | Constraints |
|---|---|---|---|
organizationId | string | Yes | - |
invoiceId | string | Yes | - |
amount | number | No | - |
paymentMethod | string | No | - |
partialPayment | boolean | No | - |
freeTreatment | boolean | No | - |
transactionId | string | No | - |
notes | string | No | - |
admissionId | string | No | - |
createdByStackUserId | string | No | - |
completeDischarge | boolean | No | - |
Example Request
curl -X POST https://api.aivida.in/api \
-H "Content-Type: application/json" \
-H "x-stack-access-token: <access_token_optional>" \
-d '{
"namespace": "billing",
"apiName": "recordPayment",
"data": {
"organizationId": "org_123",
"invoiceId": "invoice_123"
}
}'Example Response
{ "status": "ok", "data": {} }sendReport
Source: backend/endpoints/billing/send-report
Input Fields
| Field | Type | Required | Constraints |
|---|---|---|---|
organizationId | string | Yes | - |
emails | array<string> | Yes | min: 1 |
format | string | Yes | - |
filename | string | No | - |
contentBase64 | string | Yes | - |
reportType | string | No | - |
dateRange | string | No | - |
Example Request
curl -X POST https://api.aivida.in/api \
-H "Content-Type: application/json" \
-H "x-stack-access-token: <access_token_optional>" \
-d '{
"namespace": "billing",
"apiName": "sendReport",
"data": {
"organizationId": "org_123",
"emails": "user@example.com",
"format": "value",
"contentBase64": "value"
}
}'Example Response
{ "status": "ok", "data": {} }