How to Set Up the AirTrail Addon for Flight Import Integration in TREK
Enable the AirTrail addon globally in the Admin panel, configure your self-hosted instance URL and API key in Settings, then import flights directly into trips using the dedicated REST endpoints.
TREK is an open-source travel management platform that integrates with self-hosted AirTrail instances through a dedicated addon. This integration allows users to import flight data directly into trip reservations and optionally synchronize changes back to AirTrail. The setup involves three distinct layers: global addon registration, per-user credential configuration, and flight import processing.
Enable the AirTrail Addon Globally
Administrators must activate the AirTrail addon before any user can access the integration. The addon definition is hard-coded in [server/src/db/seeds.ts](https://github.com/mauriceboe/TREK/blob/main/server/src/db/seeds.ts) (line 106) and registered in [server/src/addons.ts](https://github.com/mauriceboe/TREK/blob/main/server/src/addons.ts) (line 10).
- Navigate to Admin → Add‑ons in the TREK interface.
- Locate AirTrail (description: Sync flights from your self‑hosted AirTrail instance).
- Toggle the addon ON and save.
When disabled, the addon’s enabled flag in the addons table hides all related UI components and API routes automatically.
Configure Per-User AirTrail Connections
Each user must provide their AirTrail instance credentials to establish connectivity. The configuration schema is defined in [shared/src/airtrail/airtrail.schema.ts](https://github.com/mauriceboe/TREK/blob/main/shared/src/airtrail/airtrail.schema.ts) and validated against airtrailSettingsSchema.
-
Go to Settings → Integrations → AirTrail.
-
Configure the following fields:
- Instance URL: Your self‑hosted AirTrail address (e.g.,
https://flights.example.com). The server automatically appends/apito this URL. - API key: Bearer token generated in AirTrail under Settings → Security.
- Allow insecure TLS: Enable only for LAN instances using self‑signed certificates.
- Write back changes: Optional flag (
writeEnabled) that pushes TREK reservation edits back to AirTrail.
- Instance URL: Your self‑hosted AirTrail address (e.g.,
-
Click Save to send a
POST /api/integrations/airtrailrequest. The payload is validated and stored in theuserstable, with theairtrail_api_keyencrypted at rest. -
Click Test connection to verify connectivity via
GET /api/integrations/airtrail. The endpoint returns connection status and flight count, displaying the API key masked as••••••••(enforced byAIRTRAIL_KEY_MASKat line 15).
Import Flights into Trips
Once configured, users can import flights into specific trips using the import endpoints defined in [server/src/nest/integrations/airtrail-import.controller.ts](https://github.com/mauriceboe/TREK/blob/main/server/src/nest/integrations/airtrail-import.controller.ts).
- Open a trip and navigate to the Reservations tab.
- Select Import → AirTrail. The UI fetches available flights via
GET /api/integrations/airtrail, which internally callslistFlightsinairtrailClient.ts. - Select desired flights and confirm. The client sends
POST /api/trips/:tripId/reservations/import/airtrailwith a payload matchingairtrailImportSchema(array of flight IDs). - The controller invokes
importAirtrailFlightsfrom [server/src/services/airtrail/airtrailService.ts](https://github.com/mauriceboe/TREK/blob/main/server/src/services/airtrail/airtrailService.ts`), which:- Retrieves credentials via
getAirtrailCredentials. - Maps flights to reservations using
airtrailMapper.mapFlightToReservation. - Inserts
Reservationrecords (typeflight) into thereservationstable.
- Retrieves credentials via
The response follows airtrailImportResultSchema, showing successfully imported IDs and skipped entries with reasons (e.g., already-imported).
Optional Background Sync and Write-Back
TREK supports bidirectional synchronization when write‑back is enabled.
- Real‑time write‑back: When
writeEnabledis true, edits to imported reservations triggerpushReservationToAirtrailin [server/src/services/airtrail/airtrailSync.ts](https://github.com/mauriceboe/TREK/blob/main/server/src/services/airtrail/airtrailSync.ts), posting updates to the AirTrail API. - Scheduled polling: The background task
airtrailSyncTaskin [server/src/scheduler.ts](https://github.com/mauriceboe/TREK/blob/main/server/src/scheduler.ts) polls for new flights at intervals defined by theairtrail_poll_interval_minutessetting.
Code Examples
Enable the Addon via API
curl -X PATCH https://trek.example.com/api/admin/addons \
-H "Authorization: Bearer <ADMIN_JWT>" \
-H "Content-Type: application/json" \
-d '{"id":"airtrail","enabled":true}'
Configure User Credentials
curl -X POST https://trek.example.com/api/integrations/airtrail \
-H "Authorization: Bearer <USER_JWT>" \
-H "Content-Type: application/json" \
-d '{
"url": "https://flights.myselfhosted.com",
"apiKey": "my-bearer-token",
"allowInsecureTls": false,
"writeEnabled": true
}'
Test the Connection
curl -X GET https://trek.example.com/api/integrations/airtrail \
-H "Authorization: Bearer <USER_JWT>"
Successful response:
{
"connected": true,
"flightCount": 12,
"url": "https://flights.myselfhosted.com",
"apiKeyMasked": "••••••••",
"allowInsecureTls": false,
"writeEnabled": true
}
Import Flights into a Trip
curl -X POST https://trek.example.com/api/trips/42/reservations/import/airtrail \
-H "Authorization: Bearer <USER_JWT>" \
-H "Content-Type: application/json" \
-d '{
"flightIds": ["f123", "f456"]
}'
Response example:
{
"imported": ["f123"],
"skipped": [
{
"flightId": "f456",
"reason": "already-imported",
"detail": "Flight already present in this trip"
}
]
}
Push Updates Back to AirTrail (Write-Back)
import { pushReservationToAirtrail } from '@trek/server/src/services/airtrail/airtrailSync';
await pushReservationToAirtrail({
reservationId: 789,
tripId: 42,
airline: 'Swiss',
flightNumber: 'LX123',
departure: '2026-09-01T10:00:00Z',
arrival: '2026-09-01T13:00:00Z'
});
Summary
- Global enablement is required first via the Admin panel, registering the addon in the database seeds.
- Per-user configuration stores encrypted credentials in the
userstable, validated againstairtrailSettingsSchema. - Flight import uses
POST /api/trips/:tripId/reservations/import/airtrailto create reservations from AirTrail data. - Bidirectional sync is available through the write‑back flag and background scheduler tasks.
Frequently Asked Questions
How do I enable the AirTrail addon in TREK?
Administrators must navigate to Admin → Add‑ons and toggle AirTrail to ON. This updates the enabled flag in the addons table and exposes the integration routes defined in [server/src/nest/integrations/airtrail.controller.ts](https://github.com/mauriceboe/TREK/blob/main/server/src/nest/integrations/airtrail.controller.ts).
Where are AirTrail credentials stored in TREK?
User credentials are stored in the users table with the API key encrypted. The schema definition in [shared/src/airtrail/airtrail.schema.ts](https://github.com/mauriceboe/TREK/blob/main/shared/src/airtrail/airtrail.schema.ts) defines the structure, while [server/src/services/airtrail/airtrailService.ts](https://github.com/mauriceboe/TREK/blob/main/server/src/services/airtrail/airtrailService.ts) handles retrieval through getAirtrailCredentials.
Can TREK sync flight changes back to AirTrail?
Yes. When the Write back changes option is enabled during configuration, TREK invokes pushReservationToAirtrail from [server/src/services/airtrail/airtrailSync.ts](https://github.com/mauriceboe/TREK/blob/main/server/src/services/airtrail/airtrailSync.ts) whenever you edit imported reservations, pushing updates to your AirTrail instance via its REST API.
What happens if I disable the AirTrail addon after configuring it?
Disabling the addon hides all AirTrail UI elements and API routes immediately, though existing imported reservations remain in the database. Users cannot import new flights or sync changes until the addon is re‑enabled by an administrator.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →