Remote shutdown using JSON-RPC

Hi Guys,

I have been using the RUST API calls with curl to shutdown truenas. With the JSON-RPC 2.0 can this be done with curl or another common utility?

Thanks,

This is extremely frustrating, is it me or is the documentation poor, or not very thorough? I had to search wide to find what the new endpoints are, they don’t appear in the documentation regarding websocket. I found some info in the forum pointing to /api/current and with some testing and logic /api/v26.0.0 can be used, but I cannot find documentation on them, its feels like tribal knowledge.

When I simplify it testing with websocat, there is no information in the documentation that explains how authentication or API keys are used. I did however find TrueNAS Websocket Documentation for core, which I am sure if different. But this is the only place that points to authentication and looking deeper in the new documentation found a method auth.login_with_api_key. Great now I can authenticate and pull something simple like system.info. But can I use headers (with bearer), and json data for a simple curl command.

I fully appreciate the move to RCP and its benefits, but any guidance would be appreciated in how this works with TrueNAS, for example is it possible to use JSON-RPC over HTTP.

Are you using TrueNAS 26-BETA.1? It’s not clear from your post if you are or if you found the current documentation. If you are, there is some basic reference documentation here API Reference | TrueNAS Documentation Hub that covers things like accessing API docs, and which also links to the full API docs at https://api.truenas.com/. There are also 25.10 versions available from the version switchers on those pages.

For your specific question about HTTP and curl, I think it would be better to install the GitHub - truenas/api_client · GitHub on the remote system and communicate with TrueNAS that way. The README covers how to authenticate and structure your commands.

Hi @DjP-iX, sorry yes, I am on TrueNAS 26-BETA.1 for this box.

I’ve double check the documents you posted, but I cannot find info for endpoints and authentication. The Websocket section is limited and doesn’t have authentication details. The only API reference I found was what I posted, including the api/docs/current/ on the local host, where I found the method.

The request is coming from a device that is appliance like, but have curl easily available. Even so I might be to able to workaround it, but its a workaround, so the preference would be to use curl. Which should be workable??? As the documentation is limited I don’t know if I can use http (which can upgrade) with specific headers with the API key like I used to with RUST.

Thanks for assisting.

Hi, I’m using a Python script to remotely shut down my TRUENAS SCALE 25.10.3 server. Perhaps it can help you; the script is as follows:

import sys
from truenas_api_client import Client

host=“wss://192.168.1.5/api/current”
API_USERNAME = “xxxxx”
API_KEY =“xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”

with Client(uri=host,call_timeout=120 ,verify_ssl=False) as c:
auth_req ={
“mechanism”: “API_KEY_PLAIN”,
“username”: API_USERNAME,
“api_key”: API_KEY
}
resp = c.call(“auth.login_ex”, auth_req )
assert resp[“response_type”] == “SUCCESS”

c.call(“system.shutdown”,“Troubleshooting Issues”, timeout = 120)
print(f"FREENAS shutdown")

I used truenas/api_client to do this and so far it seems to be working.

API_USERNAME is a local TRUENAS user with administrator privileges.
API_KEY It is an API Key defined for the user described above.

The connection is via WSS; otherwise, the “auth.login_ex” authorization will not work.

I hope this helps

Regards

Thanks for providing that, however I cannot utilize it, I played with it a little though to see what I can do. Every workaround I come to, it gets road blocked. It’s a little rediculas at this point.

I played around with this for several hours and all I get is “METHOD NOT ALLOWED” responses from curl utilizing websocket. I’m coming to the conflusion that this now isn’t possible with these API change. Its just limiting, with little information in the documentation.