Skip to main content

Train Booking

The Train Booking API lets you discover train stations, search available SGR train trips, retrieve cabin, fare, and seat information, hold selected seats, and create SGR train reservations.

Overview

The Train Booking API currently provides:

  • SGR station discovery for origin and destination selection
  • Train search between two stations on a travel date
  • Trip details including route, departure and arrival times, price, stop times, railway cars, and operator details
  • Cabin, passenger-type pricing, seat map, and booking requirement details for a selected train
  • Seat hold and release for seat-selection flows
  • Reservation creation for one-way and return SGR journeys, with a 15-minute Safiri payment window

Authentication

Train search and train details are protected Safiri Booking API endpoints and require JWT authentication. Obtain a JWT token by logging in through the /api/logon endpoint.

note

For detailed information on authenticating and obtaining a token, see the Authentication guide.

The train station list is served by the train GTFS API and can be used to populate station pickers before calling the protected booking API.

Headers

Required for train search, train details, seat hold/release, and reservation:

  • Authorization: Bearer <JWT_TOKEN> - Your JWT authentication token

Optional:

  • Content-Language: <language_code> - Language for responses (default: en)
  • Content-Currency: <currency_code> - Preferred display currency where supported. Train responses return the base price.currency and formatted values in price.otherCurrencies.

Wallet Charges for Third-Party Agents

Train booking integrations are intended for third-party agents using a pre-funded Safiri wallet. The API returns Safiri's payable amount separately from whatever retail amount you decide to charge your own customer.

Safiri deducts the returned train payable amount from your wallet:

ComponentWhere to find itDescription
Transporter feeprice.fees[] where type is TRANSPORTER; also price.totalThe TRC train fare payable to the transporter.
Safiri feeprice.fees[] where type is SAFIRI_COMMISSIONSafiri's fee for the booking.
Wallet debitprice.grandTotalThe amount Safiri charges to your wallet for that train ticket. This is the transporter fee plus Safiri-controlled fees returned in price.fees.

You can charge your customer any additional agency, service, or handling fee on top of price.grandTotal. That extra customer-facing markup is managed by your own system; do not send it in the train booking request, and Safiri does not deduct it from your wallet.

For example, if the API returns price.total of 22500, SAFIRI_COMMISSION of 2000, and price.grandTotal of 24500, Safiri will deduct 24500 from your wallet. If you charge your customer 26000, the extra 1500 is your own markup outside the Safiri wallet debit.

Endpoints

Get Train Stations

Retrieve SGR stations and their Safiri stop IDs. Use the returned stop_id values as the from and to query parameters when searching for trains.

Endpoint: GET https://train-gtfs-api.safiri.app/api/stops?mini=true

Example Request:

GET https://train-gtfs-api.safiri.app/api/stops?mini=true

Query Parameters

ParameterTypeRequiredDescription
minibooleanNoWhen true, returns the compact station payload used by search and autocomplete flows.

Response Fields

FieldTypeDescription
stop_idstringSafiri stop ID. Use this exact value in train search, for example DARESALAAM:SGR:0.
stop_latnumberStation latitude.
stop_lonnumberStation longitude.
stop_namestringHuman-readable station name.
stop_descstringStation location or address description.
stop_timezonestringIANA timezone for the station.
city_geohashstringGeohash used for station clustering and spatial search.
popularitynumberRanking value used by search and selection UIs.
partnersarrayProvider metadata. For SGR train search, use stops with a TRC partner whose service is SGR.
Example response
[
{
"stop_id": "DARESALAAM:SGR:0",
"stop_lat": -6.82488714,
"stop_lon": 39.2830351,
"stop_name": "Dar es Salaam (John Magufuli SGR Station)",
"stop_desc": "Kisutu, Ilala, Dar es Salaam, Tanzania",
"stop_timezone": "Africa/Dar_es_Salaam",
"city_geohash": "kygcjv",
"popularity": 30,
"partners": [
{
"provider": "TRC",
"service": "SGR",
"id": 1,
"name": "Dar Es Salaam"
}
]
},
{
"stop_id": "DODOMA:SGR:0",
"stop_lat": -6.21138079,
"stop_lon": 35.73413998,
"stop_name": "Dodoma (Samia SGR Station)",
"stop_desc": "Dodoma, Tanzania",
"stop_timezone": "Africa/Dar_es_Salaam",
"city_geohash": "kycktj",
"popularity": 30,
"partners": [
{
"provider": "TRC",
"service": "SGR",
"id": 12,
"name": "Dodoma"
}
]
}
]

Search for Trains

Search for available SGR train trips between two train stations on a travel date.

