Polovni Automobili API call plan and cost
A typical lookup has four steps:
- Take the brand label from brands.
- Find the model spelling with models.
- Run a filtered search and walk its pages.
- Open the advertisements you care about with listing.
The first two results do not depend on the search that follows, so one brands call and one models call per brand can serve many searches, and filter-options belongs to the same setup stage when you build a filter form. Costs add up per call: a models call is 4.5 credits, while a brands call, each search page and each listing are 3 credits apiece.
Finding diesel Golfs whose matches fit on one page of up to 200 rows and then reading five of them in full therefore costs 3 + 4.5 + 3 + 15 = 25.5 credits. The first example follows this plan with one change: it skips brands because the label Volkswagen is already known, takes the model Golf for the search from the models response, sends page 2 only because page 1 reported has_more, and copies the listing's ad_id from a row of page 1.
Resolve the brand label and the model spelling
Brand values are exact labels. To resolve the label and the model spelling:
- Take
labelfrom a brands entry, notslug, and send it unchanged, because a hyphenated variant is rejected. - Call models with that label. The response lists
{model, ads_seen}pairs found in the sampled advertisements and tells you how much was read throughads_sampledandsample_coverage_pct. - If a model you expect is missing and the coverage is below 100, call again with a larger
sample_pages, up to 10. - Use each
modelstring exactly as returned inside the searchmodelarray, and put two or more names there to search several models at once.
For a filter form, filter-options supplies the allowed values with Serbian labels to show next to them.
Turn requirements into search filters
Map each requirement to one field:
- A budget of 12,000 becomes
price_max: 12000in the advertisement's currency; checkprice_currencyon every row, and setonly_with_price: trueto skip ads without a price. - A horsepower limit has to be converted to kilowatts for
power_kw_minorpower_kw_max. - Four or five doors is
doors: "5", written as a string. - Several fuels go into one
fuelarray and match any of them, but the emission class takes a single value, so Euro 5 and Euro 6 cars need two separate searches.
The search contract declares no field for equipment; filter for equipment yourself on the equipment array of each listing instead.
Page through results within 750 pages
To read a result page by page:
- Start with
page: 1andpage_size: 200, the largest page. - After each response, store the rows of
carsand keeptop_adsapart, because those are paid placements rather than search hits. - Continue while
has_moreis true and the next page number is withinreachable_pages.
Page numbers stop at 750, and a request for page 751 is refused at no cost. When total_results is larger than reachable_results, split the search into narrower ones, for example by year_min and year_max bands or by fuel, and merge their rows by ad_id. Each page is a separate billable call, so reading a result of 3,000 rows at 200 per page takes 15 calls and 45 credits.
Open the advertisements you need
Pick rows from the search results and send each ad_id string to listing exactly as returned. Leave out slug unless you want it reflected in the returned URL. A removed advertisement answers with a failure that is not charged, so record it and move on instead of retrying.
Listing calls are independent of each other: give each its own Idempotency-Key and pace them: your account allows a burst of 10 requests, then one more every 0.2 seconds, and limits shared by all customers can apply as well, so RATE_LIMITED or CONCURRENCY_LIMIT (429) can arrive even at that pace. Wait the seconds given in Retry-After and resend with the same key.
Timeouts and retries without paying twice
Create one Idempotency-Key per intent and store it with the exact action and JSON before sending. If a call ends with OPERATION_TIMEOUT (504), OUTCOME_UNKNOWN or RESULT_INVALID, the operation may have run: its price is held, not charged, and released after 15 minutes. Do not send that intent again under a new key.
Resending the unchanged request with the same key never runs it a second time; it answers REQUEST_PENDING (409) while the hold is open and OUTCOME_UNKNOWN_RELEASED (504), with nothing charged, after the release, and a result that arrives after the timeout is never delivered. Only then decide whether a new request with a new key is worth it, knowing it is charged if it succeeds. A definite failure such as REQUEST_REJECTED calls for a corrected request under a new key.
Example 2: the loop in JavaScript
The second example runs the same plan against stubbed replies, so it needs no key and makes no network calls. post() builds each request with the action path, a fresh Idempotency-Key and the input under body, and send() stands in for the network, keeping each reply under its key the way the gateway does. The code:
- takes the brand label from brands
- picks the model with the most
ads_seen - pages through search while
has_moreis true and collects 260 rows - opens the first two rows with listing
The second listing times out; the code resends it once with the same key, gets REQUEST_PENDING (409) and stops there. It prints the chosen model, the row count, the opened listing, the pending one and the 16.5 credits spent, because the timed-out call was not charged.
[
{
"body": {
"brand": "Volkswagen",
"sample_pages": 5
}
},
{
"body": {
"brand": "Volkswagen",
"model": [
"Golf"
],
"fuel": [
"diesel"
],
"year_min": 2015,
"mileage_max": 150000,
"price_max": 12000,
"page": 1,
"page_size": 200
}
},
{
"body": {
"brand": "Volkswagen",
"model": [
"Golf"
],
"fuel": [
"diesel"
],
"year_min": 2015,
"mileage_max": 150000,
"price_max": 12000,
"page": 2,
"page_size": 200
}
},
{
"body": {
"ad_id": "9182736405"
}
}
]// Brands → models → search pages → listing, run against stubbed replies: no API key and no network calls.
// 品牌 → 车型 → 分页搜索 → 广告详情;响应为内存中的桩数据,不需要密钥,也不发起网络请求。
const PRICE = { 'polovniautomobili-models': '450' }; // Every other operation costs '300' credit units.
const row = (i) => ({ ad_id: String(9182736000 + i), brand: 'Volkswagen', model: 'Golf',
year: 2016, price: 9900 + i, price_currency: 'EUR', mileage_km: 140000 - i, fuel: 'diesel' });
const stub = {
'polovniautomobili-brands': () => ({ count: 2, total_ads: 2400, brands: [
{ brand: 'Volkswagen', label: 'Volkswagen', slug: 'volkswagen' },
{ brand: 'Škoda', label: 'Škoda', slug: 'skoda' }] }),
'polovniautomobili-models': (body) => ({ brand: body.brand, brand_ads: 1800, ads_sampled: 1000,
sample_pages: body.sample_pages, sample_coverage_pct: 55.6, count: 2,
models: [{ model: 'Passat', ads_seen: 310 }, { model: 'Golf', ads_seen: 420 }] }),
'polovniautomobili-search': (body) => ({ total_results: 260, page: body.page,
page_size: body.page_size, pages: 2, has_more: body.page < 2,
cars: Array.from({ length: body.page === 1 ? 200 : 60 }, (_, i) => row((body.page - 1) * 200 + i)),
top_ads: [] }),
// The second advertisement times out, so the code below shows the same-key check.
'polovniautomobili-listing': (body) => body.ad_id === '9182736001' ? 'timeout'
: { car: { ...row(Number(body.ad_id) - 9182736000), equipment: ['ABS'], images: [] } },
};
const stored = new Map(); // What the gateway keeps per Idempotency-Key.
let requestNumber = 0;
function send(request) { // Stands in for fetch(); returns { status, json }.
const key = request.headers['Idempotency-Key'];
if (stored.has(key)) return stored.get(key); // Same key: the recorded state, never a second run.
const action = request.path.split('/').pop();
const { body } = JSON.parse(request.body);
const out = stub[action](body), requestId = `req-${++requestNumber}`;
if (out === 'timeout') {
stored.set(key, { status: 409, json: { ok: false, error: { code: 'REQUEST_PENDING',
message: 'This request was already dispatched.' },
meta: { requestId, chargedCreditUnits: '0', status: 'uncertain' } } });
return { status: 504, json: { ok: false, error: { code: 'OPERATION_TIMEOUT',
message: 'The operation did not finish in time and may still have run.' },
meta: { requestId, chargedCreditUnits: '0', status: 'uncertain' } } };
}
const reply = { status: 200, json: { ok: true, data: out,
meta: { requestId, chargedCreditUnits: PRICE[action] ?? '300' } } };
stored.set(key, reply);
return reply;
}
let spentUnits = 0;
function post(action, body, key = crypto.randomUUID()) { // One new key per intent.
const request = { method: 'POST', path: `/api/v1/polovniautomobili/${action}`,
headers: { 'Content-Type': 'application/json', 'Idempotency-Key': key },
body: JSON.stringify({ body }) }; // Every input sits under body.
const { status, json } = send(request);
spentUnits += Number(json.meta.chargedCreditUnits);
return { status, json, key };
}
// 1. Brand label (never the slug), then the model with the most ads_seen.
const brand = post('polovniautomobili-brands', {}).json.data.brands
.find((entry) => entry.label === 'Volkswagen').label;
const sampled = post('polovniautomobili-models', { brand, sample_pages: 5 }).json.data;
const model = [...sampled.models].sort((a, b) => b.ads_seen - a.ads_seen)[0].model;
// 2. Search with filters, 200 rows per page, while has_more is true (page numbers stop at 750).
const filters = { brand, model: [model], fuel: ['diesel'], year_min: 2015,
mileage_max: 150000, price_max: 12000 };
const rows = [];
for (let page = 1; page <= 750; page++) {
const { data } = post('polovniautomobili-search', { ...filters, page, page_size: 200 }).json;
rows.push(...data.cars);
if (!data.has_more) break;
}
// 3. Open the first two rows; an uncertain outcome is checked with the SAME key, never retried with a new one.
const opened = [], pending = [];
for (const { ad_id } of rows.slice(0, 2)) {
const first = post('polovniautomobili-listing', { ad_id });
if (first.json.ok) { opened.push(first.json.data.car.ad_id); continue; }
if (first.json.meta.status !== 'uncertain') continue; // A definite failure: nothing charged, move on.
const check = post('polovniautomobili-listing', { ad_id }, first.key);
pending.push({ ad_id, first: first.json.error.code, check: check.json.error.code, status: check.status });
}
console.log({ brand, model, rows: rows.length, opened, pending, spentCredits: spentUnits / 100 });
Server-side request template
This server-side template shows authentication and request identity using the first operation of this API. Choose the operation for your use case and check its current availability and price on the API page. After a timeout, resend the unchanged request with the same Idempotency-Key.
The gateway request is always POST.
Use a JSON object with the documented path, query, headers and body locations; omit unused locations. input.headers is JSON data for the operation, not browser request headers. Do not put credentials here. Keep body arrays, scalar values and null as documented; omission is different from null.
# Server-side only. Set KAKIAPI_API_KEY in your secret manager.
# Every gateway operation is called with POST.
# Only operations shown as enabled on the API page can be called.
# Generate once per intent; retain the same value on status checks.
REQUEST_ID="$(uuidgen)"
curl --request POST 'https://kakiapi.com/api/v1/polovniautomobili/polovniautomobili-brands' \
--header "Content-Type: application/json" \
--header "x-api-key: $KAKIAPI_API_KEY" \
--header "Idempotency-Key: $REQUEST_ID" \
--data '{"body":{}}'Integration checklist
- The API key is stored in a server-side secret manager and never sent to a browser.
- Each request carries its own Idempotency-Key, kept until the request has a final answer.
- The integration reads ok and error.code and handles each error code as the error table describes.
- An uncertain POST is inspected using its original identity, never blindly repeated with a new one.
- The operation’s current availability and price have been checked on its API page.
Polovni Automobili car classifieds overview and prices · Read the API reference · Try it in the playground