Using Deutsche Bahn departure board APIs

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
glenn9
Posts: 145
Joined: Wed Jan 15, 2020 10:45 pm
Location: Europe

Using Deutsche Bahn departure board APIs

Post by glenn9 » Thu Jan 14, 2021 1:55 pm

Dear All,

Next on my learning list for LC is engaging with APIs, and last night managed to put together a URL shortening app which accessed the is.gd API (https://is.gd/apishorteningreference.php).

It was surprisingly straightforward using the 'Get' command and it all worked well.

Stoked with confidence, I wanted to see if I could access the Deutsche Bahn departure board API (https://is.gd/DB_APIs) but sadly hit the P/buffers abruptly - not because of LC - but because I guess I'm not understanding how to implement the DB APIs correctly.

A long shot, but I just wanted to check if anyone had any experience with DB API's and could put me on the right track?

Many thanks,

Kind regards,

Glenn

Klaus
Posts: 12205
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Using Deutsche Bahn departure board APIs

Post by Klaus » Thu Jan 14, 2021 4:23 pm

Hi Glenn,

which one of the ten listed APIs do you mean exactly?


Best

Klaus

glenn9
Posts: 145
Joined: Wed Jan 15, 2020 10:45 pm
Location: Europe

Re: Using Deutsche Bahn departure board APIs

Post by glenn9 » Fri Jan 15, 2021 10:01 am

Hi Klaus,

It was the Fahrplan_free service, my interest was on the departure board for individual stations. https://developer.deutschebahn.com/stor ... OpenData#/

Kind regards,

Glenn

AndyP
Posts: 514
Joined: Wed Aug 27, 2008 12:57 pm
Location: Seeheim, Germany (ex UK)
Contact:

Re: Using Deutsche Bahn departure board APIs

Post by AndyP » Fri Jan 15, 2021 10:52 am

Hi Glen,

I've just played around with this api and its nice and easy to use

So I started with https://api.deutschebahn.com/freeplan/v1/location/frank to get the station id for Frankfurt Hessen which returned this

[
{
"name": "Frankfurt(Main)Hbf",
"lon": 8.663785,
"lat": 50.107149,
"id": 8000105
},
{
"name": "Frankfurt(M) Flughafen Fernbf",
"lon": 8.570181,
"lat": 50.053169,
"id": 8070003
},
{
"name": "Frankfurt(M)Flughafen",
"lon": 8.570972,
"lat": 50.05121,
"id": 8000281
},
{
"name": "FRANKFURT(MAIN)",
"lon": 8.663785,
"lat": 50.107149,
"id": 8096021
},
{
"name": "Frankfurt(Oder)",
"lon": 14.546497,
"lat": 52.33642,
"id": 8010113
},
{
"name": "Frankfurt(Main)Süd",
"lon": 8.686456,
"lat": 50.099365,
"id": 8002041
},
{
"name": "Frankfurt(Main)West",
"lon": 8.639335,
"lat": 50.118862,
"id": 8002042
},
{
"name": "Frankfurt(M) Flughafen Regionalbf",
"lon": 8.57125,
"lat": 50.051219,
"id": 8070004
},
{
"name": "Frankfurt-Niederrad",
"lon": 8.637079,
"lat": 50.081287,
"id": 8002050
},
{
"name": "Franzensfeste",
"lon": 11.610081,
"lat": 46.788719,
"id": 8300089
},
{
"name": "Besançon Franche-Comté TGV",
"lon": 5.952675,
"lat": 47.307558,
"id": 8730086
},
{
"name": "Flughafen Berlin Brandenburg BER",
"lon": 13.511947,
"lat": 52.364808,
"id": 8011201
}
]

From this I took

name": "Frankfurt(Main)Hbf",
"lon": 8.663785,
"lat": 50.107149,
"id": 8000105 <<<<<<ID


I then fed this into https://api.deutschebahn.com/freeplan/v ... 2021-01-20 to get the board info for the station id above, this gave *only giving partial results here as the responce is quite large!

[
{
"name": "ICE 520",
"type": "ICE",
"boardId": 8000105,
"stopId": 8000105,
"stopName": "Frankfurt&#x0028;Main&#x0029;Hbf",
"dateTime": "2021-01-20T00:03",
"origin": "München Hbf",
"track": "9",
"detailsId": "405429%2F138644%2F991548%2F360631%2F80%3fstation_evaId%3D8000105"
},
{
"name": "IC 2027",
"type": "IC",
"boardId": 8000105,
"stopId": 8000105,
"stopName": "Frankfurt&#x0028;Main&#x0029;Hbf",
"dateTime": "2021-01-20T00:13",
"origin": "Lübeck Hbf",
"track": "2",
"detailsId": "463764%2F156373%2F12290%2F148443%2F80%3fstation_evaId%3D8000105"
},
{
"name": "ICE 990",
"type": "ICE",
"boardId": 8000105,
"stopId": 8000105,
"stopName": "Frankfurt&#x0028;Main&#x0029;Hbf",
"dateTime": "2021-01-20T00:41",
"origin": "München Hbf",
"track": "7",
"detailsId": "656652%2F224734%2F949082%2F255657%2F80%3fstation_evaId%3D8000105"
},
{
"name": "ICE 699",
"type": "ICE",
"boardId": 8000105,
"stopId": 8000105,
"stopName": "Frankfurt&#x0028;Main&#x0029;Hbf",
"dateTime": "2021-01-20T02:15",
"origin": "Hamburg-Altona",
"track": "8",
"detailsId": "149661%2F54437%2F297050%2F98638%2F80%3fstation_evaId%3D8000105"
},
{
"name": "ICE 209",
"type": "ICE",
"boardId": 8000105,
"stopId": 8000105,

To get a list of arrivals for the specified date and station id.

I noticed that without an api key the service is restricted to 10 calls per minute, so this may be what is causing you the problems.

I also made a little tool JSON API Helper to help with json apis which you can find under Sample Stacks in the LiveCode ide just search for json
Andy Piddock

http://2108.co.uk/tinyide/ - Mini LC IDE alternative

http://2108.co.uk/script-editor-themer/ - Script Editor colour theming

http://livecodeshare.runrev.com/stack/897/LiveCode-Multi-Search - Search across 8 LC resources

glenn9
Posts: 145
Joined: Wed Jan 15, 2020 10:45 pm
Location: Europe

Re: Using Deutsche Bahn departure board APIs

Post by glenn9 » Fri Jan 15, 2021 11:40 am

Hi Andy,

Thank you so much for this.

I've just downloaded the API helper tool and will work through this to get an understanding etc.

Where I was also having problems with the API was with the departure board, in that the destination station wasn't showing (even with the api key)

For example:

[
{
"name": "ICE 1686",
"type": "ICE",
"boardId": null,
"stopId": 8000064,
"stopName": "Celle",
"dateTime": "2021-01-15T07:20",
"track": "5",
"detailsId": "738054%2F247340%2F932804%2F220384%2F80%3fstation_evaId%3D8000064"
},
{
"name": "IC 2371",
"type": "IC",
"boardId": null,
"stopId": 8000064,
"stopName": "Celle",
"dateTime": "2021-01-15T07:37",
"track": "6",
"detailsId": "39198%2F15865%2F546196%2F260032%2F80%3fstation_evaId%3D8000064"
},
{
"name": "ICE 1676",
"type": "ICE",
"boardId": null,
"stopId": 8000064,
"stopName": "Celle",
"dateTime": "2021-01-15T08:18",
"track": "5",
"detailsId": "804000%2F269285%2F157510%2F189245%2F80%3fstation_evaId%3D8000064"
},

but on arrivals board the origin shows up fine as in your data for Frankfurt Hbf

Not sure what I need to do get the departure board to show destination....?

Regards,

Glenn

glenn9
Posts: 145
Joined: Wed Jan 15, 2020 10:45 pm
Location: Europe

Re: Using Deutsche Bahn departure board APIs

Post by glenn9 » Fri Jan 15, 2021 1:32 pm

I'm wanting to access the departure board API at this link https://developer.deutschebahn.com/stor ... DBOpenData

Klaus
Posts: 12205
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Using Deutsche Bahn departure board APIs

Post by Klaus » Fri Jan 15, 2021 1:52 pm

I know! :-)

The last posting was spam!

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”