post https://api.keeptruckin.com/v1/vehicles
Create a new vehicle
Add External Ids
To add external ids to a vehicle record just add the following to the request body. External ID represents a unique identifier for a vehicle in an external system. The name of this external system is stored as integration_name
. The combination of external_id
and integration_name
will always be unique.
{
"number":"toyota_32",
# other attributes for a vehicle
...
...
...
# add external id for vehicle
"external_ids_attributes":[
{
"external_id":"987",
"integration_name":"generic_tms"
}
]
}
require 'uri'
require 'net/http'
require 'json'
url = URI('https://api.keeptruckin.com/v1/vehicles')
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request['Authorization'] = "Bearer <OAUTH_TOKEN>"
request['Content-Type'] = 'application/json'
params = {
:company_id => 1,
:number => "Demo Vehicle",
:status => "active",
:ifta => true,
:vin => "WP0AB2966NS458669",
:make => "Demo",
:model => "Vehicle",
:year => "2016",
:license_plate_state => "CA",
:license_plate_number=> "5M37250",
:metric_units => false,
:fuel_type => "diesel",
:eld_device => {
:id => 2,
:identifier => "000074802542164638439715893965",
:model => "lbb-1"
},
:current_driver => {
:id => 11,
:first_name => "Demo",
:last_name => "Driver",
:username => "demo_driver",
:email => nil,
:driver_company_id => nil,
:status => "active",
:role => "driver"
}
}
request.body = params.to_json
response = http.request(request)
puts response.read_body