Is there an API for the Duplo 10874 train set?
There is now official documentation for the Bluetooth protocol used by the Powered Up product line:

https://github.com/LEGO/lego-ble-wireless-protocol-docs

The community has created some tools to interact directly with Powered Up and Boost hubs. Here is one example:

https://github.com/nathankellenicki/node-poweredup

That tool supports basically every device using the Powered Up Bluetooth protocol, including the new Duplo trains.