GET /api/trips/:id
Show trip details


PUT /api/trips/:id/approve
Approve trip. If trip params are present, updates the trip before approval

Approves expense. If params of the expense are present, updates the expense before approval


POST /api/trips/:id/disapprove
Disapprove trip

Disapprove expense with a comment

Params

Param name Description
comment
optional

The reason of expense disapproval; will be displayed to user

Validations:

  • Must be a String


GET /api/trips/:id/conditional_values
Get values for the conditional fields of the trip


GET /api/trips
Get the list of trips

Get the list of all trips accessible by the current user. Can be paginated and/or filtered by trip state

Examples

GET /api/trips
200
[
  {
    "id": 1,
    "description": "MyText",
    "_id": "trip-1",
    "user_name": "Wellington Nikolaus IV",
    "state": "queue",
    "user_id": 4,
    "type": "trip",
    "updated_at": "2021-05-26T20:11:19.064Z",
    "cost_center_ids": [],
    "date": "2021-05-26",
    "approvers": [],
    "approved_by": null,
    "approved_by_ids": [],
    "current_approvers_ids": [],
    "transaction_approvers": [],
    "created_at": "2021-05-26T20:11:19.064Z",
    "company_id": 2,
    "paid_at": null,
    "taxable": 1.0,
    "mileage_vehicle_id": 1,
    "cost_center_id": 0,
    "user": {
      "id": 4,
      "name": "Wellington Nikolaus IV",
      "email": "quinten@bernhardward.name",
      "country": {
        "id": 2,
        "name": "quam exercitationem a",
        "currency": "EUR",
        "currency_symbol": "€"
      }
    },
    "cost_centers": [],
    "comments": [],
    "entries": [
      {
        "id": 1,
        "trip_transaction_id": 1,
        "distance": 10.0,
        "number_of_people": "1",
        "cost_cents": 100,
        "cost_currency": "EUR",
        "original_amount_cents": 100,
        "original_amount_currency": "EUR",
        "route": null,
        "emissions": "16.6639"
      }
    ],
    "vehicle": {
      "id": 1,
      "name": "id",
      "country": {
        "id": 3,
        "name": "et dolores ut",
        "currency": "EUR",
        "created_at": "2021-05-26T20:11:18.944Z",
        "updated_at": "2021-05-26T20:11:18.944Z",
        "code": null
      },
      "years": [
        {
          "id": 1,
          "year": 2021,
          "cost_cents": "10.0",
          "additional_passenger_cents": "0.0"
        }
      ]
    },
    "documents": []
  }
]

Params

Param name Description
archived_after
optional

Return only trips accounted on and after the supplied date. Date format: YYYYMMDD (example: 20180702)

Validations:

  • Must be a String

page
optional

Return only one page of trips. Default per-page is 10

Validations:

  • Must be a Integer

per_page
optional

Number of trips returned per page. Works only in combination with “page” param. Default value is 10

Validations:

  • Must be a Integer

state
optional

Validations:

  • Must be one of: draft, reviewing, unapproved, queue, accounting.


POST /api/trips
Create a new trip (aka mileage)

Creates a new trip.

Examples

POST /api/trips
{
  "state": "draft",
  "date": "2021-05-26",
  "user_id": 1,
  "company_id": 17,
  "mileage_vehicle_id": 9,
  "currency": "EUR",
  "original_currency": "EUR",
  "description": "Test trip",
  "cost_center_ids": [
    691
  ],
  "entries_attributes": [
    {
      "number_of_people": "John Smith",
      "distance": "300"
    },
    {
      "number_of_people": "1",
      "distance": "200",
      "waypoints_attributtes": [
        {
          "position": 0,
          "address": "Amsterdam",
          "latitude": 52.3675734,
          "longitude": 4.9041389
        },
        {
          "position": 1,
          "address": "The Hague",
          "latitude": 52.0704978,
          "longitude": 4.3006999
        }
      ]
    }
  ]
}
201
{
  "id": 115,
  "description": "Test trip",
  "_id": "trip-115",
  "user_name": "HackH",
  "state": "queue",
  "user_id": 1,
  "type": "trip",
  "updated_at": "2021-05-26T20:28:21.257Z",
  "cost_center_ids": [
    691
  ],
  "date": "2021-05-26",
  "approvers": [],
  "approved_by": [],
  "approved_by_ids": [],
  "current_approvers_ids": [],
  "transaction_approvers": [],
  "created_at": "2021-05-26T20:28:21.257Z",
  "company_id": 17,
  "paid_at": null,
  "taxable": 135.0,
  "mileage_vehicle_id": 9,
  "cost_center_id": 0,
  "user": {
    "id": 1,
    "name": "HackH",
    "email": "buru@hack.com",
    "country": {
      "id": 3,
      "name": "Sweden",
      "currency": "SEK",
      "currency_symbol": "kr"
    }
  },
  "cost_centers": [
    {
      "id": 691,
      "name": "Ololo CC",
      "dimension_name": "Cost Center",
      "assignee_ids": [],
      "deactivated": false,
      "external_id": "”06”",
      "approvers": []
    }
  ],
  "comments": [],
  "entries": [
    {
      "id": 118,
      "trip_transaction_id": 115,
      "distance": 300.0,
      "number_of_people": "John Smith",
      "cost_cents": 13500,
      "cost_currency": "EUR",
      "original_amount_cents": 13500,
      "original_amount_currency": "EUR",
      "route": null
    }
  ],
  "vehicle": {
    "id": 9,
    "name": "Autolla (0.43 EUR/km)",
    "country": {
      "id": 1,
      "name": "Finland",
      "currency": "EUR",
      "created_at": "2017-09-06T11:51:21.283Z",
      "updated_at": "2021-01-15T18:09:35.537Z",
      "code": "FI"
    },
    "years": [
      {
        "id": 18,
        "year": 2019,
        "cost_cents": "43.0",
        "additional_passenger_cents": "0.0"
      },
      {
        "id": 28,
        "year": 2020,
        "cost_cents": "43.0",
        "additional_passenger_cents": "0.0"
      },
      {
        "id": 30,
        "year": 2021,
        "cost_cents": "45.0",
        "additional_passenger_cents": "1.0"
      }
    ]
  },
  "documents": []
}

