Legacy v1
TypeScript SDK
Last updated:
Official TypeScript/JavaScript SDK for the Cardog v1 API.
Docs for the previous API generation. v1 endpoints keep working, but new work should target v2. See v2 Quickstart.
The official TypeScript SDK for the Cardog API. Works with Node.js, Bun, Deno, and modern browsers.
Installation
npm install @cardog/api
# or
pnpm add @cardog/api
# or
yarn add @cardog/apiQuick Start
import { CardogClient } from "@cardog/api";
const client = new CardogClient({
apiKey: process.env.CARDOG_API_KEY,
});
// Decode a VIN
const vehicle = await client.vin.decode("1HGCM82633A123456");
console.log(vehicle.make, vehicle.model, vehicle.year);Configuration
const client = new CardogClient({
apiKey: "your-api-key",
baseUrl: "https://api.cardog.app", // Optional, defaults to production
timeout: 30000, // Optional, request timeout in ms
});VIN Decoding
// Full decode with specs
const result = await client.vin.decode("1HGCM82633A123456");
// Result includes:
// - make, model, year, trim
// - engine, transmission, drivetrain
// - body style, doors, seats
// - fuel type, MPG estimates
// - and more...Listings Search
const listings = await client.listings.search({
make: "Toyota",
model: "Camry",
yearMin: 2020,
priceMax: 30000,
limit: 20,
});
for (const listing of listings.data) {
console.log(`${listing.title} - $${listing.price}`);
}Recalls
// Get recalls for a specific vehicle
const recalls = await client.recalls.byVin("1HGCM82633A123456");
// Or search by make/model/year
const toyotaRecalls = await client.recalls.search({
make: "Toyota",
model: "Camry",
year: 2020,
});Error Handling
import { CardogClient, CardogError } from "@cardog/api";
try {
const result = await client.vin.decode("INVALID");
} catch (error) {
if (error instanceof CardogError) {
console.error(error.code, error.message);
}
}React Query Integration
The SDK works with React Query:
import { useQuery } from "@tanstack/react-query";
import { client } from "./cardog";
function VehicleDetails({ vin }: { vin: string }) {
const { data, isLoading } = useQuery({
queryKey: ["vin", vin],
queryFn: () => client.vin.decode(vin),
});
if (isLoading) return <div>Loading...</div>;
return <div>{data?.make} {data?.model}</div>;
}TypeScript Support
The SDK is written in TypeScript and ships full type definitions:
import type { Vehicle, Listing, Recall } from "@cardog/api";
function displayVehicle(vehicle: Vehicle) {
// Full autocomplete and type checking
}Source Code
The SDK is open source: github.com/cardog-ai/cardog-js
Was this helpful?