GetVehicleVariableValuesList
async function GetVehicleVariableValuesList(
variableValue: number | string,
doFetch?: boolean
): Promise<NhtsaResponse<GetVehicleVariableValuesListResults> | string>
💡 More In Depth
See: Package Reference
Description
GetVehicleVariableValuesList
provides a list of all the accepted values for a given variable that are stored in the vPIC dataset.
If variableValue
is a string, it must use full name, not just part of it, e.g., "Battery Type", not "Battery"
variableValue
can be also be a number, which is the ID of the variable, e.g., 1, 2, 3, etc.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
variableValue | string | number | undefined | The variable you want to get a values list of |
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 NhtsaResponse object containing an array of GetVehicleVariableValuesListResults objects in the Results
key.
=> Promise<NhtsaResponse<GetVehicleVariableValuesListResults>>
type NhtsaResponse<GetVehicleVariableValuesListResults> = {
Count: number
Message: string
Results: Array<GetVehicleVariableValuesListResults>
SearchCriteria: string
}
🔍 Click to Show Full Example Response
// Using GetVehicleVariableValuesList('battery type')
const exampleResponse = {
Count: 9,
Message: 'Results returned successfully',
Results: [
{
ElementName: 'Battery Type',
Id: 1,
Name: 'Lead Acid/Lead',
},
{
ElementName: 'Battery Type',
Id: 2,
Name: 'Nickel-Metal-Hydride/NiMH',
},
{
ElementName: 'Battery Type',
Id: 3,
Name: 'Lithium-Ion/Li-Ion',
},
{
ElementName: 'Battery Type',
Id: 4,
Name: 'Cobalt Dioxide/Cobalt',
},
{
ElementName: 'Battery Type',
Id: 5,
Name: 'Nickle-Cobalt-Manganese/NCM',
},
{
ElementName: 'Battery Type',
Id: 6,
Name: 'Nickle-Cobalt-Aluminum/NCA',
},
{
ElementName: 'Battery Type',
Id: 7,
Name: 'Manganese Oxide Spinel/MnO',
},
{
ElementName: 'Battery Type',
Id: 8,
Name: 'Iron Phosphate/FePo',
},
{
ElementName: 'Battery Type',
Id: 9,
Name: 'Silicon',
},
],
SearchCriteria: 'Variable:battery type',
}
If doFetch
is set to false
Returns a 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/GetVehicleVariableValuesList/battery%20type?format=json'
💡 See: BYOF - Bring Your Own Fetch
Type - GetVehicleVariableValuesListResults
type GetVehicleVariableValuesListResults = {
ElementName: string
Id: number
Name: string
}
Ƭ GetVehicleVariableValuesListResults: Object
Objects returned in the Results
array of GetVehicleVariableValuesList
endpoint response.
Examples
Examples 1-2:
Fetches data from VPIC API
Returns:
=> Promise<NhtsaResponse<GetVehicleVariableValuesListResults>>
Example 1: Get Vehicle Variable Values List by Name
import { GetVehicleVariableValuesList } from '@shaggytools/nhtsa-api-wrapper'
const response = await GetVehicleVariableValuesList('battery type')
Example 2: Get Vehicle Variable Values List by Variable ID
import { GetVehicleVariableValuesList } from '@shaggytools/nhtsa-api-wrapper'
const response = await GetVehicleVariableValuesList(1)
Examples 3-4:
Does NOT fetch data from VPIC API
Returns:
=> Promise<string>
Example 3: Get Vehicle Variable Values List by Name and doFetch = false
import { GetVehicleVariableValuesList } from '@shaggytools/nhtsa-api-wrapper'
const url = await GetVehicleVariableValuesList('battery type', false)
// url: 'https://vpic.nhtsa.dot.gov/api/vehicles/GetVehicleVariableValuesList/battery%20type?format=json'
Example 4: Get Vehicle Variable Values List by Variable ID and doFetch = false
import { GetVehicleVariableValuesList } from '@shaggytools/nhtsa-api-wrapper'
const url = await GetVehicleVariableValuesList(1, false)
// url: 'https://vpic.nhtsa.dot.gov/api/vehicles/GetVehicleVariableValuesList/1?format=json'