Skip to content
On this page

GetParts


typescript
async function GetParts(
  params?:
    | {
        manufacturer?: string | number
        type?: 565 | 566
        fromDate?: string
        toDate?: string
        page?: string | number
      }
    | boolean,
  doFetch?: boolean
): Promise<NhtsaResponse<GetPartsResults> | string>

💡 More In Depth

See: Package Reference

Description

GetParts provides a list of ORGs with letter date in the given range of the dates and with specified Type (params.type) of ORG.

  • Up to 1000 results will be returned at a time.
  • Get the next page by incrementing the params.page query parameter.

All query params are optional.

params.manufacturer:

  • (optional) if supplied value is a number - method will do exact match on Manufacturer's Id
  • if supplied value is a string - it will look for manufacturers whose name is LIKE the provided name
  • it accepts a partial manufacturer name as an input
  • multiple results are returned in case of multiple matches
  • manufacturer name can be a partial name, or a full name for more specificity, e.g., "988", "HONDA", "HONDA OF CANADA MFG., INC.", etc.

params.type:

  • (optional) number, 565 (Vehicle Identification Number Guidance, based on 49 CFR Part 565) or 566 (Manufacturer Identification – Reporting Requirements based on 49 CFR Part 566)

params.fromDate:

  • (optional) ORG's Letter Date should be on or after this date

params.toDate:

  • (optional) ORG's Letter Date should be on or before this date

params.page:

  • (optional) number, 1 (default) first 1000 records, 2 - next 1000 records, etc

Parameters

NameTypeDefault ValueDescription
params?Object | boolean undefinedObject of query search names and values to append to the URL as a query string.
params.manufacturer?string | numberundefinedManufacturer Name or ID
params.type?565 | 566undefinedSpecified type of ORG to search
params.fromDate?stringundefinedStart date of search query
params.toDate?stringundefinedEnd date of search query
params.page?string | numberundefinedWhich page number of results to request (up to 1000 results per page)
doFetchbooleantrueWhether to fetch the data or just return the URL (default: true)

📝 NOTE

Any params that are not listed in the table above will be ignored.

As params is optional, it also has type | boolean, so you can set doFetch without having to pass undefined in place of intentionally undefined params.

Returns

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

typescript
=> Promise<NhtsaResponse<GetPartsResults>>
typescript
type NhtsaResponse<GetPartsResults> = {
  Count: number
  Message: string
  Results: Array<GetPartsResults>
  SearchCriteria: string
}
🔍 Click to Show Full Example Response
ts
// Using GetParts({ type: 575, fromDate: '1/1/2015, toDate: `5/5/2015', manufacturer: hon })
const exampleResponse = {
  Count: 6,
  Message: 'Results returned successfully',
  Results: [
    {
      CoverLetterURL: '',
      LetterDate: '4/30/2015',
      ManufacturerId: 987,
      ManufacturerName: 'HONDA MOTOR CO., LTD',
      ModelYearFrom: null,
      ModelYearTo: null,
      Name: 'ORG10655',
      Type: '565',
      URL: 'http://vpic.nhtsa.dot.gov/mid/home/displayfile/cf88fcd6-97e5-4b9a-bc6c-53f87eaf4ab3',
    },
    {
      CoverLetterURL: '',
      LetterDate: '3/11/2015',
      ManufacturerId: 988,
      ManufacturerName: 'AMERICAN HONDA MOTOR CO., INC.',
      ModelYearFrom: null,
      ModelYearTo: null,
      Name: 'ORG10720',
      Type: '565',
      URL: 'http://vpic.nhtsa.dot.gov/mid/home/displayfile/0d1c7d12-b3d9-4a53-9d2c-56ab2b5ac235',
    },
    {
      CoverLetterURL: '',
      LetterDate: '3/11/2015',
      ManufacturerId: 988,
      ManufacturerName: 'AMERICAN HONDA MOTOR CO., INC.',
      ModelYearFrom: null,
      ModelYearTo: null,
      Name: 'ORG10721',
      Type: '565',
      URL: 'http://vpic.nhtsa.dot.gov/mid/home/displayfile/3fee1b5a-c834-4074-8f03-6e1b73516ee0',
    },
    {
      CoverLetterURL: '',
      LetterDate: '3/4/2015',
      ManufacturerId: 14236,
      ManufacturerName: 'CHONGQING SHINERAY MOTORCYCLE CO., LTD.',
      ModelYearFrom: null,
      ModelYearTo: null,
      Name: 'ORG11082',
      Type: '565',
      URL: 'http://vpic.nhtsa.dot.gov/mid/home/displayfile/f9a0be8f-e887-4491-acb1-f7bcdea9a26f',
    },
    {
      CoverLetterURL: '',
      LetterDate: '2/26/2015',
      ManufacturerId: 988,
      ManufacturerName: 'AMERICAN HONDA MOTOR CO., INC.',
      ModelYearFrom: null,
      ModelYearTo: null,
      Name: 'ORG10727',
      Type: '565',
      URL: 'http://vpic.nhtsa.dot.gov/mid/home/displayfile/71f28292-1daf-4c6e-8cf1-6a9785489ad9',
    },
    {
      CoverLetterURL: '',
      LetterDate: '1/28/2015',
      ManufacturerId: 987,
      ManufacturerName: 'HONDA MOTOR CO., LTD',
      ModelYearFrom: null,
      ModelYearTo: null,
      Name: 'ORG10651',
      Type: '565',
      URL: 'http://vpic.nhtsa.dot.gov/mid/home/displayfile/e591547b-0c65-4d7c-9803-00202c70868f',
    },
  ],
  SearchCriteria:
    'Type: 565 | From Date: 1/1/2015 | To Date: 5/5/2015 | manufacturer: hon',
}

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/GetParts?type=565&fromDate=1/1/2015&toDate=5/5/2015&manufacturer=honda&page=1format=json'

Type - GetPartsResults

ts
type GetPartsResults = {
  CoverLetterURL: string
  LetterDate: string
  ManufacturerId: number
  ManufacturerName: string
  ModelYearFrom: number | null
  ModelYearTo: number | null
  Name: string
  Type: string
  URL: string
}

Ƭ GetPartsResults: Object

Objects returned in the Results array of GetParts endpoint response.

Examples

Examples 1-2:

  • Fetches data from VPIC API

  • Returns:

typescript
=> Promise<NhtsaResponse<GetPartsResults>>

Example 1: Get Parts

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

const response = await GetParts()

Example 2: Get Parts With Optional Params

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

const response = await GetParts({
  type: 565,
  fromDate: '2019-01-01',
  toDate: '2019-12-31',
  manufacturer: 'honda',
  page: 1,
})

Examples 3-4:

typescript
=> Promise<string>

Example 3: Get Parts and doFetch = false

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

const url = await GetParts(false)

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

Example 4: Get Parts With Optional Params and doFetch = false

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

const url = await GetParts(
  {
    type: 565,
    fromDate: '1/1/2015',
    toDate: '5/5/2015',
    manufacturer: 'honda',
    page: 2,
  },
  false
)

// url = 'https://vpic.nhtsa.dot.gov/api/vehicles/GetParts?type=565&fromDate=1/1/2015&toDate=5/5/2015&manufacturer=honda&page=2format=json'

Released under the MIT License.