derhuerst / vbb-rest

An HTTP API for Berlin & Brandenburg public transport.
https://v6.vbb.transport.rest/
ISC License
123 stars 14 forks source link

How do you get the id of the departing line? #22

Closed michaelcheers closed 6 years ago

michaelcheers commented 6 years ago

Say I got this result from asking for the departures:

[
    {
        "ref": "1|25705|1|86|8022018",
        "station": {
            "type": "station",
            "name": "Wiesenwinkel",
            "coordinates": {
                "latitude": 52.594429,
                "longitude": 13.380983
            },
            "id": "900000132500",
            "products": {
                "suburban": false,
                "subway": false,
                "tram": true,
                "bus": false,
                "ferry": false,
                "express": false,
                "regional": false
            }
        },
        "when": "2018-02-08T21:42:00+01:00",
        "direction": "Mitte, Am Kupfergraben",
        "line": {
            "type": "line",
            "name": "M1",
            "class": 4,
            "productCode": 2,
            "productName": "Str",
            "product": "tram",
            "mode": "train",
            "public": true,
            "id": "m1",
            "symbol": "M",
            "nr": 1,
            "metro": true,
            "express": false,
            "night": false
        },
        "remarks": [
            null,
            null
        ],
        "trip": 25705,
        "delay": 0
    }
]

How would I get the line id? I would have though json[0].line.id would have done it but I just get the lowercase version of the name and not a valid id,

derhuerst commented 6 years ago

The underlying (HAFAS) VBB API either doesn't have the concept of a line ID or doesn't expose it. It only exposes this ref, which you can use to query details about the trip (the individual vehicle travelling, not the line).

The fact that json[0].line.id is there is only because the departures(stationId) method returns data in the Friendly Public Transport Format 1.0.1. I'm aware that this is misleading and should probably document this better.

derhuerst commented 6 years ago

This is a general problem: VBB provides open static data, which contains lines including their IDs. Except from very brittle matching by name, there is no way to associate a static line ID with a trip from the HAFAS API. This significantly reduces the number of use cases unfortunately.