Endpoint: GET /api/trip/train/search

Example Request:

GET /api/trip/train/search?from=DARESALAAM:SGR:0&to=MOROGORO:SGR:0&date=2026-06-10

Query Parameters

ParameterTypeRequiredDescription
fromstringYesOrigin station stop_id from the train stops endpoint. Example: DARESALAAM:SGR:0.
tostringYesDestination station stop_id from the train stops endpoint. Example: MOROGORO:SGR:0.
datestringYesTravel date in YYYY-MM-DD format.
Example response
{
"meta": {
"count": 6,
"provider": "TRC_SGR",
"links": {
"self": "https://booking-api.safiri.app/api/trip/train/search?from=DARESALAAM%3ASGR%3A0&to=MOROGORO%3ASGR%3A0&date=2026-06-10"
},
"createdAt": "2026-06-10T01:29:53.925Z"
},
"data": [
{
"provider": "TRC_SGR",
"trip": {
"id": 98,
"name": "DAR - DOM \\ EXPRESS",
"number": "11902",
"trainSetId": 20,
"timeTableId": 299,
"timeTableTrainSetId": 8537,
"gtfsTripId": "SASGR002:O",
"headsign": "Dodoma via Pugu, Soga, Ruvu, Ngerengere, Morogoro, Mkata, Kilosa, Kidete, Gulwe, Igandu",
"wheelchairAccessible": 1,
"bikesAllowed": null
},
"route": {
"id": 68,
"gtfsRouteId": "SASGR002:SER002",
"name": "DAR - DOM"
},
"departure": {
"date": "2026-06-09",
"time": "06:00:00",
"dateTime": "2026-06-09T06:00:00+03:00",
"stop": {
"stop_id": "DARESALAAM:SGR:0",
"stop_lat": -6.82488714,
"stop_lon": 39.2830351,
"stop_name": "Dar es Salaam (John Magufuli SGR Station)",
"stop_desc": "Kisutu, Ilala, Dar es Salaam, Tanzania",
"stop_timezone": "Africa/Dar_es_Salaam",
"city_geohash": "kygcjv",
"popularity": 30,
"partners": [
{
"provider": "TRC",
"service": "SGR",
"id": 1,
"name": "Dar Es Salaam"
}
]
}
},
"arrival": {
"date": "2026-06-09",
"time": "07:40:00",
"dateTime": "2026-06-09T07:40:00+03:00",
"stop": {
"stop_id": "MOROGORO:SGR:0",
"stop_lat": -6.75460532,
"stop_lon": 37.66439974,
"stop_name": "Morogoro (Jakaya Kikwete SGR Station)",
"stop_desc": "Morogoro, Tanzania",
"stop_timezone": "Africa/Dar_es_Salaam",
"city_geohash": "kyfc94",
"popularity": 30,
"partners": [
{
"provider": "TRC",
"service": "SGR",
"id": 6,
"name": "Morogoro"
}
]
}
},
"price": {
"pricingContext": "ONLINE",
"currency": "TZS",
"total": "22500",
"bookingFeeTotal": "2000",
"grandTotal": "24500",
"fees": [
{
"type": "TRANSPORTER",
"amount": "22500",
"recipient": "TRC"
},
{
"type": "FACILITATION",
"amount": "0",
"recipient": "SAFIRI_AGENT"
},
{
"type": "SAFIRI_COMMISSION",
"amount": "2000",
"recipient": "SAFIRI"
}
],
"otherCurrencies": {
"TZS": {
"amount": 22500,
"formatted": "TZS 22,500.00"
},
"USD": {
"amount": 8.57,
"formatted": "USD 8.57"
},
"KES": {
"amount": 1107.74,
"formatted": "KES 1,107.74"
},
"UGX": {
"amount": 32274.83,
"formatted": "UGX 32,274.83"
},
"ZMW": {
"amount": 150.59,
"formatted": "ZMW 150.59"
}
}
},
"stopTimes": [
{
"stopId": "DARESALAAM:SGR:0",
"stopSequence": 0,
"arrivalTime": "05:55:00",
"departureTime": "06:00:00",
"stopName": "Dar es Salaam (John Magufuli SGR Station)",
"stopDescription": "Kisutu, Ilala, Dar es Salaam, Tanzania",
"latitude": -6.82488714,
"longitude": 39.2830351
},
{
"stopId": "MOROGORO:SGR:0",
"stopSequence": 5,
"arrivalTime": "08:35:33",
"departureTime": "08:40:33",
"stopName": "Morogoro (Jakaya Kikwete SGR Station)",
"stopDescription": "Morogoro, Tanzania",
"latitude": -6.75460532,
"longitude": 37.66439974
}
],
"cars": [
{
"id": 417,
"carId": 19,
"orderNo": 1,
"typeId": 151,
"typeName": "Royal Class",
"capacity": 44,
"standardSeatCapacity": 44,
"disabledSeatCapacity": 0,
"emptySeats": 0,
"emptyStandardSeats": 0,
"emptyDisabledSeats": 0,
"hasSeat": true,
"bookedSeats": []
},
{
"id": 420,
"carId": 15,
"orderNo": 4,
"typeId": 12,
"typeName": "Economy",
"capacity": 76,
"standardSeatCapacity": 74,
"disabledSeatCapacity": 2,
"emptySeats": 0,
"emptyStandardSeats": 0,
"emptyDisabledSeats": 0,
"hasSeat": true,
"bookedSeats": []
}
],
"transitAgency": {
"name": "Tanzania Railways Corporation",
"tradingName": "Tanzania Railways Corporation",
"tinNumber": "000000001",
"uuid": "204ea6a5-e374-4a22-a8b0-7a1d406c0514",
"phoneNumber": "+255800110042",
"email": "info@trc.co.tz",
"website": "https://sgrticket.trc.co.tz",
"type": "TRAIN",
"logos": []
}
}
]
}
note

