Vehicle API

Fields

Field Name Unique? Validation
registration ^[a-zA-Z0-9]+$
year   ^[0-9]{4}$
transmission   ('M', 'A')
seat_number   ^[0-9]{1,2}$
fuel_type   ^[a-zA-Z0-9_ ]+$
name    
asset_no    
key_no    
body_colour    
license_type    
kms_start    
kms_current    
availability_weekend    
availability_afterhours    
comments    
vehicle_cost    
vehicle_cost_type    

Relationships

Resource 1-to-1 1-to-many many-to-1 many-to-many
make      
model      
features      
company      
branch      
cost-centre      

Operations

GET /vehicles

Returns a list of vehicle hashes. Vehicles can be filtered be the following query string parameters:

  • company
  • branch
  • cost-centre

By supplying one of the above as the query key with the ID for that resource, vehicles can be limited to those related groupings.

Operation: GET /vehicles?company=1
Itent: fetch a list of vehicles which belong to company 1
Status: 200 OK
Response body:
[{ VEHICLE HASH }, { VEHICLE HASH }, ... ]

GET /vehicle/ID

Operation: GET /vehicle/1
Intent: retrieve vehicle 1
Status: 200 OK
Response body:
{
    "id": "1",
    "location": "/vehicle/1",
    "name": "racy number",
    "registration": "rcynum",
    "year": "2014",
    "transmission": "A",
    "seat_number": "4",
    "fuel_type": "PULP",
    "body_color": "united grey",
    "license_type": "car",
    "kms_start": "14000",
    "kms_current": "128572",
    "avail_weekend": "yes",
    "avail_outofhours": "no",
    "comments": "",
    "make": { VEHICLE MAKE HASH },
    "model": { VEHICLE MODEL HASH },
    "branch": { BRANCH HASH },
    "features": { VEHICLE FEATURES HASH },
    "cost-centre": { COST-CENTRE HASH },
    "bookings.total": "17"
}

POST /vehicle

When creating a vehicle, the client may optionally supply a comma-separated list of cost-centre IDs or feature IDs (or both).

Operation: POST /vehicle
Request body:
{
    "registration": "abc123",
    "year": "1981",
    "transmission": "M",
    "seat_number": "4",
    "fuel_type": "biodiesel",
    "cost-centre_ids": "1,2",
    "feature_ids": "8,12,39"
}
Intent: create a new vehicle
Status: 201 Created
Response body: { VEHICLE HASH }

PUT /vehicle/ID

Operation: PUT /vehicle/1
Request body:
{
    "registration": "bca321"
}
Intent: update the registration datum for vehicle 1
Status: 200 OK
Response body: { VEHICLE HASH }

DELETE /vehicle/ID

Operation: DELETE /vehicle/1
Intent: delete vehicle 1
Status: 200 OK

POST /vehicle/ID/booking/DATETIMEPATH

See also

Bookings

Operation: POST /vehicle/1/booking/2014-01-01/20:00/2014-01-01/21:00
Intent: book vehicle 1 for one hour on the 1st of Jan, 2014 starting at 2000hrs
Status: 201 Created
Response body: { BOOKING HASH }

GET /vehicle/ID/bookings/DATETIMEPATH

See also

Bookings

Operation: GET /vehicle/1/booking/2014-01-01/00:00/2014-01-02/23:00
Intent: fetch bookings for vehicle 1 between midnight, 1st of Jan, 2014 and 2300hrs, 2nd of Jan, 2014
Status: 200 OK
Response body: [ { BOOKING HASH }, { BOOKING HASH }, ... ]

GET /vehicle/ID/assets

See also

Assets

GET /vehicle/ID/assets/TAG

See also

Assets

Operation: GET /vehicle/1/assets
Intent: return all assets for vehicle 1
Status: 200 OK
Response body: { ASSETS HASH }

POST /vehicle/ID/assets/TAG

See also

Assets

Operation: POST /vehicle/1/assets/alloys
Request headers: Content-Type:image/gif
Request body: <binary JPEG data>
Intent: upload a GIF for vehicle 1 tagged "alloys"
Status: 201 Created
Response body: { ASSETS HASH }

POST /import/vehicles

Accepts CSV data and creates one vehicle per row.