PC Api Documentation

Discussion in 'TSW General Discussion' started by lawn.chairs, Sep 19, 2025.

  1. lawn.chairs

    lawn.chairs Member

    Joined:
    Aug 8, 2021
    Messages:
    48
    Likes Received:
    49
    Anyone have any API docs? Would love to finally be able to write my own controller inputs. I'm assuming its some C++ tie-in to unreal but I'm definitely not familiar enough with unreal's architecture...
     
  2. BeenTrain

    BeenTrain Active Member

    Joined:
    Dec 10, 2016
    Messages:
    183
    Likes Received:
    161
    I don't think API documentation is available yet but this is a good startpoint:

    The API runs on http://localhost:31270/.

    Start by checking these endpoints using f.e Postman, don't forget to add the api key in the header called "DTGCommKey".
    When you activate the API by adding the -HTTPAPI launch parameter in Steam, you can find the api key in you user profile under Documents\My Games\TrainSimWorld5\Saved\Config\CommAPIKey.txt
    These give you insight into available nodes and endpoints, great starting points for exploring.
     
    • Helpful Helpful x 4
    • Like Like x 2
  3. BeenTrain

    BeenTrain Active Member

    Joined:
    Dec 10, 2016
    Messages:
    183
    Likes Received:
    161
    While we wait for the official Train Sim World API documentation, I’ve compiled an unofficial reference PDF based on how ThirdRails uses the API.
    It includes practical examples of API usage and should be helpful if you’re exploring implementation details.

    If you’re interested in working with it in C#, I’m happy to share my client code to help you get started.

    You can download the unofficial API documentation at ThirdRails.org: https://thirdrails.org/Downloads/TSW_API_Unofficial_Documentation.pdf

    Hopefully this can help anybody out there!
     
    • Like Like x 3
    • Helpful Helpful x 3
  4. lawn.chairs

    lawn.chairs Member

    Joined:
    Aug 8, 2021
    Messages:
    48
    Likes Received:
    49
    Awesome. The main control goodness is definitely in setFeatureStatus. And because this is HTTP, I don't need the C# code -- I just figured that this was some UE4 dll tie-in under the hood. (It still might be, but if so then TSW has done the work of abstracting it.)

    This isn't the world's best use case for an HTTP implementation (a websocket layer would absolutely shine here) but async requests ought to get the job done given the absolute minimal latency of local devices.

    Nice work, much appreciated
     
  5. BeenTrain

    BeenTrain Active Member

    Joined:
    Dec 10, 2016
    Messages:
    183
    Likes Received:
    161
    Yeah I see what you mean. But I must say that polling the API works fine for ThirdRails. On localhost there’s really no noticeable latency, even when polling multiple times per second for sessions that run over an hour.
    It’s great that DTG is making this possible it is really fun to build on!
     
  6. waaghals

    waaghals New Member

    Joined:
    Sep 21, 2025
    Messages:
    2
    Likes Received:
    0
    I've been trying to figure out what is possible through the API, and to write proper API documentation for it.
    To be able to inspect all possible available information on the API I've also written an inspector that allows for inspecting all possible values and controlling some that are writable.

    Viewing all nodes and their endpoints works. Continuously fetching a endpoint's value also works. Setting writable endpoints also works.
    I've even been able to setup some rudimentary controls for PushButtonControls and IrregularLevelControls. Which is the vast majority of the nodes with writable endpoints.

    I've not been able to setup the subscription. I can add a Path to a subscription. But when fetching the information on that subscription, no data is returned.
    For actual controlling the game it works well enough, but listening for values would definitionally be preferred to run over Server Sent Events of even Websockets.
     
  7. lawn.chairs

    lawn.chairs Member

    Joined:
    Aug 8, 2021
    Messages:
    48
    Likes Received:
    49
    darn right. so many great project ideas floating through my head.

    now i'm really gonna need to buy a 3d printer and figure out cad. oh no, woe is me
     
  8. pogodoyle#7387

    pogodoyle#7387 Well-Known Member

    Joined:
    Aug 21, 2021
    Messages:
    265
    Likes Received:
    689
    This looks like an interesting API … already thinking of quick hack for my TrainMapper app to show the live positions of everything in the game, just to see how it looks! In theory it’s just replacing the live NR feed with an adapter off the back of this API :cool:

    That being said, if we can only get the lat/long of the player that’s going to be a pretty empty map :D
     
    Last edited: Sep 22, 2025
  9. OpenMinded

    OpenMinded Well-Known Member

    Joined:
    Feb 10, 2021
    Messages:
    1,366
    Likes Received:
    2,348
    • Like Like x 5
    • Helpful Helpful x 1
  10. pogodoyle#7387

    pogodoyle#7387 Well-Known Member

    Joined:
    Aug 21, 2021
    Messages:
    265
    Likes Received:
    689
    Wow, this is a pretty useful API!

    I just knocked up a quick demo to see if it would show all the trains in my current Preston-Carlisle session... hey presto... it's following me all the way to Carlisle now. Kind of takes the fun out of the drive though, I can see what's coming towards me way in advance now :D:D:D

    Might be a useful dev tool though I guess.

    Most likely I'll just use it for route learning though.

    Screenshot 2025-10-17 at 16.54.35.png
     
    • Like Like x 3
  11. Sharon E

    Sharon E Well-Known Member

    Joined:
    Dec 9, 2016
    Messages:
    2,262
    Likes Received:
    2,225
    Interesting, those of us who are now using Winzarten app have starting using api in game.
     
  12. pogodoyle#7387

    pogodoyle#7387 Well-Known Member

    Joined:
    Aug 21, 2021
    Messages:
    265
    Likes Received:
    689
    Feels like there’s a lot to explore here. Trouble is Birmingham-Crewe is out on Tuesday, and that’s my exploring time all spoken for right there :D:D:D
     
  13. argh.bailey

    argh.bailey Active Member

    Joined:
    Jan 9, 2021
    Messages:
    88
    Likes Received:
    113
    Anyone had any luck finding things like status of being 'stopped at objective' or 'loading status'. Can't find anything in the track monitor or the HUD. What I'm after is the bit of the hud that displays the 'lock door' message
     
  14. pogodoyle#7387

    pogodoyle#7387 Well-Known Member

    Joined:
    Aug 21, 2021
    Messages:
    265
    Likes Received:
    689
    Haven’t looked properly, but I’ll keep it in mind as I keep playing with the API this week!
     
  15. atpyatt

    atpyatt Well-Known Member

    Joined:
    Nov 28, 2020
    Messages:
    120
    Likes Received:
    314
    I've looked and I couldn't find it either, I don't think it's in there yet.

    Has anybody managed to get values for endpoint names that have a space in them? E.g.
    VirtualRailDriver/Auto Brake.

    http://localhost:31270/get/VirtualRailDriver.Reverser works fine, /get/VirtualRailDriver.Auto<Encode space>Brake does not (HTML encoded whitespace, struggling with formatting here), seems like a bit of an oversight to have whitespace in some of these endpoint names?
     
    Last edited: Oct 21, 2025 at 9:33 PM
  16. BeenTrain

    BeenTrain Active Member

    Joined:
    Dec 10, 2016
    Messages:
    183
    Likes Received:
    161
    Try "%20"

    In C# you can do this:
    string encodedNodeName = Uri.EscapeDataString("VirtualRailDriver.Auto Brake");
    This results in "VirtualRailDriver.Auto%20Brake"

    I have not used it with spaces, but with endpoint having "/" in it ""AWS/TPWS" but it should also escape spaces. Becomes "AWS%2FTPWS"
     
  17. atpyatt

    atpyatt Well-Known Member

    Joined:
    Nov 28, 2020
    Messages:
    120
    Likes Received:
    314
    Unfortunately encoding the space doesn't work.
     
  18. Ricardo Rivera - Reppo

    Ricardo Rivera - Reppo New Member

    Joined:
    Jan 24, 2020
    Messages:
    6
    Likes Received:
    5
    Hi all,

    I am an amateur user of Arduino projects and I would like to create custom and mechanical controls for TSW using digital an analog enters. I understand the Api works with HTTP commands. Does it mean that I could send from the Arduino program those commands to be readed by the Api? If yes, how I can set the comm between the Arduino card and the PC? Serial? Ethernet? Sorry for my ignorance about these things...

    Thanks in advance.
     
  19. GuitarMan

    GuitarMan Well-Known Member

    Joined:
    Aug 15, 2020
    Messages:
    635
    Likes Received:
    879
    Is not old enough code that it encodes the space with a + is it?
     
  20. pogodoyle#7387

    pogodoyle#7387 Well-Known Member

    Joined:
    Aug 21, 2021
    Messages:
    265
    Likes Received:
    689
    The software on the Arduino would be making HTTP requests to the game, so the Arduino has to be hooked up to the same LAN either via physical Ethernet or WiFi.
     
  21. Ricardo Rivera - Reppo

    Ricardo Rivera - Reppo New Member

    Joined:
    Jan 24, 2020
    Messages:
    6
    Likes Received:
    5
    That is what I needed to know. Thank you very much!

    Cheers.
     
  22. argh.bailey

    argh.bailey Active Member

    Joined:
    Jan 9, 2021
    Messages:
    88
    Likes Received:
    113
    I have been using processing as an interface between an arduino and the game. Processing makes the request to the game and then sends the result via serial over usb to an arduino with an lcd display. Just because I don't have an arduino or similar to hand that had network capability.
     

Share This Page