Use one item from data as the selected train option in your application UI. Pass that full selected item to Get Train Details to retrieve cabins, passenger-type prices, seat maps, and booking requirements.

Response Structure

FieldTypeDescription
metaobjectSearch metadata including result count, provider, self link, and response timestamp.
dataarrayList of train options matching the requested origin, destination, and date.

Meta Object

FieldTypeDescription
countnumberNumber of train options returned.
providerstringTrain provider key. Current value is TRC_SGR.
links.selfstringFully qualified URL for the current search request.
createdAtstringISO timestamp for when the search response was generated.

Train Result Object

Each item in data represents one train option.

FieldTypeDescription
providerstringProvider key for the train option. Current value is TRC_SGR.
tripobjectTrain identity, timetable IDs, GTFS trip ID, headsign, and accessibility flags.
routeobjectRoute identity and GTFS route metadata.
departureobjectDeparture date, time, ISO date-time, and origin stop.
arrivalobjectArrival date, time, ISO date-time, and destination stop.
priceobjectTRC fare, Safiri fee breakdown, collected/debited total, base currency, and converted otherCurrencies.
stopTimesarray or nullOrdered route stops with arrival and departure times. May be null if GTFS stop-time enrichment is unavailable.
carsarrayRailway car classes, capacities, seat availability, and booked seat metadata.
carTypesarrayDeduplicated cabin/class list derived from cars. Useful for cabin filters.
transitAgencyobjectOperator information for Tanzania Railways Corporation.

Trip Object

FieldTypeDescription
idnumberTRC trip identifier.
namestringTrain trip name.
numberstringTrain number.
trainSetIdnumberTRC train set identifier.
timeTableIdnumberTRC timetable identifier.
timeTableTrainSetIdnumberTRC timetable train set identifier.
gtfsTripIdstring or nullMatching GTFS trip ID when available.
headsignstring or nullRoute headsign showing the destination and major intermediate stops.
wheelchairAccessiblenumber or nullGTFS wheelchair accessibility flag when available.
bikesAllowednumber or nullGTFS bike allowance flag when available.

Price Object

FieldTypeDescription
pricingContextstringPricing mode used for display and booking: ONLINE, SAFIRI_AGENT, or THIRD_PARTY_AGENT.
currencystringBase fare currency. Current SGR fares are returned in TZS.
totalstringDynamic TRC fare amount. This is the transporter ticket cost and is included in the wallet debit.
bookingFeeTotalstringSafiri-controlled fees above the TRC fare. For third-party agents, this is Safiri's booking fee unless another fee component is explicitly returned.
grandTotalstringAmount Safiri debits from the third-party agent wallet for this ticket. It does not include any additional markup you charge your customer outside Safiri.
feesarrayWallet-debit component breakdown. Includes TRANSPORTER, FACILITATION, and SAFIRI_COMMISSION; zero-value components are included as "0".
otherCurrenciesobjectConverted TRC fare amounts keyed by currency code. Each currency contains an amount and a human-readable formatted value.

Price Fee Object

FieldTypeDescription
typestringFee component type: TRANSPORTER, FACILITATION, or SAFIRI_COMMISSION.
amountstringComponent amount in the price currency. The returned fee amounts sum to grandTotal.
recipientstringComponent recipient, for example TRC, SAFIRI_AGENT, or SAFIRI.

