Skip to main content

Version: 0.1.0

Start Building with CarVach SDK


The CarVach SDK is a tool designed to integrate with the CarVach API, enabling developers to retrieve vehicle information and interact with vehicles remotely. This README provides a step - by step guide on how to use the CarVach SDK in your project.

Installation

First, you need to install the CarVach SDK package. Open your terminal and run the following command:

npm install carvach

Imports

import { Carvach, Vehicle } from "carvach";

Initialization

You can get CLIENT ID, CLIENT SECRET and REDIRECT URI from CarVach Dashboard

const carvach = new Carvach({
clientId: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
redirectUri: process.env.REDIRECT_URI,
});

Getting Authorization URL

To authorize you application with the OEM(Original Equipment Manufacturer), you need to acquire an authorization URL:

app.get("/", async (req, res) => {
const url = await carvach.getAuthUrl();
res.redirect(url);
});

Handling Authorization Code

After authorization completes, you application will receive an authorization code on your redirect endpoint. Your application server will have to used that code to excahnge access_token for it.

// Example:  https://your-application-server.com/redirect?code=28sg83nkjsdofi8

app.get("/redirect", async (req, res) => {
const authorization_code = req.query.code;
const { access_token } = await carvach.exchangeCode(authorization_code);
});

Interacting with Vehicle

Once you have obtained the access token, you can use it to interact with the vehicle data. Here's an example of how to retrieve the vehicle's odometer reading:

app.get("/redirect", async (req, res) => {
const authorization_code = req.query.code;
const { access_token } = await carvach.exchangeCode(authorization_code);

const vehicle = new Vehicle({
vin: CARVACH_VIN,
accessToken: access_token,
subscriptionKey: process.env.SUBSCRIPTION_KEY,
});

const result = await vehicle.getOdometerReading();
console.log(result);
});