Skip to content
On this page

GetMakesForVehicleType


typescript
async function GetMakesForVehicleType(
  typeName: string,
  doFetch?: boolean
): Promise<NhtsaResponse<GetMakesForVehicleTypeResults> | string>

💡 More In Depth

See: Package Reference

Description

GetMakesForVehicleType returns all the Makes in the vPIC dataset for a specified vehicle type (typeName), whose name is LIKE the vehicle type name in vPIC Dataset.

typeName can be a partial name, or a full name for more specificity, e.g., "Vehicle", "Moto", "Low Speed Vehicle", etc.

Parameters

NameTypeDefault valueDescription
typeNamestringundefinedA partial or full vehicle type name
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 GetMakesForVehicleTypeResults objects in the Results key.

typescript
=> Promise<NhtsaResponse<GetMakesForVehicleTypeResults>>
typescript
type NhtsaResponse<GetMakesForVehicleTypeResults> = {
  Count: number
  Message: string
  Results: Array<GetMakesForVehicleTypeResults>
  SearchCriteria: string
}
🔍 Click to Show Full Example Response
ts
// Using GetMakesForVehicleType('truck') - truncated for brevity
const exampleResponse = {
  Count: 171,
  Message: 'Response returned successfully',
  Results: [
    {
      MakeId: 441,
      MakeName: 'TESLA',
      VehicleTypeId: 3,
      VehicleTypeName: 'Truck ',
    },
    {
      MakeId: 448,
      MakeName: 'TOYOTA',
      VehicleTypeId: 3,
      VehicleTypeName: 'Truck ',
    },
    {
      MakeId: 449,
      MakeName: 'MERCEDES-BENZ',
      VehicleTypeId: 3,
      VehicleTypeName: 'Truck ',
    },
    {
      MakeId: 450,
      MakeName: 'FREIGHTLINER',
      VehicleTypeId: 3,
      VehicleTypeName: 'Truck ',
    },
    {
      MakeId: 460,
      MakeName: 'FORD',
      VehicleTypeId: 3,
      VehicleTypeName: 'Truck ',
    },
    {
      MakeId: 464,
      MakeName: 'LINCOLN',
      VehicleTypeId: 3,
      VehicleTypeName: 'Truck ',
    },
    {
      MakeId: 465,
      MakeName: 'MERCURY',
      VehicleTypeId: 3,
      VehicleTypeName: 'Truck ',
    },
    {
      MakeId: 467,
      MakeName: 'CHEVROLET',
      VehicleTypeId: 3,
      VehicleTypeName: 'Truck ',
    },
    {
      MakeId: 469,
      MakeName: 'CADILLAC',
      VehicleTypeId: 3,
      VehicleTypeName: 'Truck ',
    },
    {
      MakeId: 472,
      MakeName: 'GMC',
      VehicleTypeId: 3,
      VehicleTypeName: 'Truck ',
    },
    {
      MakeId: 473,
      MakeName: 'MAZDA',
      VehicleTypeId: 3,
      VehicleTypeName: 'Truck ',
    },
    {
      MakeId: 474,
      MakeName: 'HONDA',
      VehicleTypeId: 3,
      VehicleTypeName: 'Truck ',
    },
    {
      MakeId: 475,
      MakeName: 'ACURA',
      VehicleTypeId: 3,
      VehicleTypeName: 'Truck ',
    },
    {
      MakeId: 476,
      MakeName: 'DODGE',
      VehicleTypeId: 3,
      VehicleTypeName: 'Truck ',
    },
    // ... 156 more items
  ],
  SearchCriteria: 'Vehicle Type: truck',
}

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/GetMakesForVehicleType/truck?format=json'

Type - GetMakesForVehicleTypeResults

ts
type GetMakesForVehicleTypeResults = {
  MakeId: number
  MakeName: string
  VehicleTypeId: number
  VehicleTypeName: string
}

Ƭ GetMakesForVehicleTypeResults: Object

Objects returned in the Results array of GetMakesForVehicleTypeResults endpoint response.

Examples

Example 1:

  • Fetches data from VPIC API

  • Returns:

typescript
=> Promise<NhtsaResponse<GetMakesForVehicleTypeResults>>

Example 1: Get Makes for Vehicle Type

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

const response = await GetMakesForVehicleType('truck')

Example 2:

typescript
=> Promise<string>

Example 2: Get Makes for Vehicle Type with doFetch = false

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

const url = await GetMakesForVehicleType('truck', false)

// url = 'https://vpic.nhtsa.dot.gov/api/vehicles/GetMakesForVehicleType/truck?format=json'

Released under the MIT License.