Api.heavytruckparts.net

From ISoft Wiki
Revision as of 15:19, 4 February 2016 by Broy (talk | contribs) (Added notes for "skipping" search terms and requesting lists for available part types, manufacturers, and models.)
Jump to navigationJump to search

API access can be provided to the HeavyTruckParts.Net data store. The API can be a convenient way to provide access to search results or to a customer's inventory on HTP.Net.

RESTful Service

The API is a RESTful service. That means that requests to it work just like making a request to a website. You use a URL, with a possible query string to add filters to the behavior, with an HTTP method (usually GET) and the results are returned to you. Another thing to keep in mind that, as a pure RESTful service, there is NO STATE in the API. It does not have sessions, and doesn't remember anything about a request. That means that a user MUST provide authentication details with EVERY request made.

Authentication and Security

The API authenticates with a user and password (which will be pre-agreed on between ISoft and any client who wants API access) via HTTP Basic authentication. Basic authentication is not, in and of itself, secure. So to combine the ease of Basic authentication with additional security, the API requires access over HTTPS. Industry standard SSL-encryption protects every API request, so Basic authentication can be safely used.

Customized For Each API User

The API results are customized on the basis of the API user that authenticates with the API. So simply by presenting the correct user, the API will automatically determine which dataset to provide (automotive, motorcycle, yellow iron, or heavy truck). It also determines the customization for the user. The API user provides their own part types, manufacturer, and model information in a search. This information is used by the API to map to the values used by HeavyTruckParts.Net. Additionally, search results are customized by the API user, so an API user can have access to a predetermined set of vendors' inventory, with customizable default filters. An API user can be defined to prefer data in XML or JSON format; by default the API provides JSON-formatted data back to the API user.

Customized For End Users

The API can accept an id for the end user -- that is, the person visiting the website of the API User or using the webapp built by the API user. Customizations-per-end-user that can be applied include custom pricing (if the id can be matched to the appropriate customerid in a vendor system), default distance sorting (if the id can be matched to a particular zip code), or special availability rules.

Making a Request

So how is a request made? Assuming that you have a valid API User and know how to make the request, providing that user and password via Basic authentication, API requests are just HTTP GET requests:

https://api.heavytruckparts.net/inventory/search/<part type>/<make or manufacturer>/<model>?<filter options>

The request should be URI escaped:

https://api.heavytruckparts.net/inventory/search/Engine%20Assembly/CUMMINS/ISX?year_range=2013,2015&zipcode=68503&distance=100
  • Part Type: The part type is specified on the URL as the first part. This may be a string or numeric value; it will be mapped to the appropriate value for HTP.Net based on your API user. This is a many-to-many mapping: You may have a part type that maps to many HTP.Net part types, or many part types that map to a single HTP.Net part type.
  • Make or Manufacturer: The vehicle make or part manufacturer for the part search, specified on the URL as the second part. This is a many-to-many mapping: You may have a manufacturer that maps to many HTP.Net manufacturers or many manufacturers that map to a single HTP.Net manufacturer.
  • Model: The vehicle or part model for the part search, specified on the URL as the third part. This is many-to-many mapping: You may have a model that maps to many HTP.Net models or many models that map to a single HTP.Net model.
  • Filter Options: An optional query string of <filter>=<value> options, separated by & symbols to add as many filter options as desired.
    • year_range: a comma separated value of "first_year,last_year" inclusive. A 0 means "all years." "year_range=0,2003" is "all years up to and including 2003.
    • zipcode: the zipcode to distance search from. By default, if a zipcode is provided, results will be sorted by distance.
    • distance: a distance in miles to limit results to. Requires zipcode to be specified, 0 means "any distance."
    • keywords: a space-separated list of keywords to perform a keyword search with. The keyword search looks for ALL keywords, but can be structured via pipe (|) operators for OR behavior. For example, keywords=(first set of search terms)|(second set of search terms)
    • userid: the end-user id, representing a person using the website or webapp which relies on the API. Pricing and other values in the results can be customized based on this value.
    • page_number: the results are separated into separate "pages" results. This value indicates which "page" in the results should be returned.
    • sort_column: the column in the results that the results should be sorted by. The default is "price," unless a zip code is specified, and then the default is "distance." Allowable values are "part_name", "make_model", "year", "oem_number", "vendor_sku", "description", "price", "coreprice", "condition", "type", "distance", and "vendor".
    • sort_order: the "direction" the sort_column should be sorted on. The default is "ascending". Allowable values are "ascending" and "descending" (or the abbreviations "asc" and "desc").

The exact search format can be customized for individual API users. In general, the search parts are "optional" but require a place holder (though in most cases, if some search parts are not used, a keyword search filter is encouraged to help narrow down search results). Due to the nature of URLs, something must be entered for each search component to form a valid URL. In a standard search URI, providing the "magic" character asterisk (*) for a search component will cause that search component to be ignored for the purposes of the search. For example,

