Hi TN community,
Trying to use Python to create a program to make API calls, using the “truenas_api_client” as detailed here:
TrueNAS Websocket Documentation
When I try this program with the /websocket
endpoint, it works:
from truenas_api_client import Client
TN_TARGET = 'truenas01.mycompany.com'
TN_API_KEY = '1-5up3r53cr37K3y'
with Client(uri=f"ws://{TN_TARGET}/websocket") as clt:
clt.call("auth.login_with_api_key", TN_API_KEY)
print(clt.ping()) # pong
(returns True
)
…but somewhere I read that the /websocket
endpoint was deprecated, and one should now use the /api/current
endpoint. But, when I try that, I get the error:
Websocket client error: ValueError('scheme http is invalid')
Can someone confirm the endpoint I should be using, and if it is indeed /api/current
, how to get that endpoint to work?
Thanks.
What version of TrueNAS are you testing against?
If nightlies, then ws://{target}/api/current
TrueNAS Enterprise, Version: ElectricEel-24.10.1
Enterprise as in you have an enterprise support contract?
api/current
is 25.04 and later. websocket
is 24.10 and earlier.
2 Likes
Yes, we do have support (Bronze), but I thought it might be faster (and more helpful to the community) to ask the question here…
Can you tell me if the TrueNAS GUI utilizes the Websockets API to send the commands to the middleware, or is the API not used for the GUI? (trying to figure out if the API is full-featured, or it some things must be done thru the GUI)
Thanks for the reply on the endpoint, makes sense.
Everything goes through the WS API. BTW, in 24.10 many WS API endpoints are audited as well (the ones that make config changes) if you need to check what is being called for particular operation that the webui is doing. You can view through UI or query the audit log through audit.query
.
Wonderful! Thanks for all the info. I’m enjoying working with the API so far to script needful things for our instances 