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][account_conditional_field_id]
optional , nil allowed

ID of expense account’s conditional field

Validations:

  • Must be a Integer

trip[conditional_values_attributes][value]
optional , nil allowed

Conditional field’s value

Validations:

  • Must be a String