This is a an example for using the TrueNAS Websocket API using Go. It parallels the Python TrueNAS API client, found here: https://github.com/truenas/api_client
It is JSON-RPC 2.0 based, so it doesn't use the ws://truenas.address/websocket API.
On any system with Go installed (see https://go.dev/doc/install), clone this repo.
Then build the truenas_go command:
go build truenas_go.go
go install truenas_go.go
Example run:
export TRUENAS_API_KEY="1-xxxxxxxxx" # Create this on your TrueNAS, and copy the result here
truenas_go --uri ws://ip_of_your_truenas/api/current --api-key=${TRUENAS_API_KEY} --timeout 20 --method system.info
More command line examples in EXAMPLES.md
Code examples in examples/
See examples/app_upgrade/app_upgrade.go
for an example that uses a long running job and progress reporting.