@shaggytools/nhtsa-api-wrapper
Javascript Wrapper and Helper Functions for the NHTSA VPIC API
A universal (browser/server) javascript wrapper for the National Highway Traffic
Safety Administration (NHTSA) Vehicle Information API (VPIC).
The VPIC API is primarily used for decoding useful information from a Vehicle Identification Number
(VIN) in the United States and Canada. It can also be used to get all models of a make, to decode
WMIs, get all makes for a certain year, and more.
Built With:
Full Documentation
Node Install
$ npm install @shaggytools/nhtsa-api-wrapper
Yarn
$ yarn add @shaggytools/nhtsa-api-wrapper
Pnpm
$ pnpm add @shaggytools/nhtsa-api-wrapper
Node Quick Start
Decoding a VIN is as easy as importing the DecodeVinValues
function and calling it
with a VIN.
Make sure to first install via your favorite package manager or use a CDN.
import { DecodeVinValues } from '@shaggytools/nhtsa-api-wrapper'
const results = await DecodeVinValues('WA1A4AFY2J2008189')
const { Results } = await DecodeVinValues('WA1A4AFY2J2008189')
const decodedVehicle = Results[0]
For a full example response see: DecodeVinValues
All available endpoints can be found here: VPIC API Endpoints
Browser Install
You can use the package directly in html script tags using a CDN. There are several options for CDN
providers.
For targeting modern browsers, you can use the ESM versions with <script type="module">
and
import statements.
For older browsers, you can use the IIFE versions with <script src="https://...">
to import the
package. Then use the package in a separate html script via the browser global NHTSA
. This global
variable is only available when using the IIFE or UMD versions.
UNPKG CDN
All package files and types are hosted on the UNPKG CDN found here:
https://www.unpkg.com/@shaggytools/nhtsa-api-wrapper/
jsDelivr CDN
Homepage: https://www.jsdelivr.com/package/npm/@shaggytools/nhtsa-api-wrapper
Browser Quick Start
The following examples use the jsDelivr CDN:
ESM:
~ 4kB (auto minified)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<h1>ESM Example</h1>
</body>
<script type="module">
import NHTSA from 'https://cdn.jsdelivr.net/npm/@shaggytools/nhtsa-api-wrapper/+esm'
console.log(NHTSA)
import { DecodeVinValues } from 'https://cdn.jsdelivr.net/npm/@shaggytools/nhtsa-api-wrapper/+esm'
const { Results } = await DecodeVinValues('11111111111111111')
console.log('Results', Results[0])
</script>
</html>
IIFE:
~ 4kB (auto minified)
IIFE browser global variable: NHTSA
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script
src="https://cdn.jsdelivr.net/npm/@shaggytools/nhtsa-api-wrapper"
></script>
</head>
<body>
<btn id="DecodeVinValues"
>Click to use DecodeVinValues()</btn
>
</br>
Results:
<div id="DecodeVinValuesResults"></div>
</body>
<script>
console.log(NHTSA)
document
.getElementById("DecodeVinValues")
.addEventListener("click", async function () {
const response = await NHTSA.DecodeVinValues("3VWD07AJ5EM388202").catch(
(err) => err
);
console.log('VPIC Response: ', response);
document.getElementById("DecodeVinValuesResults").innerText =
JSON.stringify(response.Results[0]);
});
</script>
</html>
List of Exported Functions
import {
DecodeVin,
DecodeVinExtended,
DecodeVinValues,
DecodeVinValuesBatch,
DecodeVinValuesExtended,
DecodeWMI,
GetAllMakes,
GetAllManufacturers,
GetCanadianVehicleSpecifications,
GetEquipmentPlantCodes,
GetMakeForManufacturer,
GetMakesForManufacturerAndYear,
GetMakesForVehicleType,
GetManufacturerDetails,
GetModelsForMake,
GetModelsForMakeId,
GetModelsForMakeIdYear,
GetModelsForMakeYear,
GetParts,
GetVehicleTypesForMake,
GetVehicleTypesForMakeId,
GetVehicleVariableList,
GetVehicleVariableValuesList,
GetWMIsForManufacturer,
useNHTSA,
isValidVin,
} from '@shaggytools/nhtsa-api-wrapper'