Skip to content

Examples

All examples follow the same flow: find the tool → calculate. In production code, add error handling and a timeout.

Terminal window
BASE="https://api.mirac-ozdemir.com/v1/public"
curl -s "$BASE/search?locale=tr&q=kdv&pageSize=1"
curl -s -X POST "$BASE/tools/by-key/kdv/calculate" \
-H "Content-Type: application/json" \
-d '{"inputs":{"amount":"1000","mode":"exclusive","vatRateOption":"standard"}}'

Drawing a results table from the definition

Section titled “Drawing a results table from the definition”

breakdown carries both the label keys and the format; the labels are in the definition:

const { data: tool } = await api(`/tools/by-key/${key}?locale=tr`);
const { data, meta } = await api(`/tools/by-key/${key}/calculate`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ version: tool.versionNumber, inputs }) });
for (const item of data.breakdown) {
const label = tool.content.labels.outputs[item.key]?.label ?? item.key;
const value = item.format === 'money'
? new Intl.NumberFormat('tr-TR', { style: 'currency', currency: item.currency }).format(item.value)
: item.value;
console.log(`${label}: ${value}`);
}