Skip to content
On this page

GetVehicleVariableValuesList


typescript
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

NameTypeDefault valueDescription
variableValuestring | numberundefinedThe variable you want to get a values list of
doFetch?booleantrueWhether to fetch the data or just return the URL (default: true)

📝 NOTE

Set doFetch to false if you want to fetch the data yourself.

Returns

Returns a Promise that resolves to a NhtsaResponse object containing an array of GetVehicleVariableValuesListResults objects in the Results key.

typescript
=> Promise<NhtsaResponse<GetVehicleVariableValuesListResults>>
typescript
type NhtsaResponse<GetVehicleVariableValuesListResults> = {
  Count: number
  Message: string
  Results: Array<GetVehicleVariableValuesListResults>
  SearchCriteria: string
}
🔍 Click to Show Full Example Response
ts
// 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.

typescript
=> Promise<string>

// ex: => 'https://vpic.nhtsa.dot.gov/api/vehicles/GetVehicleVariableValuesList/battery%20type?format=json'

Type - GetVehicleVariableValuesListResults

ts
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:

typescript
=> Promise<NhtsaResponse<GetVehicleVariableValuesListResults>>

Example 1: Get Vehicle Variable Values List by Name

ts
import { GetVehicleVariableValuesList } from '@shaggytools/nhtsa-api-wrapper'

const response = await GetVehicleVariableValuesList('battery type')

Example 2: Get Vehicle Variable Values List by Variable ID

ts
import { GetVehicleVariableValuesList } from '@shaggytools/nhtsa-api-wrapper'

const response = await GetVehicleVariableValuesList(1)

Examples 3-4:

typescript
=> Promise<string>

Example 3: Get Vehicle Variable Values List by Name and doFetch = false

ts
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

ts
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'

Released under the MIT License.