REST API

PlanRZ

Guest
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.
 
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:
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.
 
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:
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
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.
Yes it doesn't work on dedicated. You're not going to get any official help with it though.
 
Yes it doesn't work on dedicated. You're not going to get any official help with it though.

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
 
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?
 
Is there a way to use the rest api to pass driving control to AI? I can map a key (A in my case) to pass driving control to AI once I am on the track. Is there a way to do this right from the garage using rest api so that the ai can drive the complete session?

the documentation from the swagger url (http://localhost:5397/swagger/index.html) does not seem to list anything related to AI under the garage or race endpoints.
 
i found another api end point -- "/rest/options/testinputhook", but its not documented. is this end point supposed to emulate keyboard input? if yes, then i can use rest api to input the AI control keymap? however, i am unable to find documentation notes for rest endpoint.
 
Dunno but Crew Chief does it by faking key presses or using the HWControl API in its shared memory DLL. Not sure if AI control works through that API though, you certainly can't operate explicit driving controls (steering, throttle etc.).
 
Back
Top