Currency Amount Object

FieldTypeDescription
amountnumberNumeric amount in the target currency.
formattedstringDisplay-ready amount with currency code and separators.

Railway Car Object

FieldTypeDescription
idnumberTimetable railway car identifier.
carIdnumberRailway car type identifier.
orderNonumberCar order in the train.
typeIdnumberTRC class/type identifier.
typeNamestringPassenger class name, for example Royal Class, Business, or Economy.
capacitynumberTotal car capacity.
standardSeatCapacitynumberStandard seat capacity.
disabledSeatCapacitynumberAccessible seat capacity.
emptySeatsnumberCurrently available seats for the car.
emptyStandardSeatsnumberCurrently available standard seats.
emptyDisabledSeatsnumberCurrently available accessible seats.
hasSeatbooleanWhether the car has reserved seats.
bookedSeatsarraySeat booking metadata when returned by the provider.

Get Train Details

Retrieve detailed cabin, passenger-type fare, seat map, and booking requirement information for one selected train option.

Endpoint: POST /api/trip/train/details

Example Request:

POST /api/trip/train/details

Request Body

Pass the full train option selected from the Search for Trains response.

{
"trip": {
"provider": "TRC_SGR",
"trip": {
"id": 98,
"name": "DAR - DOM \\ EXPRESS",
"number": "11902",
"trainSetId": 20,
"timeTableId": 299,
"timeTableTrainSetId": 8537
},
"route": {
"id": 68,
"gtfsRouteId": "SASGR002:SER002",
"name": "DAR - DOM"
},
"departure": { "...": "full departure object from search" },
"arrival": { "...": "full arrival object from search" },
"price": { "...": "full price object from search" },
"stopTimes": [],
"cars": [],
"transitAgency": { "...": "full transit agency object from search" }
}
}

Response Structure

FieldTypeDescription
metaobjectDetails metadata including provider, self link, and response timestamp.
dataobjectThe selected train option enriched with train-set, cabin, seat, fare, and booking requirement details.

Details Data Object

The details response returns the same selected trip fields from search, plus train and bookingRequirements.

FieldTypeDescription
providerstringProvider key for the train option. Current value is TRC_SGR.
tripobjectTrain identity, timetable IDs, GTFS trip ID, headsign, and accessibility flags.
routeobjectRoute identity and GTFS route metadata.
departureobjectDeparture date, time, ISO date-time, and origin stop.
arrivalobjectArrival date, time, ISO date-time, and destination stop.
priceobjectBase amount, base currency, and converted otherCurrencies.
stopTimesarray or nullOrdered route stops with arrival and departure times.
trainobjectDetailed train-set information and cabin/car layout.
bookingRequirementsobjectPassenger details and option lists required for seat reservation.
transitAgencyobjectOperator information for Tanzania Railways Corporation.

Train Object

FieldTypeDescription
idnumberTimetable train set identifier.
typeIdnumberTrain type identifier.
typestringTrain type name, for example High Speed Train.
namestringTrain set name.
numbernumberTrain set number.
carTypesarrayDeduplicated cabin/class list derived from cars.
carsarrayCabin/car details, including prices and seats.

Train Car Object

FieldTypeDescription
idnumberTimetable car identifier.
namestringCar name from the provider.
orderNonumberCar order in the train.
carIdnumberRailway car identifier.
carTypeIdnumberRailway car class/type identifier.
carTypestringPassenger class name, for example Royal Class, Business, or Economy.
capacitynumberTotal car capacity.
standardCapacitynumberStandard seat capacity.
disabledCapacitynumberAccessible seat capacity.
emptySeatsnumberCurrently available seats in this car.
rowCountnumberNumber of seat-layout rows.
columnCountnumberNumber of seat-layout columns.
hasSeatbooleanWhether the car has selectable seats.
isActivebooleanWhether the car is active.
isDisabledbooleanWhether the car is disabled/unavailable.
pricesarrayPassenger-type prices for this car.
seatsarraySeat map for this car.

Car Price Object

FieldTypeDescription
ticketTypeIdnumberPassenger ticket type identifier.
ticketTypeCodenumberPassenger ticket type code.
ticketTypeNamestringPassenger type, for example Adult (13 and Above) or Child (4 - 12 Years).
pricingContextstringPricing mode used for this fare: ONLINE, SAFIRI_AGENT, or THIRD_PARTY_AGENT.
totalstringDynamic TRC fare amount for this passenger type and car. This is the transporter ticket cost and is included in the wallet debit.
bookingFeeTotalstringSafiri-controlled fees above the TRC fare. For third-party agents, this is Safiri's booking fee unless another fee component is explicitly returned.
grandTotalstringAmount Safiri debits from the third-party agent wallet for this ticket. It does not include any additional markup you charge your customer outside Safiri.
feesarrayWallet-debit component breakdown with TRANSPORTER, FACILITATION, and SAFIRI_COMMISSION.
formattedPricestringDisplay-ready fare amount.
currencystringFare currency.
otherCurrenciesobjectConverted fare amounts keyed by currency code.
luggageTypeIdnumberSelected/default luggage type identifier.
luggageTypeNamestringSelected/default luggage type name.
luggagePricenumberLuggage price amount.

