API version 1.3.0 · openapi.yaml
API reference
Base URL https://api.valulog.com/v1. Get a free test key from your dashboard.
Example
curl https://api.valulog.com/v1/calculate \
-H "Authorization: Bearer $VALULOG_KEY" \
-H "Idempotency-Key: order-1042" \
-H "Content-Type: application/json" \
-d '{
"currency": "GBP",
"items": [
{ "id": "line-1", "sku": "TEE", "unit_price_cents": 2000, "quantity": 2 },
{ "id": "line-2", "sku": "MUG", "unit_price_cents": 1000, "quantity": 1 }
],
"discounts": [
{ "rule_id": "TENOFF", "type": "PERCENTAGE", "basis_points": 1000 }
]
}'The system of record for pricing, discounts, and audit-safe refunds. Valulog is not a payment processor and does not give tax advice: payments stay with your payment provider; Valulog records how prices, discounts and refunds were calculated.
Authentication
Every endpoint except /health needs an API key: Authorization: Bearer vl_live_… (live) or Bearer vl_test_… (sandbox). - The merchant is taken from the key. Do not send merchant_id; if you do, it must match the key's merchant or the request is refused (403). - Sandbox (test) and live data are separate: a test key never sees live data. - Records belonging to another merchant are reported as 404. - Invalid or revoked keys return 401. Live keys need a paid plan (403 PLAN_REQUIRED).
Rate limits
Per API key, per minute. Sandbox keys: 10. Starter: 60. Growth: 300. Every response carries X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset. If the limiter is unavailable the API refuses with 503 rather than letting unmetered requests through.
Monthly allowance
Calculations and refunds count towards a monthly allowance (UTC calendar month): Sandbox/test keys 1,000, Starter 25,000, Growth 250,000. Reads and idempotent replays are not counted. Mutations return X-Quota-Limit and X-Quota-Remaining; when the allowance is used up they return 429 QUOTA_EXCEEDED until the 1st of the next month or a plan upgrade.
Core Philosophy
- Immutable Snapshots: We do not recalculate refunds. We replay history.
- Integer Math: No floats. All values are minor currency units (cents/pence/yen).
- Idempotency First:
Idempotency-Keyheader is mandatory for all mutations.
Discount Rules
Rules are a discriminated union on the type field: - FIXED_AMOUNT → uses amount_cents - PERCENTAGE → uses basis_points (1000 = 10%) - BUY_X_GET_Y → uses buy_quantity, get_quantity, get_discount_basis_points
Every rule declares application_base: - ORIGINAL_SUBTOTAL — discount calculated on pre-discount value - REMAINING_BALANCE — discount cascades after previous rules - PER_LINE — applied independently per eligible line
Currency
All values are in minor units for the given currency: - GBP/USD/EUR: cents (exponent 2) - JPY/KRW: whole units (exponent 0) - KWD/BHD: fils (exponent 3)
The response includes currency_minor_unit_exponent so consumers know how to display.
Endpoints
- GET /health · Health check
- POST /calculate · Calculate allocations and freeze an immutable snapshot
- POST /refunds · Process idempotent refund against frozen snapshot
- GET /transactions/{transaction_id} · Retrieve frozen transaction with refund ledger
- GET /transactions/{transaction_id}/refunds · List refunds with cursor pagination
- GET /transactions/{transaction_id}/integrity · Verify snapshot hash integrity (audit endpoint)
GET/health
Health check
Public (no key). Reports whether the API, its database (postgres) and its rate-limit and idempotency store (redis) are reachable right now. Sent with Cache-Control: no-store. There is no separate status page and no uptime SLA; see https://valulog.com/status.
- 200 The API and all its dependencies are reachable
- 503 At least one dependency is not reachable; writes are refused with SERVICE_UNAVAILABLE
POST/calculate
Calculate allocations and freeze an immutable snapshot
| Parameter | In | Type | Notes |
|---|---|---|---|
| Idempotency-Key * | header | string | Unique per operation. Scoped to your merchant and environment. A UUID is recommended. |
Body: CalculationRequest
- 200 Snapshot frozen
- 400 Request validation failed
- 401 Missing, invalid or revoked API key
- 403 merchant_id does not match the key, or the plan does not allow live keys (PLAN_REQUIRED)
- 409 Key reused with different payload
- 429 Too many requests (`RATE_LIMITED`) or monthly allowance used (`QUOTA_EXCEEDED`)
- 503 A dependency is unavailable; retry after the Retry-After seconds
POST/refunds
Process idempotent refund against frozen snapshot
| Parameter | In | Type | Notes |
|---|---|---|---|
| Idempotency-Key * | header | string | Unique per operation. Scoped to your merchant and environment. A UUID is recommended. |
Body: RefundRequest
- 200 Refund processed
- 400 Request validation failed
- 401 Missing, invalid or revoked API key
- 403 merchant_id does not match the key, or the plan does not allow live keys (PLAN_REQUIRED)
- 404 Resource not found
- 409 Key reused with different payload
- 422 Insufficient refundable amount
- 429 Too many requests (`RATE_LIMITED`) or monthly allowance used (`QUOTA_EXCEEDED`)
- 503 A dependency is unavailable; retry after the Retry-After seconds
GET/transactions/{transaction_id}
Retrieve frozen transaction with refund ledger
| Parameter | In | Type | Notes |
|---|---|---|---|
| transaction_id * | path | string (uuid) |
- 200 The frozen transaction and its refund ledger
- 401 Missing, invalid or revoked API key
- 404 Resource not found
- 429 Too many requests (`RATE_LIMITED`) or monthly allowance used (`QUOTA_EXCEEDED`)
- 503 A dependency is unavailable; retry after the Retry-After seconds
GET/transactions/{transaction_id}/refunds
List refunds with cursor pagination
| Parameter | In | Type | Notes |
|---|---|---|---|
| transaction_id * | path | string (uuid) | |
| cursor | query | string | Opaque value from `next_cursor` on the previous page. |
| limit | query | integer |
- 200 A page of refunds for the transaction
- 401 Missing, invalid or revoked API key
- 404 Resource not found
- 429 Too many requests (`RATE_LIMITED`) or monthly allowance used (`QUOTA_EXCEEDED`)
- 503 A dependency is unavailable; retry after the Retry-After seconds
GET/transactions/{transaction_id}/integrity
Verify snapshot hash integrity (audit endpoint)
| Parameter | In | Type | Notes |
|---|---|---|---|
| transaction_id * | path | string (uuid) |
- 200 Integrity verified
- 401 Missing, invalid or revoked API key
- 404 Resource not found
- 409 Integrity violation detected
- 429 Too many requests (`RATE_LIMITED`) or monthly allowance used (`QUOTA_EXCEEDED`)
- 503 A dependency is unavailable; retry after the Retry-After seconds
Schemas
HealthResponse
| status | healthy | degraded | |
| timestamp | string (date-time) | |
| version | string | |
| uptime_seconds | integer | |
| dependencies | object |
CalculationRequest
| merchant_id | string (uuid) | Optional and not needed. The merchant comes from the API key; a different value is refused (403). |
| currency * | string | ISO 4217 code. Supported: USD, GBP, EUR, JPY, KWD, etc. |
| items * | CartItem[] | |
| discounts | DiscountRule[] | |
| metadata | object |
CartItem
| id * | string | |
| sku | string | |
| unit_price_cents * | integer | Price per unit in minor currency units |
| quantity * | integer | |
| is_discount_eligible | boolean | |
| metadata | object |
DiscountRule
FixedAmountRule
| rule_id * | string | |
| type * | FIXED_AMOUNT | |
| amount_cents * | integer | Fixed discount in minor currency units |
| applicable_items | string[] | |
| max_discount_cents | integer | |
| application_base | ORIGINAL_SUBTOTAL | REMAINING_BALANCE | PER_LINE |
PercentageRule
| rule_id * | string | |
| type * | PERCENTAGE | |
| basis_points * | integer | 1000 = 10%, 10000 = 100% |
| applicable_items | string[] | |
| max_discount_cents | integer | |
| application_base | ORIGINAL_SUBTOTAL | REMAINING_BALANCE | PER_LINE |
BuyXGetYRule
| rule_id * | string | |
| type * | BUY_X_GET_Y | |
| buy_quantity * | integer | Items needed to qualify |
| get_quantity * | integer | Items that receive the discount |
| get_discount_basis_points * | integer | 10000 = free, 5000 = 50% off |
| cheapest_first | boolean | true = discount cheapest eligible items first |
| applicable_items | string[] | |
| max_discount_cents | integer | |
| application_base | ORIGINAL_SUBTOTAL | REMAINING_BALANCE | PER_LINE |
CalculationResult
| transaction_id | string (uuid) | |
| merchant_id | string (uuid) | |
| currency | string | |
| currency_minor_unit_exponent | integer | 0 for JPY, 2 for GBP/USD, 3 for KWD |
| allocations | LineAllocation[] | |
| totals | CalculationTotals | |
| snapshot_hash | string | |
| metadata | object | |
| created_at | string (date-time) | |
| engine_version | string |
LineAllocation
| line_item_id | string | |
| sku | string | |
| quantity | integer | |
| unit_price_cents | integer | |
| original_cents | integer | |
| allocated_discount_cents | integer | |
| final_cents | integer | |
| final_tax_basis_cents | integer | |
| rule_provenance | object[] |
CalculationTotals
| subtotal_cents | integer | |
| total_discount_cents | integer | |
| final_total_cents | integer | |
| item_count | integer |
RefundRequest
| transaction_id * | string (uuid) | |
| line_item_id * | string | |
| quantity | integer | |
| reason | string | |
| metadata | object |
RefundResult
| refund_id | string (uuid) | |
| transaction_id | string (uuid) | |
| line_item_id | string | |
| refund_amount_cents | integer | |
| quantity_refunded | integer | |
| status | COMPLETED | ALREADY_REFUNDED | PARTIAL | |
| original_line_total_cents | integer | |
| previously_refunded_cents | integer | |
| remaining_refundable_cents | integer | |
| reason | string | |
| metadata | object | |
| created_at | string (date-time) |
TransactionSnapshot
| transaction_id | string (uuid) | |
| merchant_id | string (uuid) | |
| currency | string | |
| currency_minor_unit_exponent | integer | |
| request_snapshot | CalculationRequest | |
| result_snapshot | CalculationResult | |
| refund_ledger | RefundResult[] | |
| total_refunded_cents | integer | |
| net_total_cents | integer | |
| created_at | string (date-time) | |
| snapshot_hash | string | |
| engine_version | string |
PaginatedRefunds
| transaction_id | string (uuid) | |
| refunds | RefundResult[] | |
| has_more | boolean | |
| next_cursor | string | Opaque; pass it back as `cursor`. |
| total_refunded_cents | integer |
IntegrityReport
| transaction_id | string (uuid) | |
| stored_hash | string | |
| computed_hash | string | |
| is_valid | boolean | |
| checked_at | string (date-time) |
ErrorResponse
| error_code * | UNAUTHENTICATED | FORBIDDEN | PLAN_REQUIRED | SERVICE_UNAVAILABLE | VALIDATION_ERROR | IDEMPOTENCY_CONFLICT | NOT_FOUND | ALREADY_REFUNDED | INSUFFICIENT_REFUNDABLE | RATE_LIMITED | QUOTA_EXCEEDED | INTERNAL_ERROR | |
| message * | string | |
| details | object | |
| request_id * | string | |
| doc_url | string (uri) | https://valulog.com/docs/errors/<error_code>: what the code means and whether to retry. |