Params

Param name Description
draft
optional

Whether created trip should be in draft state. If the value of this param is 1, trip will be saved as draft and will not be validated; otherwise, it will be either in reviewing or queue state (depending on whether its user has approvers or not).

Validations:

  • Must be a Integer

trip
required

Trip hash

Validations:

  • Must be a Hash

trip[description]
required

Trip description

Validations:

  • Must be a String

trip[date]
required

Trip date, e.g. “2021-05-26”

Validations:

  • Must be a String

trip[mileage_vehicle_id]
required

Mileage vehicle (from user/company mileage vehicle categories)

Validations:

  • Must be a Integer

trip[expense_account_id]
optional , nil allowed

Mileage account (from user/company settings). Will be set automatically if not passed

Validations:

  • Must be a Integer

trip[cost_center_ids]
optional , nil allowed

Cost center IDs. Should be up to 1 cost center ID per dimension. All optional

Validations:

  • Must be an array of Integer

trip[original_currency]
required

Mileage vehicle country currency, e.g. “EUR”

Validations:

  • Must be a String

trip[entries_attributes]
required

Trip entries. At least one should be present

Validations:

  • Must be an Array of nested elements

trip[entries_attributes][number_of_people]
required

Either a number, e.g. “2” or a comma-separated list of passengers, e.g. “Brian Kernigan,Dennis Ritchie,Ken Thompson”

Validations:

  • Must be a String

trip[entries_attributes][distance]
required

Trip distance in kilometers

Validations:

  • Must be a Integer

trip[entries_attributes][route]
optional , nil allowed

An optional route description. E.g. “Helsinki-Vantaa-Helsinki”

Validations:

  • Must be a String

trip[entries_attributes][waypoints_attributes]
optional , nil allowed

Entry Waypoints. At least 2 are required when present

Validations:

  • Must be an Array of nested elements

trip[entries_attributes][waypoints_attributes][address]
optional , nil allowed

Address: short place name, from Google Maps. Internal use only.

Validations:

  • Must be a String

trip[entries_attributes][waypoints_attributes][latitude]
optional , nil allowed

Geographic Latitude from Google Maps

Validations:

  • Must be a decimal number.

trip[entries_attributes][waypoints_attributes][longitude]
optional , nil allowed

Geographic Longitude from Google Maps

Validations:

  • Must be a decimal number.

trip[entries_attributes][waypoints_attributes][position]
optional , nil allowed

Waypoint position starting from 0. E.g. case with from-to waypoints: 0 for From waypoint, 1 for To waypoint

Validations:

  • Must be a Integer

trip[conditional_values_attributes]
optional , nil allowed

Values for expense account’s conditional fields (optional)

Validations:

  • Must be an Array of nested elements

trip[conditional_values_attributes][field_id]
optional , nil allowed

ID of expense account’s conditional field

Validations:

  • Must be a Integer

trip[conditional_values_attributes][field_type]
optional , nil allowed

Field type: Account::ConditionalField or ExpenseCategory::ConditionalField

Validations:

  • Must be a String

trip[conditional_values_attributes][value]
optional , nil allowed

Conditional field’s value

Validations:

  • Must be a String


POST /api/trips/calculate_cost
Get the cost of the trip

Get the total cost, mileage cost, and additional passengers cost of the trip in cents, based on vehilcle_id, entries’ distance and number_of_people.

Examples

[
  {
    "vehicle_id": 1,
    "date": "2021-05-26",
    "entries": [
      {
        "number_of_people": "Jim, Pam",
        "distance": "12.5"
      },
      {
        "number_of_people": "1",
        "distance": "12"
      }
    ],
  }
] 

Params

Param name Description
vehicle_id
required

Mileage vehicle (from user/company mileage vehicle categories)

Validations:

  • Must be a Integer

date
required

Trip date, e.g. “2021-05-26”

Validations:

  • Must be a String

entries
required

An array with the specific entry attributes (number_of_people, distance) to pass to calculator. At least one item should be present in array

Validations:

  • Must be an Array of nested elements

entries[number_of_people]
required

Either a number, e.g. “2” or a comma-separated list of passengers, e.g. “Brian Kernigan,Dennis Ritchie,Ken Thompson”

Validations:

  • Must be a String

entries[distance]
required

Trip distance in kilometers

Validations:

  • Must be a Integer

Returns

Code: 200

Description:

Trip costs break down in cents

Param name Description
mileage
required

Mileage cost of the trip.

Validations:

  • Must be a Integer

additional_passengers
required

Additional passengers cost of the trip.

Validations:

  • Must be a Integer

total_including_tax
required

Total cost of the trip, including tax.

Validations:

  • Must be a Integer

tax
required

Total tax.

Validations:

  • Must be a Integer

total_to_reimburse
required

Total cost of the trip excluding tax.

Validations:

  • Must be a Integer

total
required

Total cost of the trip. The same value as in total_including_tax.

Validations:

  • Must be a Integer

emissions
required

CO₂ emissions estimate (in kg CO₂e).

Validations:

  • Must be a Float