TrueNAS API Clients

As part of making TrueNAS better integrated into 3rd party solutions we are pleased to offer a couple of different API reference clients:

Both are available under open-source (LGPL) licenses and can be used to manually drive around a TrueNAS system using the API, or can be used as reference for your own projects which require direct TrueNAS integration.

As always, API documentation is available in-product, as well as on our Documentation Hub. Lastly you can use the TrueNAS AI-Powered Search to generate working examples of code which talks to the API.

Happy coding!

4 Likes

Looks like this could call for a rewrite (and probably dramatic shortening) of my script to deploy a TLS cert to TrueNAS.

What version of TrueNAS is it for?

It was written for FreeNAS 11, and AFAIK works with every release of CORE and SCALE. Rewriting it to use midclt would presumably narrow its applicability.

Thanks!
I wish I knew how to do Python coding. I can use the API in a BASH script however I suspect it would be easier to use it in Python (which I don’t know either) :disappointed_relieved:

Someday, maybe soon. :thinking:

Both of these implementations can be run as stand-alone runtimes as well, so technically you could write a bash wrapper around them. Only big hurdle there is dealing with JSON in bash is a nightmare of jq usage :slight_smile:

1 Like

Yes it is. Unfortunately that is all I know right now.

Yea, I was there a few years back. I did enough bash, jq, awk, and sed combinations until I had enough and had to go learn Golang to get some modern convenience.

2 Likes

You can look at some of our existing python scripts as a template for how to use the python client:

One of key things to realize with the python client is:

from truenas_api_client import Client

with Client() as c:
   data = c.call(<method>, <args>)

Make use of context manager. When the block indented under with Client() as c exits then resources are freed and socket is closed.

2 Likes