EndpointsBilling

Billing

Function-calling namespace: billing

  • Base URL: https://api.aivida.in
  • Engine endpoint: POST /api
  • Auth: Stack token middleware enabled in optional mode.
  • Send token in header: x-stack-access-token: <access_token> (or Authorization: Bearer <access_token>).
  • In optional mode: no token is allowed; invalid token is rejected with 401.

applyDiscount

Source: backend/endpoints/billing/apply-discount

Input Fields

FieldTypeRequiredConstraints
stackTeamIdstringNo-
organizationIdstringNo-
invoiceIdstringYes-
discountnumberYes-
discountReasonstringNo-

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

FieldTypeRequiredConstraints
organizationIdstringYes-
patientIdstringYes-
billTypestringNo-
descriptionstringNo-
lineItemsarray<object>No-
notesstringNo-
appointmentIdstringNo-
admissionIdstringNo-
bloodRequestIdstringNo-
doctorIdstringNo-
paymentobjectNonullable

Nested Field Structures

lineItems item

FieldTypeRequiredConstraints
descriptionstringYes-
quantityintegerNo-
unitPricenumberNo-
totalnumberNo-
productIdstringNo-

payment

FieldTypeRequiredConstraints
amountnumberNo-
paymentMethodstringNo-
transactionIdstringNo-
notesstringNo-

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

FieldTypeRequiredConstraints
organizationIdstringYes-
idstringYes-
kindstringNo-
filterstringNo-

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

FieldTypeRequiredConstraints
organizationIdstringYes-

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

FieldTypeRequiredConstraints
organizationIdstringYes-
idstringYes-
sourcestringYes-

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

FieldTypeRequiredConstraints
organizationIdstringYes-
pageintegerNo-
pageSizeintegerNo-
searchstringNo-
filterstringYes-
paymentStatusstringNopaid or unpaid; aliases: pending, success
statusstringNoBackward-compatible alias for paymentStatus
tabstringNoBackward-compatible alias for paymentStatus
statusesarray<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 with paymentStatus: "paid".
  • Unpaid tab: send filter: "unpaid" or send a category filter with paymentStatus: "unpaid".
  • Existing category filters still work: consultations, discharges, bloodRequests, labTest, pharmacy, other.
  • Existing statuses payload still works for invoice status filtering.

Backend Supported Filters

FieldSupported ValuesDescription
filterpaid, unpaidBilling management tab filters across all billing buckets.
filterconsultations, consultancyConsultation billing rows.
filterdischarges, dischargeDischarge billing rows.
filterbloodRequests, blood, bloodBankBlood bank billing rows.
filterlabTest, labLab invoice rows.
filterpharmacyPharmacy invoice rows.
filterotherOther invoice rows.
paymentStatus, status, tabpaid, success, successful, waivedPaid rows.
paymentStatus, status, tabunpaid, pending, not_paid, due, overdue, partial, partially_paidUnpaid rows.
statuses[]pending, paid, partially_paid, cancelled, overdueExisting 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

FieldTypeRequiredConstraints
organizationIdstringYes-
pageintegerNo-
pageSizeintegerNo-
searchstringNo-
filterstringNo-

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

FieldTypeRequiredConstraints
organizationIdstringYes-
searchstringNo-
pageintegerNo-
pageSizeintegerNo-
paymentMethodstringNocash, card, upi; all returns all methods
methodstringNoBackward-compatible alias for paymentMethod
tabstringNoBackward-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

FieldSupported ValuesDescription
paymentMethod, method, taball, all_payments, paymentsReturn all payment methods.
paymentMethod, method, tabcashReturn cash payments.
paymentMethod, method, tabcard, credit_card, debit_cardReturn card payments.
paymentMethod, method, tabupiReturn UPI payments.
paymentMethod, method, tabonline, razorpayReturn 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

FieldTypeRequiredConstraints
organizationIdstringYes-
invoiceIdstringYes-
amountnumberNo-
paymentMethodstringNo-
partialPaymentbooleanNo-
freeTreatmentbooleanNo-
transactionIdstringNo-
notesstringNo-
admissionIdstringNo-
createdByStackUserIdstringNo-
completeDischargebooleanNo-

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

FieldTypeRequiredConstraints
organizationIdstringYes-
emailsarray<string>Yesmin: 1
formatstringYes-
filenamestringNo-
contentBase64stringYes-
reportTypestringNo-
dateRangestringNo-

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": {} }