Fleetio Integration Documentation

Overview

This document provides an overview of the Fleetio integration, detailing the endpoints used, fields sent for expense entries, the daily vehicle fetch process, and the logging system for active integrations and tolls.

Endpoints Used

Vehicle Endpoints

  • Fetch All Vehicles: GET https://secure.fleetio.com/api/v1/vehicles
  • Fetch Archived Vehicles: GET https://secure.fleetio.com/api/v1/vehicles/archived

Webhook Endpoints

  • Create Webhook: POST https://secure.fleetio.com/api/v1/webhooks
  • Get Webhooks: GET https://secure.fleetio.com/api/v1/webhooks
  • Delete Webhook: DELETE https://secure.fleetio.com/api/v1/webhooks/{id}

Expense Entry Endpoints

  • Expense Entry: POST https://secure.fleetio.com/api/v1/expense_entries

Expense Entry Fields

When creating expense entries, the following fields are sent. This includes custom fields that must be present on the Fleetio side:

Common Fields

  • expense_entry_type_id: The ID of the expense entry type.
  • vehicle_id: The ID of the vehicle in Fleetio.
  • occurred_at: The date and time when the expense occurred.
  • total_amount_cents: The total amount of the expense in cents.
  • total_amount: The total amount of the expense.

Custom Fields

  • plate_number: The plate number of the vehicle.
  • plate_state: The state of the vehicle’s license plate.
  • ticket_id: The ID of the ticket.
  • pin: The PIN associated with the vehicle.
  • fleet_liable: Indicates whether the fleet is liable.
  • transaction_date_time: The date and time of the transaction.
  • violation: The violation number (for parking).
  • notice_number: The notice number (for parking).
  • issuing_authority: The issuing authority of the ticket.
  • vehicle_number: The vehicle number.
  • pdf: URL to the PDF of the ticket (if available).
  • fleetit_fee: The fee charged by Fleetio (for tolls).
  • posting_date: The posting date of the transaction (for tolls).
  • exit_plaza: The exit plaza (for tolls).
  • cash_cost: The cash cost associated with the toll (for tolls).
  • agency: The agency managing the toll (for tolls).

Daily Vehicle Fetch Process

Vehicles are fetched from Fleetio once a day. The process involves fetching both active and archived vehicles using the specified endpoints. The integration checks for updates and new vehicles, processing and updating the local database accordingly.

Fetching Vehicles

  1. Fetch Active Vehicles: The system fetches all active vehicles using the https://secure.fleetio.com/api/v1/vehicles endpoint.
  2. Fetch Archived Vehicles: The system fetches all archived vehicles using the https://secure.fleetio.com/api/v1/vehicles/archived endpoint.

Logging System

Active Integration Logs

Logs for active integrations are created to track the daily vehicle fetch process. These logs include details about the number of vehicles fetched, added, updated, and any errors encountered.

Toll Logs

After sending a toll, logs are created for each toll transaction. These logs include:

  • Timestamp: When the log was created.
  • Action: Description of the action taken (e.g., “Send toll to Fleetio”).
  • Direction: Indicates whether the action was “sending” or “receiving”.
  • Success: Indicates whether the action was successful.
  • Response: Details of the response from Fleetio.
  • Payload: The data sent in the request.
  • Entity ID: The ID of the toll entity.
  • Entity Type: The type of entity (e.g., “TICKET”, “PARKING”).

Example Log Entry

{
  "timestamp": "2024-05-05T21:09:01.685651-04:00",
  "action": "Send toll to Fleetio",
  "direction": "sending",
  "success": true,
  "response": {
    "message": "Success",
    "vehicles_updated": 2,
    "new_vehicles_added": 0,
    "unable_to_find_states": 0,
    "total_vehicles_fetched": 6178,
    "belongs_to_different_fleet": 6176
  },
  "payload": {
    "expense_entry_type_id": 706773,
    "vehicle_id": "12345",
    "occurred_at": "2024-05-05T21:09:01.685651-04:00",
    "total_amount_cents": 1000,
    "total_amount": "10.00",
    "custom_fields": {
      "plate_number": "ABC123",
      "plate_state": "NY",
      "ticket_id": 1,
      "fleetit_fee": "5.00",
      "posting_date": "2024-05-05",
      "transaction_date_time": "2024-05-05 21:09:01",
      "exit_plaza": "Plaza 1",
      "cash_cost": "10.00",
      "agency": "Agency 1",
      "vehicle_number": "VN12345"
    }
  },
  "entity_id": 1,
  "entity_type": "TICKET"
}