Seat Object

FieldTypeDescription
idstringSeat identifier.
labelstringSeat label shown to passengers. Empty for non-seat layout cells.
positionYnumberZero-based display row.
positionXnumberZero-based display column within the row.
keystringStable frontend key for the layout cell.
typestringLayout cell type, for example SEAT, DISABLED_SEAT, AISLE, WC, LUGGAGE, or BED.
classstringCabin/class for the car, for example ECONOMY, BUSINESS, or ROYAL_CLASS.
orientationstringSeat orientation for layout rendering: UP, DOWN, LEFT, or RIGHT.
availablebooleanWhether the seat can be selected.

Booking Requirements Object

FieldTypeDescription
travelerRequirementsobjectRequired traveler fields for seat reservation.
nationalityOptionsarrayValid passenger nationality/residency options.
luggageOptionsarrayValid luggage options.
ticketTypeOptionsarrayValid passenger ticket type options.
Example response
{
"meta": {
"provider": "TRC_SGR",
"links": {
"self": "https://booking-api.safiri.app/api/trip/train/details"
},
"createdAt": "2026-06-10T01:30:01.015Z"
},
"data": {
"provider": "TRC_SGR",
"trip": {
"id": 98,
"name": "DAR - DOM \\ EXPRESS",
"number": "11902",
"trainSetId": 20,
"timeTableId": 299,
"timeTableTrainSetId": 8537,
"gtfsTripId": "SASGR002:O",
"headsign": "Dodoma via Pugu, Soga, Ruvu, Ngerengere, Morogoro, Mkata, Kilosa, Kidete, Gulwe, Igandu",
"wheelchairAccessible": 1,
"bikesAllowed": null
},
"route": {
"id": 68,
"gtfsRouteId": "SASGR002:SER002",
"name": "DAR - DOM"
},
"departure": {
"date": "2026-06-09",
"time": "06:00:00",
"dateTime": "2026-06-09T06:00:00+03:00",
"stop": {
"stop_id": "DARESALAAM:SGR:0",
"stop_name": "Dar es Salaam (John Magufuli SGR Station)"
}
},
"arrival": {
"date": "2026-06-09",
"time": "07:40:00",
"dateTime": "2026-06-09T07:40:00+03:00",
"stop": {
"stop_id": "MOROGORO:SGR:0",
"stop_name": "Morogoro (Jakaya Kikwete SGR Station)"
}
},
"price": {
"pricingContext": "ONLINE",
"currency": "TZS",
"total": "22500",
"bookingFeeTotal": "2000",
"grandTotal": "24500",
"fees": [
{
"type": "TRANSPORTER",
"amount": "22500",
"recipient": "TRC"
},
{
"type": "FACILITATION",
"amount": "0",
"recipient": "SAFIRI_AGENT"
},
{
"type": "SAFIRI_COMMISSION",
"amount": "2000",
"recipient": "SAFIRI"
}
],
"otherCurrencies": {
"TZS": {
"amount": 22500,
"formatted": "TZS 22,500.00"
},
"USD": {
"amount": 8.57,
"formatted": "USD 8.57"
}
}
},
"stopTimes": [
{
"stopId": "DARESALAAM:SGR:0",
"stopSequence": 0,
"arrivalTime": "05:55:00",
"departureTime": "06:00:00"
},
{
"stopId": "MOROGORO:SGR:0",
"stopSequence": 5,
"arrivalTime": "08:35:33",
"departureTime": "08:40:33"
}
],
"train": {
"id": 8537,
"typeId": 13,
"type": "High Speed Train",
"name": "EXPRESS TRAIN",
"number": 1011,
"cars": [
{
"id": 417,
"name": "ROYAL CLASS KIOSK",
"orderNo": 1,
"carId": 19,
"carTypeId": 151,
"carType": "Royal Class",
"capacity": 44,
"standardCapacity": 44,
"disabledCapacity": 0,
"emptySeats": 0,
"rowCount": 12,
"columnCount": 5,
"hasSeat": true,
"isActive": true,
"isDisabled": false,
"prices": [
{
"ticketTypeId": 4,
"ticketTypeCode": 4,
"ticketTypeName": "Adult (13 and Above)",
"pricingContext": "ONLINE",
"total": "45500",
"bookingFeeTotal": "2000",
"grandTotal": "47500",
"fees": [
{
"type": "TRANSPORTER",
"amount": "45500",
"recipient": "TRC"
},
{
"type": "FACILITATION",
"amount": "0",
"recipient": "SAFIRI_AGENT"
},
{
"type": "SAFIRI_COMMISSION",
"amount": "2000",
"recipient": "SAFIRI"
}
],
"formattedPrice": "TZS 45,500.00",
"currency": "TZS",
"otherCurrencies": {
"TZS": {
"amount": 45500,
"formatted": "TZS 45,500.00"
},
"USD": {
"amount": 17.34,
"formatted": "USD 17.34"
}
},
"luggageTypeId": 5,
"luggageTypeName": "None",
"luggagePrice": 0
}
],
"seats": [
{
"id": "1020",
"label": "23",
"positionY": 6,
"positionX": 1,
"key": "1020",
"type": "SEAT",
"class": "ROYAL_CLASS",
"orientation": "DOWN",
"available": true
}
]
}
]
},
"bookingRequirements": {
"travelerRequirements": {
"travelerId": true,
"genderRequired": true,
"ageCategory": true,
"seatRequired": true,
"nationality": true,
"luggageRequired": false,
"emailAddressRequired": false,
"mobilePhoneNumberRequired": true
},
"nationalityOptions": [
{
"code": 20,
"id": 20,
"title": "Non-Resident",
"price": null
},
{
"code": 19,
"id": 19,
"title": "Resident",
"price": null
}
],
"luggageOptions": [
{
"id": 5,
"name": "None",
"description": "None",
"weight": 0,
"price": 0,
"isActive": true,
"configurationItemId": 98
}
],
"ticketTypeOptions": [
{
"code": 4,
"id": 4,
"title": "Adult (13 and Above)",
"price": 45500
},
{
"code": 3,
"id": 3,
"title": "Child (4 - 12 Years)",
"price": 45500
}
]
},
"transitAgency": {
"name": "Tanzania Railways Corporation",
"tradingName": "Tanzania Railways Corporation",
"tinNumber": "000000001",
"uuid": "204ea6a5-e374-4a22-a8b0-7a1d406c0514",
"phoneNumber": "+255800110042",
"email": "info@trc.co.tz",
"website": "https://sgrticket.trc.co.tz",
"type": "TRAIN",
"logos": []
}
}
}

