Vahan SDK provides a easy-to-use APIs for seamless integration
- Prerequisites
- Installation Outline
- Installation and Setup
- Supported Functionalities
- Token Manager Functions
- Vehicle Functions
- State Functions
- Control Functions
- General Functions
- Vendor Prerequisites
- Prerequisites for Tesla
---
- Must have a VahanAPI account.
- Complete vendor specific prerequisites.
- Node and node package manager(NPM) must be installed.
---
1. Create a VahanAPI account.
2. Complete vendor specific prerequisites.
3. Installing node and npm.
4. Install the SDK from npm.
- Create your VahanAPI account from this Link.
- Follow this link to reach vendor specfic tasks.
- Follow this link for the guide to install npm.
- Install the SDK from npm.
```
npm i vahansdk
- Initialise a npm project
``
npm init
- In the package.json add "type": "module" as mentioned below.
``
{
"name": "project",
"main": "index.js",
"type": "module",
}
1. Import the VahanSDK from the npm package.
``
import { VahanSDK } from "vahansdk";
2. Initialise the VahanSDK with your Vahan account.
``
const Vahan = new VahanSDK(username, password);
3. Generate the accessToken for authorization.
``
const token = await Vahan.TokenManager.getVahanAccessToken();
4. Now any api can be called using their specified function calls.
`required-parameters
const Response = await Vahan.Vehicles.vehicleSummary();`
console.log(Response)
---
- To use supported functions, follow this approach.
- To utilize supported functions, adhere to the following approach:
- Identify the function type from the list below:
1. TokenManager
2. Vehicle
3. State
4. Control
5. 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
});
`
---
- For detailed information about our APIs, visit this link.
---
- 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 })_
1. getAccessToken
2. refreshAccessToken
Read More about TokenManager functions.
---
_For Vehicle Type(Vahan.Vehicles. { functionName } )_
1. vehicleSummary
2. vehicleSpecifications
Read More about Vehicle functions.
---
_For State Type(Vahan.State. { functionName } )_
1. batteryState
2. climateState
3. locationState
4. vehicleState
Read More about State functions.
---
_For Control Type(Vahan.Control. { functionName } )_
1. getVehicleControls
2. chargePortControl
3. engineControl
4. flashLightControl
5. frunkControl
6. hornControl
7. vehicleLockControl
8. sentryModeControl
9. vehicleSoftwareControl
10. sunroofControl
11. thermostatControl
12. trunkControl
13. valetModeControl
14. ventControl
15. wakeUpControl
Read More about Control functions.
---
_For General Type(Vahan.General. { functionName } )_
1. diagnostics (DNE on Mock server so would be returning 404)
2. releaseNotes
Read More about General functions.
`
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.
`
---
- 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.
---
- 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();
`
---
- 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.
- Retrieve specifications of your vehicle.
``
const response = await Vahan.Vehicles.vehicleSpecifications(vendor, keyId, vahanAccessToken, vendorAccessToken, additionalParameters);
---
- Retrieve summary of your vehicle.
``
const response = await Vahan.Vehicles.vehicleSummary(vendor, keyId, vahanAccessToken, vendorAccessToken, additionalParameters);
---
- Retrieve all vehicles linked to the requesting user.
``
const response = await Vahan.State.batteryState(vendor, keyId, vahanAccessToken, vendorAccessToken, additionalParameters);
---
- Retrieve all vehicles linked to the requesting user.
``
const response = await Vahan.State.climateState(vendor, keyId, vahanAccessToken, vendorAccessToken, additionalParameters);
---
- Retrieve all vehicles linked to the requesting user.
``
const response = await Vahan.State.locationState(vendor, keyId, vahanAccessToken, vendorAccessToken, additionalParameters);
---
- Retrieve all vehicles linked to the requesting user.
``
const response = await Vahan.State.vehicleState(vendor, keyId, vahanAccessToken, vendorAccessToken, additionalParameters);
---
- Retrieves controls supported by your vehicles.
``
const response = await Vahan.Control.getVehicleControls(vendor, keyId, vahanAccessToken, vendorAccessToken, additionalParameters);
---
- Manage the charging port functionality of your vehicle.
``
const response = await Vahan.Control.chargePortControl(vendor, keyId, action, vahanAccessToken, vendorAccessToken, additionalParameters);
---
- Manage the engine control functionality of your vehicle.
``
const response = await Vahan.Control.engineControl(vendor, keyId, vahanAccessToken, vendorAccessToken, additionalParameters);
---
- Manage the flash light functionality of your vehicle.
``
const response = await Vahan.Control.flashLightControl(vendor, keyId, vahanAccessToken, vendorAccessToken, additionalParameters);
---
- Manage the frunk(front trunk) functionality of your vehicle.
``
const response = await Vahan.Control.frunkControl(vendor, keyId, vahanAccessToken, vendorAccessToken, additionalParameters);
---
- Manage the horn functionality of your vehicle.
``
const response = await Vahan.Control.hornControl(vendor, keyId, vahanAccessToken, vendorAccessToken, additionalParameters);
---
- Manage the locking functionality of your vehicle.
``
const response = await Vahan.Control.vehicleLockControl(vendor, keyId, action, vahanAccessToken, vendorAccessToken, additionalParameters);
---
- Manage the sentry mode functionality of your vehicle.
``
const response = await Vahan.Control.sentryModeControl(vendor, keyId, action, vahanAccessToken, vendorAccessToken, additionalParameters);
---
- Initiate or cancel the vehicle software updates of your vehicle.
``
const response = await Vahan.Control.vehicleSoftwareControl(vendor, keyId, action, vahanAccessToken, vendorAccessToken, additionalParameters);
---
- Manage the sunroof functionality of your vehicle.
``
const response = await Vahan.Control.sunroofControl(vendor, keyId, action, vahanAccessToken, vendorAccessToken, additionalParameters);
---
- Manage the thermostat functionality of your vehicle.
``
const response = await Vahan.Control.thermostatControl(vendor, keyId, action, vahanAccessToken, vendorAccessToken, additionalParameters);
---
- Manage the trunk functionality of your vehicle.
``
const response = await Vahan.Control.trunkControl(vendor, keyId, vahanAccessToken, vendorAccessToken, additionalParameters);
---
- Manage the valet mode functionality of your vehicle.
``
const response = await Vahan.Control.valetModeControl(vendor, keyId, action, valetPassword, vahanAccessToken, vendorAccessToken, additionalParameters);
---
- Manage the vent functionality of your vehicle.
``
const response = await Vahan.Control.ventControl(vendor, keyId, action, vahanAccessToken, vendorAccessToken, additionalParameters);
---
- Wake up the car from sleep.
``
const response = await Vahan.Control.wakeUpControl(vendor, keyId, action, vahanAccessToken, vendorAccessToken, additionalParameters);
---
- Retrieve diagnostics details for your vehicle.
``
const response = await Vahan.General.diagnostics(vendor, keyId, vahanAccessToken, vendorAccessToken, additionalParameters);
---
- Retrieve release notes details for your vehicle.
```
const response = await Vahan.General.releaseNotes(vendor, keyId, vahanAccessToken, vendorAccessToken, additionalParameters);
---
- For Tesla:
- Have Tesla mobile app installed on your device.
- Install virtual key on the vehicle.
- Generate vendorAccessToken.
---
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.
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.