DecodeWMI
async function DecodeWMI(
WMI: string,
doFetch?: boolean
) => Promise<NhtsaResponse<DecodeWMIResults> | string>
💡 More In Depth
See: Package Reference
Description
DecodeWMI provides information on the World Manufacturer Identifier for a specific WMI code.
WMI may be provided as either 3 characters representing VIN position 1-3 or 6 characters representing VIN positions 1-3 & 12-14.
- Examples: "JTD" "1T9131"
A list of WMI codes can be found here, but keep in mind that not all of the listed WMIs are registered with NHTSA and therefore may not be available in VPIC data sets.
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
WMI | string | undefined | World Manufacturer Identifier |
doFetch? | boolean | true | Whether to fetch the data or just return the URL (default: true) |
📝 NOTE
Set doFetch to false if you want to fetch the data yourself.
- See BYOF - Bring Your Own Fetch for more info.
Returns
Returns a Promise that resolves to a single NhtsaResponse object of type DecodeWMIResults in the Results key.
=> Promise<NhtsaResponse<DecodeWMIResults>>
interface NhtsaApiResponse<DecodeWMIResults> = {
Count: number
Message: string
Results: Array<DecodeWMIResults>
SearchCriteria: string
}
🔍 Click to Show Full Example Response
// Using DecodeWMI('WVW')
const exampleResponse = {
Count: 1,
Message: 'Results returned successfully',
Results: [
{
CommonName: 'Volkswagen',
CreatedOn: '2015-06-01',
DateAvailableToPublic: '2015-01-01',
Make: 'VOLKSWAGEN',
ManufacturerName: 'VOLKSWAGEN AG',
ParentCompanyName: '',
URL: 'volkswagenag.com',
UpdatedOn: '2022-08-08',
VehicleType: 'Passenger Car',
},
],
SearchCriteria: 'WMI:WVW',
}If doFetch is set to false
Returns the URL string that can be used to fetch the data, does not fetch the data internally.
=> Promise<string>
// ex: => 'https://vpic.nhtsa.dot.gov/api/vehicles/DecodeWMI/WVW?format=json'
💡 See: BYOF - Bring Your Own Fetch
Type - DecodeWMIResults
Ƭ DecodeWMIResults: Object
Object returned in the Results array of DecodeWMI endpoint response.
In the return object, Results will be an array with a single object of type DecodeWMIResults.
type DecodeWMIResults = {
CommonName: string
CreatedOn: string
DateAvailableToPublic: string
Make: string
ManufacturerName: string
ParentCompanyName: string
URL: string
UpdatedOn: string | null
VehicleType: string
}Examples
Examples 1-2:
Fetches data from VPIC API
Returns:
=> Promise<NhtsaResponse<DecodeWMIResults>>
Example 1: Decode WMI
import { DecodeWMI } from '@shaggytools/nhtsa-api-wrapper'
const response = await DecodeWMI('WVW')
Example 2: Decode WMI and doFetch = true
import { DecodeWMI } from '@shaggytools/nhtsa-api-wrapper'
const response = await DecodeWMI('1CG', true)
Example 3:
Does NOT fetch data from VPIC API
Returns:
=> Promise<string>
Example 3: Decode WMI and doFetch = false
import { DecodeWMI } from '@shaggytools/nhtsa-api-wrapper'
const url = await DecodeWMI('WAU', false)
// url = 'https://vpic.nhtsa.dot.gov/api/vehicles/DecodeWMI/WAU?format=json'