Hold Train Seat

Hold one selected SGR seat before collecting passenger details. Call this endpoint when a customer selects a seat in the seat map.

Endpoint: POST /api/trip/train/seat/hold

Example Request:

POST /api/trip/train/seat/hold

Request Body

FieldTypeRequiredDescription
departureStopPartnerIdnumberYesTRC station ID from departure.stop.partners[].id.
arrivalStopPartnerIdnumberYesTRC station ID from arrival.stop.partners[].id.
timeTableTrainSetIdnumberYestrip.timeTableTrainSetId from train search/details.
carIdnumberYesSelected details car id.
seatnumberYesSelected seat id.
luggageIdnumberNoLuggage option ID. Defaults to 5 (None).
{
"departureStopPartnerId": 1,
"arrivalStopPartnerId": 12,
"timeTableTrainSetId": 8710,
"carId": 497,
"seat": 2119,
"luggageId": 5
}

Success Response

{
"meta": {
"provider": "TRC_SGR",
"links": {
"self": "https://booking-api.safiri.app/api/trip/train/seat/hold"
},
"createdAt": "2026-06-12T10:00:00.000Z"
},
"data": {
"provider": "TRC_SGR",
"hold": {
"key": "f70c1e0e-9849-41dd-b3b7-949eac159dc2",
"status": "HELD"
}
}
}

Seat Already Taken

If TRC reports that the seat is no longer available, the API returns 400.

{
"error": {
"name": "modal",
"seatId": 2119
},
"errorCode": "SEAT_ALREADY_BOOKED",
"errorMessage": "This seat is taken.",
"status": 400
}

Release Train Seat

Release a previously held SGR seat. Call this endpoint when a customer unselects a seat or abandons seat selection before reservation.

Endpoint: GET /api/trip/train/seat/release

Example Request:

GET /api/trip/train/seat/release?key=f70c1e0e-9849-41dd-b3b7-949eac159dc2

Query Parameters

ParameterTypeRequiredDescription
keystringYesHold key returned by Hold Train Seat.

