JavaScript Quickstart
Call the Carapis API from JavaScript with the built-in fetch — set the Bearer header, hit GET /v2/listings, and read structured car data from JSON. Works in Node 18+ and modern browsers; no SDK required.
Set your key
Store your key in an environment variable (get one at my.carapis.com ). In the browser, proxy requests through your own server so the key is never exposed:
export CARAPIS_API_KEY="your_api_key_here"First request
const res = await fetch(
"https://api.carapis.com/v2/listings?source=encar&limit=20",
{ headers: { Authorization: `Bearer ${process.env.CARAPIS_API_KEY}` } },
);
if (!res.ok) throw new Error(`Carapis ${res.status}`);
const data = await res.json();
console.log(data.count, "total matches");
for (const car of data.results) {
console.log(car.make, car.model, car.year, car.price, car.currency);
}Set source to any slug from the platforms page.
Filtering
const params = new URLSearchParams({
source: "encar",
make: "Hyundai",
model: "Grandeur",
year_min: "2021",
price_max: "30000000",
limit: "20",
});
const res = await fetch(
`https://api.carapis.com/v2/listings?${params}`,
{ headers: { Authorization: `Bearer ${process.env.CARAPIS_API_KEY}` } },
);See every parameter in the listings reference.
Paging through all results
async function* allListings(source, limit = 20) {
let page = 1;
while (true) {
const res = await fetch(
`https://api.carapis.com/v2/listings?source=${source}&limit=${limit}&page=${page}`,
{ headers: { Authorization: `Bearer ${process.env.CARAPIS_API_KEY}` } },
);
const { results } = await res.json();
if (results.length === 0) break;
yield* results;
page += 1;
}
}
for await (const car of allListings("encar")) {
console.log(car.id, car.price);
}Handling errors
const res = await fetch(url, options);
if (!res.ok) {
const { error } = await res.json();
console.error(res.status, error.code, error.message);
}See Authentication, Pagination, Rate limits and Errors for the full reference.