vahansdk
v1.0.5
Published
Vahan SDK provides a easy-to-use APIs for seamless integration
Readme
Software Development Kit for Universal Car Backend.
Table of contents.
- Prerequisites
- Installation Outline
- Installation and Setup
- Supported Functionalities
- Token Manager Functions
- Vehicle Functions
- State Functions
- Control Functions
- General Functions
- Vendor Prerequisites
Prerequisites:
- Must have a VahanAPI account.
- Complete vendor specific prerequisites.
- Node and node package manager(NPM) must be installed.
Installation Outline:
- Create a VahanAPI account.
- Complete vendor specific prerequisites.
- Installing node and npm.
- Install the SDK from npm.
Installation and Setup.
Create VahanAPI account
- Create your VahanAPI account from this Link.
Vendor Specific Prequisites
- Follow this link to reach vendor specfic tasks.
Don't have npm installed?
- Follow this link for the guide to install npm.
How to Install the SDK.
- Install the SDK from npm.
npm i vahansdkSteps to Run.
- Initialise a npm project
npm init- In the package.json add "type": "module" as mentioned below.
{
"name": "project",
"main": "index.js",
"type": "module",
}- Import the VahanSDK from the npm package.
import { VahanSDK } from "vahansdk";- Initialise the VahanSDK with your Vahan account.
const Vahan = new VahanSDK(username, password);- Generate the accessToken for authorization.
const token = await Vahan.TokenManager.getVahanAccessToken();- Now any api can be called using their specified function calls.
const Response = await Vahan.Vehicles.vehicleSummary(`required-parameters`);
console.log(Response)How to use the supported functions
To use supported functions, follow this approach.
To utilize supported functions, adhere to the following approach:
Identify the function type from the list below:
- TokenManager
- Vehicle
- State
- Control
- General
Select the appropriate function from the corresponding category.
const Vahan = new VahanSDK(username, password);
try{
const token = await Vahan.{functionType}.{function}( `required-parameters` );// Use the resolved data
}catch(error){
console.log(new Error(error)); // Handle errors
}
(or)
Vahan.{functionType}.{function}()
.then((`required-parameters`) => {
console.log('result'); // Use the resolved data
})
.catch((error) => {
console.error('Error:', error); // Handle errors
});
Explore our APIs
- For detailed information about our APIs, visit this link.
List of Supported Functions
Both methods, async/await and promise chaining, are suitable for resolving promises returned by the mentioned functions.
Ensure that the promise is resolved before proceeding with its usage when utilizing promise chaining.
For Auth Type(Vahan.TokenManager. { functionName })
- getAccessToken
- refreshAccessToken
Read More about TokenManager functions.
For Vehicle Type(Vahan.Vehicles. { functionName } )
- vehicleSummary
- vehicleSpecifications
Read More about Vehicle functions.
For State Type(Vahan.State. { functionName } )
- batteryState
- climateState
- locationState
- vehicleState
Read More about State functions.
For Control Type(Vahan.Control. { functionName } )
- getVehicleControls
- chargePortControl
- engineControl
- flashLightControl
- frunkControl
- hornControl
- vehicleLockControl
- sentryModeControl
- vehicleSoftwareControl
- sunroofControl
- thermostatControl
- trunkControl
- valetModeControl
- ventControl
- wakeUpControl
Read More about Control functions.
For General Type(Vahan.General. { functionName } )
- diagnostics (DNE on Mock server so would be returning 404)
- releaseNotes
Read More about General functions.
Parameters
1. username
- Vahan username.
2. password
- Vahan password.
3. vahanAccessToken
- accesstoken for authentication for Vahan.
4. vendorAccessToken
- accesstoken for authentication for Vendor.
5. vendor.
- vehicle brand name.
- supported vendors.
1. tesla
2. rivian
3. velocity (mock vehicle)
- must be a string
6. keyId.
- keyId of the vehicle.
- must be a string.
7. body.
- object body containing data.
8. action.
- states the action to be performed on the control.
- true indicates affirmative action (open, turn on, etc).
- false indicates negative action (close, turn off, etc).
- must be a boolean.
9. valetPassword.
- password required to disable the valet mode for tesla.
- must be a string.
10. additionalParameters.
- additional parameters are necessary for specific vendor requests.Token Manager functions
Serves to both generate an accessToken and refresh it upon expiration.
The accessToken, once generated, has an expiration period of 30 days.
Employ the refreshAccessToken() function to renew the accessToken.
How to generate accessToken:
- Please provide your VahanAPI username and password to initialize an instance of the SDK.
const Vahan = new VahanSDK(username, password);- Generate the accessToken by invoking the getAccessToken() function.
const Vahan = new VahanSDK(username, password);
const token = await Vahan.TokenManager.getAccessToken();
Refresh the accessToken
Token renewal can be accomplished utilizing the refreshToken() function.
Ensure that the accessToken is generated prior to refreshing it.
const Vahan = new VahanSDK(username, password);
let token = await Vahan.TokenManager.getAccessToken();
token = await Vahan.TokenManager.refreshAcessToken()
- Ensure that the functions are encapsulated within an async function.
Vehicle functions
Obtaining Vehicle Specifications
- Retrieve specifications of your vehicle.
const response = await Vahan.Vehicles.vehicleSpecifications(vendor, keyId, vahanAccessToken, vendorAccessToken, additionalParameters);Obtaining Vehicle Summary
- Retrieve summary of your vehicle.
const response = await Vahan.Vehicles.vehicleSummary(vendor, keyId, vahanAccessToken, vendorAccessToken, additionalParameters);State functions
Assess the battery condition of your vehicle.
- Retrieve all vehicles linked to the requesting user.
const response = await Vahan.State.batteryState(vendor, keyId, vahanAccessToken, vendorAccessToken, additionalParameters);Assess the climate condition of your vehicle.
- Retrieve all vehicles linked to the requesting user.
const response = await Vahan.State.climateState(vendor, keyId, vahanAccessToken, vendorAccessToken, additionalParameters);Assess the location of your vehicle.
- Retrieve all vehicles linked to the requesting user.
const response = await Vahan.State.locationState(vendor, keyId, vahanAccessToken, vendorAccessToken, additionalParameters);Assess the state of the vehicle.
- Retrieve all vehicles linked to the requesting user.
const response = await Vahan.State.vehicleState(vendor, keyId, vahanAccessToken, vendorAccessToken, additionalParameters);Control functions.
Retrieve a comprehensive list of all controls supported by your vehicle
- Retrieves controls supported by your vehicles.
const response = await Vahan.Control.getVehicleControls(vendor, keyId, vahanAccessToken, vendorAccessToken, additionalParameters);Control Charge Port
- Manage the charging port functionality of your vehicle.
const response = await Vahan.Control.chargePortControl(vendor, keyId, action, vahanAccessToken, vendorAccessToken, additionalParameters);Control Engine
- Manage the engine control functionality of your vehicle.
const response = await Vahan.Control.engineControl(vendor, keyId, vahanAccessToken, vendorAccessToken, additionalParameters);Control Flash light
- Manage the flash light functionality of your vehicle.
const response = await Vahan.Control.flashLightControl(vendor, keyId, vahanAccessToken, vendorAccessToken, additionalParameters);Control Frunk
- Manage the frunk(front trunk) functionality of your vehicle.
const response = await Vahan.Control.frunkControl(vendor, keyId, vahanAccessToken, vendorAccessToken, additionalParameters);Control Horn
- Manage the horn functionality of your vehicle.
const response = await Vahan.Control.hornControl(vendor, keyId, vahanAccessToken, vendorAccessToken, additionalParameters);Control locking mechanism
- Manage the locking functionality of your vehicle.
const response = await Vahan.Control.vehicleLockControl(vendor, keyId, action, vahanAccessToken, vendorAccessToken, additionalParameters);Control sentry mode
- Manage the sentry mode functionality of your vehicle.
const response = await Vahan.Control.sentryModeControl(vendor, keyId, action, vahanAccessToken, vendorAccessToken, additionalParameters);Control vehicle software
- Initiate or cancel the vehicle software updates of your vehicle.
const response = await Vahan.Control.vehicleSoftwareControl(vendor, keyId, action, vahanAccessToken, vendorAccessToken, additionalParameters);Control sunroof
- Manage the sunroof functionality of your vehicle.
const response = await Vahan.Control.sunroofControl(vendor, keyId, action, vahanAccessToken, vendorAccessToken, additionalParameters);Control thermostat
- Manage the thermostat functionality of your vehicle.
const response = await Vahan.Control.thermostatControl(vendor, keyId, action, vahanAccessToken, vendorAccessToken, additionalParameters);Control trunk
- Manage the trunk functionality of your vehicle.
const response = await Vahan.Control.trunkControl(vendor, keyId, vahanAccessToken, vendorAccessToken, additionalParameters);Control valet mode
- Manage the valet mode functionality of your vehicle.
const response = await Vahan.Control.valetModeControl(vendor, keyId, action, valetPassword, vahanAccessToken, vendorAccessToken, additionalParameters);Control vents
- Manage the vent functionality of your vehicle.
const response = await Vahan.Control.ventControl(vendor, keyId, action, vahanAccessToken, vendorAccessToken, additionalParameters);Wake up your Vehicle
- Wake up the car from sleep.
const response = await Vahan.Control.wakeUpControl(vendor, keyId, action, vahanAccessToken, vendorAccessToken, additionalParameters);General functions.
Retrieve diagnostics details
- Retrieve diagnostics details for your vehicle.
const response = await Vahan.General.diagnostics(vendor, keyId, vahanAccessToken, vendorAccessToken, additionalParameters);Retrieve release notes details
- Retrieve release notes details for your vehicle.
const response = await Vahan.General.releaseNotes(vendor, keyId, vahanAccessToken, vendorAccessToken, additionalParameters);Vendor prerequisites
Prerequisites for Tesla
For Tesla:
- Have Tesla mobile app installed on your device.
- Install virtual key on the vehicle.
- Generate vendorAccessToken.
Setup for Tesla
Installation of Virtual key on vehicle
- Ensure you have the Tesla mobile app installed.
- To install the virtual key on your vehicle, please proceed with this link
- Proceed according to the Tesla app's instructions.
Generate vendorAccessToken
Follow this link to generate the vendorAccessToken and use it to call the functions for tesla.
This token needs to be refreshed every 8 hours.
Parameters for Tesla
To ensure proper configuration follow these steps
- Please enter the vendor field as 'tesla' or utilize Vahan's enum as Vendor.TESLA, ensuring consistency across the configuration.
- Please use the vehicle's VIN number as the keyId for Tesla.
- Please enter the vahanAccessToken and vendorAccessToken without the 'Bearer' prefix.
- Additional parameters are not required for Tesla configurations.