Success Response

{
"meta": {
"provider": "TRC_SGR",
"links": {
"self": "https://booking-api.safiri.app/api/trip/train/seat/release?key=f70c1e0e-9849-41dd-b3b7-949eac159dc2"
},
"createdAt": "2026-06-12T10:02:00.000Z"
},
"data": {
"provider": "TRC_SGR",
"hold": {
"key": "f70c1e0e-9849-41dd-b3b7-949eac159dc2",
"status": "RELEASED"
}
}
}
note

This endpoint uses GET because it wraps the upstream TRC release endpoint. Responses include Cache-Control: no-store.

Reserve Held Train Seats

Convert held seats into a confirmed reservation and open a 15-minute Safiri payment window for the customer to complete payment.

Endpoint: POST /api/trip/train/seat/reserve

The authenticated JWT user is stored on each local train ticket as boughtByUser. bookingUserType is derived server-side from that user and the train operator, so clients should not send boughtByUser or bookingUserType.

Example Request:

POST /api/trip/train/seat/reserve

Headers

HeaderRequiredDescription
AuthorizationYesBearer JWT for the user creating the reservation.
x-authentication-contextNoBooking channel saved on the train ticket. Defaults to WEB_APP when omitted.

Request Body

FieldTypeRequiredDescription
outboundobjectYesFull selected train details object from Get Train Details, containing only the selected cars/seats.
returnobject or nullNoFull selected return train details object. Use null or omit for one-way bookings.
passengersarrayYesPassenger and held-seat details. Supports multiple passengers.
issuerDeviceInfoobjectNoDevice/app metadata for the issuer, using the same shape as bus ticket issuerDeviceInfo.

Each passenger must include the common passenger fields and outbound seat fields. Return seat fields are required only when return is supplied.

Passenger FieldTypeRequiredDescription
passengerNamestringYesPassenger name sent to TRC.
identityNostringNoPassenger identity number. Use an empty string when not available.
phonestringYesPassenger phone number saved by Safiri.
countryCodestringNoPassenger phone country calling code, for example 255 or 44. Safiri derives and saves this from the parsed phone when countryCodeName is supplied.
countryCodeNamestringNoPassenger ISO country code, for example TZ or GB. Required for local-format phone numbers when countryCode is omitted. Safiri saves the parsed country in lowercase, for example tz or gb.
emailstringNoPassenger email address. Omit or use an empty string when not available. When provided, it must be a valid email format.
nationalityTypeIdnumberYesValue from bookingRequirements.nationalityOptions[].id.
isDisabledPassengerbooleanNoWhether the passenger is disabled.
ticketTypeIdnumberYesValue from bookingRequirements.ticketTypeOptions[].id, for example adult or child.
outboundSeatHoldKeystringYesHold key returned by the outbound seat hold call.
outboundCarIdnumberYesSelected outbound details car id.
outboundCarTypeIdnumberYesSelected outbound details car carTypeId.
outboundSeatIdnumberYesSelected outbound seat id.
returnSeatHoldKeystringReturn onlyHold key returned by the return seat hold call.
returnCarIdnumberReturn onlySelected return details car id.
returnCarTypeIdnumberReturn onlySelected return details car carTypeId.
returnSeatIdnumberReturn onlySelected return seat id.
note

Do not send payer information or luggage details. The API currently uses fixed payer information server-side and luggageTypeId: 5 (None) for TRC pricing and reservation.

note

Safiri validates the passenger phone against the submitted country information, then saves the passenger phone as provided plus the parsed calling code and lowercase ISO country. When submitting to TRC, non-Tanzania passenger numbers are replaced only in the TRC request because TRC does not support international phone numbers.

One-Way Example

{
"outbound": {
"provider": "TRC_SGR",
"trip": {
"id": 98,
"name": "DAR - DOM \\ EXPRESS",
"timeTableTrainSetId": 8710
},
"route": {
"id": 68,
"name": "DAR - DOM"
},
"departure": { "...": "full departure object from details" },
"arrival": { "...": "full arrival object from details" },
"train": {
"cars": [
{
"id": 497,
"carTypeId": 151,
"carType": "Royal Class",
"seats": [
{
"id": "2119",
"label": "23"
}
]
}
]
},
"transitAgency": { "...": "full transit agency object from details" }
},
"return": null,
"passengers": [
{
"passengerName": "ITULE",
"identityNo": "",
"phone": "0757713888",
"countryCodeName": "TZ",
"email": "abraham@itule.me",
"nationalityTypeId": 19,
"isDisabledPassenger": false,
"ticketTypeId": 4,
"outboundSeatHoldKey": "f70c1e0e-9849-41dd-b3b7-949eac159dc2",
"outboundCarId": 497,
"outboundCarTypeId": 151,
"outboundSeatId": 2119
}
],
"issuerDeviceInfo": {
"deviceId": "device-1",
"deviceBrand": "Apple",
"deviceModel": "iPhone",
"operatingSystem": "ios",
"operatingSystemVersion": "18.0",
"appName": "Safiri",
"appVersion": "1.0.0"
}
}

