API reference › Finance › Provider expenses

Preview calculated provider expense amount

POST /v1/finance/provider-expenses/calculate-preview

Scope
finance:read
Roles
admin, service-provider, scheduler

Read-only. Computes the suggested expense amount from the work item's expense settings and optional quantity or submitted cost, using the same calculation as submit. Does not persist any record. serviceProviderId is optional for category-first preview; when quantity or provider cannot be resolved, returns partial metadata (rate, cap, basis) with calculatedAmount 0 and quantityReason indicating what is still needed. For per_day, quantity may be omitted and is derived as whole billable days from work-item scheduled hours (under 24h = 1 day; 24h+ = ceil(hours/24)); manual quantity must be a positive whole number. For per_unit with unit mile, quantity may be omitted when serviceProviderId is sent and is derived as round-trip mileage. For per_unit use/session, quantity is required for full calculation. For flat_amount, quantity defaults to 1 when omitted. For percentage, amount is required for full calculation; without amount returns partial preview with calculatedAmount 0.

Parameters

None of its own.

Every call also sends Authorization and X-Tenant-ID; see Getting started.

Request body required

FieldTypeDescription
workItemIdstring or null

Assignment (ASG-...) or shift id. Omit in add mode to resolve category from reimbursable_expenses catalog only.

Example ASG-12345.

reimbursableExpenseIdinteger or null

Reimbursable expense category id from settings; required unless sourceReimbursableExpense is sent

Example 10.

sourceReimbursableExpenseobject

Custom-from-category path.

sourceReimbursableExpense.idinteger or string

Example 1.

sourceReimbursableExpense.labelstring or null

Example Example.

serviceProviderIdstring or null

Service provider user id; optional for category-first partial preview, required for mileage auto-quantity

Example USR-67890.

quantitynumber (float) or null

Miles, days, uses, etc. Optional when auto-derived or for partial preview

Example 50.

amountnumber (float) or null

Submitted receipt/cost; required for full percentage calculation

Example 120.

Example

JSON
{
  "workItemId": "ASG-12345",
  "reimbursableExpenseId": 10,
  "sourceReimbursableExpense": {
    "id": 1,
    "label": "Example"
  },
  "serviceProviderId": "USR-67890",
  "quantity": 50,
  "amount": 120
}

Example request

Shell
curl -X POST "https://api.fetchfido.ai/v1/finance/provider-expenses/calculate-preview" \
  -H "Authorization: Bearer $FIDO_API_KEY" \
  -H "X-Tenant-ID: $FIDO_TENANT_ID" \
  -H "Content-Type: application/json" \
  -d '{"workItemId":"ASG-12345","reimbursableExpenseId":10,"sourceReimbursableExpense":{"id":1,"label":"Example"},"serviceProviderId":"USR-67890","quantity":50,"amount":120}'

Try it

Responses

200 Calculation preview

Calculation preview.

JSON
{
  "success": true,
  "message": "Calculation preview.",
  "data": {
    "calculatedAmount": 33.5,
    "suggestedExpense": 33.5,
    "reimbursementBasis": "per_unit",
    "unit": "mile",
    "unitRate": 0.67,
    "quantity": 50,
    "amount": 10,
    "quantityReason": "not_applicable",
    "servicePayBase": 120,
    "capped": false,
    "maximumCap": 100,
    "reimbursableExpenseId": 10,
    "name": "Mileage",
    "expenseType": "travel",
    "billTo": "organization",
    "isReceiptRequired": true
  }
}
Response fields (19)
FieldTypeDescription
successboolean

Example true.

messagestring

Example Calculation preview..

dataobject
data.calculatedAmountnumber (float)

Example 33.5.

data.suggestedExpensenumber (float)

Same as calculatedAmount; suggested final amount if submit omits expense override

Example 33.5.

data.reimbursementBasisstring

One of: per_unit, per_day, flat_amount, percentage. Example per_unit.

data.unitstring or null

null for flat_amount and percentage; mile/day/use/session for other bases

Example mile.

data.unitRatenumber (float)

Example 0.67.

data.quantitynumber (float) or null

Defaults to 1 for per_unit/per_day when omitted and not auto-resolved; null for flat_amount and percentage

Example 50.

data.amountnumber (float) or null

Percentage only: category rate (same as unitRate). Request amount is receipt/cost input.

Example 10.

data.quantityReasonstring or null

Set for percentage without receipt (not_applicable); null when quantity was resolved or defaulted

Example not_applicable.

data.servicePayBasenumber (float) or null

For percentage basis: submitted receipt/cost used in formula (same column as persist service_pay_base_used)

Example 120.

data.cappedboolean

True when maximum_reimbursement_cap clamped a calculated non-percentage line total; false for percentage (cap enforced on submit receipt only)

Example false.

data.maximumCapnumber (float) or null

Example 100.

data.reimbursableExpenseIdinteger

Category template id

Example 10.

data.namestring

Category name from snapshot or catalog

Example Mileage.

data.expenseTypestring or null

Category expense type from snapshot or catalog

Example travel.

data.billTostring or null

Submit-style bill-to; from category snapshot

One of: organization, client. Example organization.

data.isReceiptRequiredboolean

Whether receipt is required for this category

Example true.

401 Not signed in

Unauthorized

JSON
{
  "success": false,
  "message": "Invalid API key. Org and user tier keys must send an X-Tenant-ID header naming the organization the key was issued for.",
  "errors": null,
  "code": "API_KEY_MISSING"
}
Response fields (4)
FieldTypeDescription
successboolean

Example false.

messagestring

Example Invalid API key. Org and user tier keys must send an X-Tenant-ID header naming the organization the key was issued for..

errorsany or null

Null on this status.

codestring

Machine-readable reason, for branching on in client code.

One of: API_KEY_MISSING, API_KEY_INVALID, API_KEY_EXPIRED. Example API_KEY_MISSING.

403 Not allowed

Scope, tenant, IP allow-list or RBAC check failed.

JSON
{
  "success": false,
  "message": "You don't have permission to access this endpoint. This API key is missing the 'finance:read' scope.",
  "errors": null,
  "code": ""
}
Response fields (4)
FieldTypeDescription
successboolean

Example false.

messagestring

Example You don't have permission to access this endpoint. This API key is missing the 'finance:read' scope..

errorsany or null

Null on this status.

codestring

Always empty on this status.

Example .

422 Validation failed

Validation error (request validation, category not found, category not attached to work item, invalid snapshot basis)

JSON
{
  "success": false,
  "message": "Expense category is not attached to this work item."
}
Response fields (2)
FieldTypeDescription
successboolean

Example false.

messagestring

Example Expense category is not attached to this work item..

429 Too many requests

Rate limit exceeded. See Retry-After.

JSON
{
  "success": false,
  "message": "You've exceeded this API key's rate limit of 120 requests per minute. Try again in 37 seconds.",
  "errors": null,
  "code": "RATE_LIMITED"
}
Response fields (4)
FieldTypeDescription
successboolean

Example false.

messagestring

Example You've exceeded this API key's rate limit of 120 requests per minute. Try again in 37 seconds..

errorsany or null

Null on this status.

codestring

Machine-readable reason, for branching on in client code.

One of: RATE_LIMITED. Example RATE_LIMITED.

500 Server error

Internal Server Error

JSON
{
  "success": false,
  "message": "Unable to calculate expense preview."
}
Response fields (2)
FieldTypeDescription
successboolean

Example false.

messagestring

Example Unable to calculate expense preview..