REST API

Discussion in 'Technical & Support' started by DanRZ, Feb 2, 2023.

  1. DanRZ

    DanRZ Registered

    Joined:
    Aug 22, 2021
    Messages:
    720
    Likes Received:
    220
    Hello i'm trying to use the Web API for rF2.
    The one you find here after launching rF2 : http://localhost:5397/swagger/index.html

    I'm using the ai/add call to try and add an AI from a powershell.

    Here is the API working well with "Try it out" :
    Capture.JPG

    And here is a powershell script that should do the same, but don't work (Not the right car added) :
    Code:
    $url = "http://localhost:5397/rest/sessions/ai/add"
    $body = @{
     "String" = "BMW M8 GTE #22"
    }
    Invoke-RestMethod -Method 'Post' -Uri $url -Body ($body|ConvertTo-Json) -ContentType "application/json"
    
    Anyone know how this API should be scripted in Powershell and can help me ?

    Thanks.
     
  2. Bernat

    Bernat Registered

    Joined:
    Jun 15, 2020
    Messages:
    757
    Likes Received:
    585
    Is there some documentation for this API?
     
  3. DanRZ

    DanRZ Registered

    Joined:
    Aug 22, 2021
    Messages:
    720
    Likes Received:
    220
    Bernat likes this.
  4. Bernat

    Bernat Registered

    Joined:
    Jun 15, 2020
    Messages:
    757
    Likes Received:
    585
    Thanks. I'm always learning new things.

    It looks like the parameter type is the important info. The first column "Parameter" isn't really used.

    I would try with:

    Code:
    $body = "BMW M8 GTE #22"
    You can open the Network tab in the browser developer tools to see how petitions are sent.
     
    Last edited: Feb 3, 2023
  5. DanRZ

    DanRZ Registered

    Joined:
    Aug 22, 2021
    Messages:
    720
    Likes Received:
    220
    Thanks, i will try that.

    If it works on the dedicated server too, it would be a solution to setup a race with selected AIs, which is actually not possible without repackaging rfcmps and keeping exclusively skins used.
     
  6. DanRZ

    DanRZ Registered

    Joined:
    Aug 22, 2021
    Messages:
    720
    Likes Received:
    220
    Hello, i have managed to use javascript and try the REST API to add AIs via an html page.
    It works perfectly on single player but doesn't seem to work on a dedicated ...

    Why ! :(

    Somebody here can confirm (or not) that the Rest API is only available in single player mode ?

    Thanks.

    PS : The url http://localhost:5397/swagger/index.html#!/sessions/addAi works on a dedicated
    but nothing happens when i use the "Try out" on ai/add api ...
    It definitely looks like the rest Api is really unavailable on a dedicated.
     
    Last edited: Feb 9, 2023
  7. Coutie

    Coutie Moderator Staff Member

    Joined:
    Oct 5, 2010
    Messages:
    3,782
    Likes Received:
    2,242
    Yes it doesn't work on dedicated. You're not going to get any official help with it though.
     
  8. DanRZ

    DanRZ Registered

    Joined:
    Aug 22, 2021
    Messages:
    720
    Likes Received:
    220
    Thanks.

    So, why is it even there ?
     
  9. Jeroen Goudeseune

    Jeroen Goudeseune Registered

    Joined:
    Aug 13, 2021
    Messages:
    37
    Likes Received:
    13
    Im also a bit interested in the Rest API.

    Is there a way 'to talk' to the pit menu through the rest api available in Rfactor2? Im trying to find a little more effecient way to change fuel, tyres, other settings by setting up some buttons (set primary, set alternate, set fuel to finish, ...) on the matric app (Software buttonbox, which supports HTTP requests). Also possibility to read fuel info from car? I went trough this http://localhost:5397/swagger/index.html but couldnt find something.

    This documentation was foundable in one of the JAR files of rfactor2
     
  10. Seven Smiles

    Seven Smiles Registered

    Joined:
    Oct 5, 2010
    Messages:
    1,099
    Likes Received:
    1,152
    Crew Chief will do all that (and more) with voice commands and you can bind them to buttons if you want to.
     
  11. Seven Smiles

    Seven Smiles Registered

    Joined:
    Oct 5, 2010
    Messages:
    1,099
    Likes Received:
    1,152
    I had a poke around, I didn't find anything outstandingly useful and sometimes useless:
    http://localhost:5397/swagger/index.html#!/race/getVehicleDescription
    Code:
    Response Body
    {
      "poContent": "This vehicle has a F2 0.75L engine and is manufactured by Dubouis Bonheur."
    }
    for the GT3 McLaren! I did find another URL that did give correct (if limited) data about the car but I can't find it again.

    Maybe the API is designed for automatic testing of the UI?
     

Share This Page