https://api.heavytruckparts.net/inventory/search/*/FULLER/*?keywords=warranty

Results

Results are provided, by default, in JSON format, though XML results could be provided instead. Results are "paginated" or broken into "pages", just like a Google search. 25 results are provided to a page.

{results:
 total_results: the total number of results for this search,
 total_pages: the total number of search result "pages" in this search,
 [type:"(USED,NEW,REMANUFACTURED, etc...)", 
  vendor:{
   company:"company name", 
   contact:"contact person", 
   city:"city the vendor is in", 
   state:"state the vendor is in", 
   postal_code:"zip code or postal code for the vendor",
   phone_number:"the vendor's phone number", 
   fax_number:"the vendor's fax number" },
  part_name:"the part type name",
  make_model:"the make or manufacturer and model of the item",
  year:"the year of the item, if provided",
  oem_number:"any OEM number associated with the item",
  vendor_sku:"the SKU or Tag Number assigned to this item by the vendor",
  description:"the description of the item",
  price:"the retail price of the item, or a custom price for the end user, if available",
  coreprice:"the core return price on the item, if any",
  condition:"the item's condition, as described by the vendor",
  details_uri:"a URL to request for further information on this item",
  images:["an array of URLs for images associated with this item"],
  distance:"the distance of the item, in miles, from a provided zipcode",
  page_number:"the page number this item is found on"]
}

Other Requests

The API handles more than just searches. You can request details on particular inventory items or fetch the available part types, manufacturers, or models for your API user.

Item Details

An item details request provides more information on a particular item than the basic search result provides.

https://api.heavytruckparts.net/inventory/details/<vendor code>/<vendor store>/<inventory item id>

The information is provided in JSON form, just like the search results, and includes all of the important data from the search results entry as well as further information on that specific inventory item. There are "Q&A" options which are vendor specified label: value pairs. The exact data in these fields and how many there are cannot be predicted, as they are specified by the item vendor.

{part_name: 'part type name',
 year: 'year of item manufacture or production, if available',
 vehicle_make: 'make of vehicle for item, if available',
 vehicle_model: 'model of vehicle for item, if available',
 part_manufacturer: 'manufacturer of item, if available',
 part_model: 'part model of item, if available',
 oem_number: 'OEM number assigned to item',
 serial_number: 'Serial number assigned to item',
 vendor_sku: 'Vendor SKU or Tag Number',
 vin: 'VIN, if available',
 core_price: 'core return price',
 description: 'item description',
 condition: 'vendor specified item condition',
 category: 'item category, i.e. USED, NEW, REMANUFACTURED',
 side: 'side of vehicle item fits, if available and appropriate',
 'vendor_specified_option_label, for instance "HP" or "Color"': 'vendor_specified_option_value'
 ...
 vendor:{
   company:"company name", 
   contact:"contact person", 
   city:"city the vendor is in", 
   state:"state the vendor is in", 
   postal_code:"zip code or postal code for the vendor",
   phone_number:"the vendor's phone number", 
   fax_number:"the vendor's fax number" },
 images:["an array of URLs for images associated with this item"]
}

Available Lists

Requests can be made to the API to fetch the complete list of part types, make/manufacturers, and models for your API user. These results are customized to match your API user's mapping data (so the results can be used directly to produce search request URIs) and by default are limited to include just those part types, makes, manufacturers, or models that pertain to the result set returned to your API user in searches (the lists will not include part types that you wouldn't find in your search, for instance). The query string filters for specifying part types for available make/manufacturers and models, and make/manufacturers for available models are optional.

https://api.heavytruckparts.net/inventory/available/part_types
https://api.heavytruckparts.net/inventory/available/makes?part_type=<part type to filter make/manufacturers by>
https://api.heavytruckparts.net/inventory/available/models?part_type=<part type to filter models by>&make=<make/manufacturer to filter models by>

The results are, as before, specified in JSON format.

{part_types:
 ['comma separated array of part types']
}
{makes:
 ['comma separated array of makes, optionally filtered by a part type in the request']
}
{models:
 ['comma separated array of models, optionally filtered by a part type and/or a make/manufacturer in the request']
}

Things to Remember

  • The API is stateless. If you have a request for a particular end user (like custom pricing) it is your responsibility to provide that end user id, and to ensure that the correct end user id is passed in any request for that end user. If you are handling sessions for your users, session management is your responsibility; the API has no concept of sessions.
  • The API tends to use the word "make" in the requests, responses, and documentation, but except for places like the item details where vehicle_make and part_manufacturer are explicitly separated, it considers make and manufacturer (as well as vehicle model and part model) interchangeably. If you check availability for "makes" for, say, engines, which are based on part manufacturer rather than vehicle make, then the engine manufacturers will be returned in the list, not the vehicle makes of the vehicles the engines came out of.