Return Journey Example

Use a separate selected details object and separate held seat for the return train.

{
"outbound": { "...": "selected outbound train details object" },
"return": { "...": "selected return train details object" },
"passengers": [
{
"passengerName": "ITULE",
"identityNo": "",
"phone": "0757713888",
"countryCodeName": "TZ",
"email": "abraham@itule.me",
"nationalityTypeId": 19,
"isDisabledPassenger": false,
"ticketTypeId": 4,
"outboundSeatHoldKey": "outbound-seat-hold-key",
"outboundCarId": 497,
"outboundCarTypeId": 151,
"outboundSeatId": 2119,
"returnSeatHoldKey": "return-seat-hold-key",
"returnCarId": 501,
"returnCarTypeId": 151,
"returnSeatId": 2120
}
]
}

Success Response

{
"meta": {
"provider": "TRC_SGR",
"links": {
"self": "https://booking-api.safiri.app/api/trip/train/seat/reserve"
},
"createdAt": "2026-06-12T10:05:00.000Z"
},
"data": {
"provider": "TRC_SGR",
"journeyType": "ONE_WAY",
"reservation": {
"pnr": "PNR00019e8aa4492c00",
"ticketNumbers": ["TRC00019e8aa449a500"],
"passengerCount": 1,
"segmentCount": 1
},
"bill": {
"id": "TRC-Pay062604545d07cf93a6ce4878913fb6fff8db2f76",
"expireDate": "2026-06-12T10:30:00.000+03:00",
"paymentRequired": true,
"controlNumber": "987264686974"
},
"paymentReference": "SGR1234567890123456",
"paymentWindow": {
"expiresInMinutes": 15,
"internalExpiresAt": "2026-06-12T10:20:00.000Z",
"expiresAt": "2026-06-12T10:20:00.000Z",
"providerExpiresAt": "2026-06-12T10:30:00.000+03:00"
},
"paymentItems": [
{
"identifier": "TRC00019e8aa449a500",
"journey": "OUTBOUND",
"passengerName": "ITULE",
"price": {
"pricingContext": "ONLINE",
"currency": "TZS",
"total": "45500",
"bookingFeeTotal": "2000",
"grandTotal": "47500",
"fees": [
{
"type": "TRANSPORTER",
"amount": "45500",
"recipient": "TRC"
},
{
"type": "FACILITATION",
"amount": "0",
"recipient": "SAFIRI_AGENT"
},
{
"type": "SAFIRI_COMMISSION",
"amount": "2000",
"recipient": "SAFIRI"
}
],
"otherCurrencies": {
"TZS": {
"amount": 45500,
"formatted": "TZS 45,500.00"
}
}
},
"trainTicketUuid": "c66b52a9-d5d3-4e58-bc15-7f2d91da18f9"
}
],
"workflowId": "SGR_TRAIN_SEAT_RESERVATION-PNR00019e8aa4492c00-passenger-group-id",
"trainTicketUuids": ["c66b52a9-d5d3-4e58-bc15-7f2d91da18f9"]
}
}

Reservation Retry Behavior

The reservation endpoint is designed to resume safely after partial upstream success:

  • If the upstream provider already created the ticket for the held seat, the API looks up local TrainTicket records by seatHoldKey and resumes from the stored reservation data rather than creating a duplicate.
  • If a payment window was already opened for the booking, the API skips re-opening it and returns the existing payment details.
warning

The endpoint can only resume an existing booking when matching local TrainTicket records are found. If the upstream provider reports an existing ticket but no local record is found, the API returns a controlled error.

Error Responses

When a train request fails, the API returns a standard error object:

{
"error": {},
"errorCode": "FROM_STOP_ID_REQUIRED",
"errorMessage": "Please provide from, to and date for SGR train search",
"status": 400
}

Common causes include:

  • Missing from, to, or date
  • A stop ID that does not exist in the train GTFS data
  • A stop that is not an SGR stop with TRC partner metadata
  • Temporary unavailability from the upstream TRC search service
  • A selected seat that no longer matches the selected train details payload
  • A seat that has already been booked or held by another customer
  • A reservation retry where no matching local booking record is found for the held seat