Transport for Finland

Transport for Finland

Transportation

Finnish transport API. Digitransit Platform is an open source journey planning solution that combines several open source components into a modern, highly available route planning service. Route planning algorithms and APIs are provided by Open Trip Planner (OTP). OTP is a great solution for general route planning but in order to provide top-notch journey planning other components such as Mobile friendly user interface, Map tile serving, Geocoding, and various data conversion tools are needed. Digitransit platform provides these tools.

Visit API

📚 Documentation & Examples

Everything you need to integrate with Transport for Finland

🚀 Quick Start Examples

Transport for Finland Javascript Examplejavascript
// Transport for Finland API Example
const response = await fetch('https://digitransit.fi/en/developers/', {
    method: 'GET',
    headers: {
        'Content-Type': 'application/json'
    }
});

const data = await response.json();
console.log(data);

Introduction to Digitransit API

DigiTransit is a Finnish development project that aims to provide accessible and sustainable public transport solutions. To achieve this goal, they've developed an open API for developers to use.

The Digitransit API provides a wealth of information related to public transportation, such as real-time vehicle locations and schedules, trip planning, and information on nearby stations and stops.

Getting Started

To access the Digitransit API, developers must register for an API key. Once you have your key, you can authenticate requests by including it in the header of your API calls.

Authorization: <YOUR_API_KEY>

Example API Requests

Get Routes

To get all available routes for a given area, use the following API call:

const baseUrl = 'https://api.digitransit.fi/routing/v1/routers/hsl/';
const endPoint = 'index/graphql';

const query = `{
    routes {
        gtfsId
        shortName
        longName
    }
}`;

const options = {
    method: 'POST',
    headers: {
        'Content-Type': 'application/graphql',
        'Authorization': `Bearer ${YOUR_API_KEY_HERE}`,
    },
    body: query,
};

fetch(baseUrl + endPoint, options)
    .then(response => response.json())
    .then(data => console.log(data.data.routes));

Get Real-time Stops

To get real-time information for stops near a given location, use the following API call:

const baseUrl = 'https://api.digitransit.fi/routing/v1/routers/hsl/';
const endPoint = 'index/graphql';

const query = `{
    stopsByRadius(lat: LATITUDE, lon: LONGITUDE, radius: RADIUS) {
        edges {
            node {
                stop {
                    gtfsId
                    name
                    lat
                    lon
                    stoptimesWithoutPatterns {
                        scheduledArrival
                        realtimeArrival
                        headsign
                        trip {
                            route {
                                shortName
                                longName
                                mode
                            }
                        }
                    }
                }
            }
        }
    }
}`;

const options = {
    method: 'POST',
    headers: {
        'Content-Type': 'application/graphql',
        'Authorization': `Bearer ${YOUR_API_KEY_HERE}`,
    },
    body: query,
};

fetch(baseUrl + endPoint, options)
    .then(response => response.json())
    .then(data => console.log(data.data.stopsByRadius.edges));

Get Trip Plan

To plan a trip between two locations, use the following API call:

const baseUrl = 'https://api.digitransit.fi/routing/v1/routers/hsl/';
const endPoint = 'plan';

const options = {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${YOUR_API_KEY_HERE}`,
    },
    body: JSON.stringify({
        from: { lat: FROM_LATITUDE, lon: FROM_LONGITUDE },
        to: { lat: TO_LATITUDE, lon: TO_LONGITUDE },
        date: '2022-12-31',
        time: '08:30:00',
        arriveBy: false,
        modes: 'BUS,RAIL',
    }),
};

fetch(baseUrl + endPoint, options)
    .then(response => response.json())
    .then(data => console.log(data.plan.itineraries));

Conclusion

The Digitransit API provides a powerful tool for developers looking to build applications related to public transportation. With its comprehensive documentation and easy-to-use API, it's never been easier to build new and innovative solutions to help people move around cities.

📊 30-Day Uptime History

Daily uptime tracking showing online vs offline minutes

Jun 15Jun 17Jun 19Jun 21Jun 23Jun 25Jun 27Jun 29Jul 1Jul 3Jul 5Jul 7Jul 9Jul 11Jul 1404008001440Minutes
Online
Offline

Related APIs in Transportation