Documentation to use the API still needed!

I feel super dumb trying to use the API, yeah the new one: TrueNAS Websocket Documentation

I don’t want to mention how many years I spent coding and using APIs, I’d be even more ashamed.

Seriously, I thought it’d be a 10mn think to start using the API and consolidate an Infra As Code base.

I can’t understand how to read its documentation. It only shows an exemple of connection, and the link to: TrueNAS uses DDP: meteor/packages/ddp/DDP.md at devel · meteor/meteor · GitHub, which isn’t helpful at all.
I can only find few examples on the forum, AI is wrong wrong wrong, I’m stuck.

I’m using midctl hoping for a no-auth quick start:
Shouldn’t this be working?

midclt call pool.snapshottask.query '[{"dataset": "tank/mydataset"}]'

I get a

[EINVAL] query-filters: Item#0 is not valid per list types: [query-filter] Not a list

As i understand it, this only outputs json formatted data. But I only use the API this way, which isn’t the best way.

Agreed, new API docs really could be better. Filters should be list of lists where each item is [key, op, value], possible keys and value types are in second column (or one could just call method without filters and look for anything useful in output), operations are =, !=, >, <

Example to find only enabled tasks for given ds:

midclt call pool.snapshottask.query \
  '[ ["dataset", "=", "pool/name"], ["enabled", "=", true] ]'
1 Like

Just to understand what we’re talking about here, are we referring to the “new” API docs meaning the 13.0 Websocket documentation linked in the first post?

Unfortunately, like the rest of CORE, there aren’t any planned changes to improve on the 13.0 API docs, beyond possible API updates in the case of a security fix.

On a positive note, the actual new API docs coming with 25.04 have been completely rewritten to, among other things, include more how-to content.

midclt call pool.snapshottask.query '[{"dataset": "tank/mydataset"}]'

No that shouldn’t work because {"dataset": "tank/mydataset"} is not a list.
midclt call pool.snapshottask.query '[["dataset", "=", "tank/mydataset"]]'
is a properly-formatted query-filter. We actually have pretty extensive documentation on how to use query-filters under ip of server/api/docs

https://www.truenas.com/docs/scale/24.10/api/scale_websocket_api.html
If you browse to bottom there’s a query-methods section.

We also give some hints about how to translate typical SQL-style syntax into query-filters and query-options via API.

1 Like

Thanks, that’s the proper section to be able to understand how to query the API.
It’s hard to find somehow, I would expect it to be the first section of the documentation

Sounds better that the actual presentation indeed.
Where is this available? Only if you install 25.04? I couldn’t find it on the TN website

It’s available through the 25.04 UI. I don’t know anything about plans for a public URL

2 Likes

FWIW, to lookup the new API Documentation (since v24.10)

https://api.truenas.com/

1 Like

Looks fantastic!

Not quite fantastic yet in fact.

I’m still almost totally unable to use the API with midclt, as there seems be not documentation and no examples about how it’s supposed to be used.

Yes, Contents — TrueNAS API v25.04.2 documentation is available, but good luck with this!

There are no example in this documentation, it feels it’s a pure technical representation of the EP available in the python library behind it.

NB: some working EP are not even in the API doc anymore, e.g. midclt call disk.temperature
Deprecation?

How on earth is it possible to use midclt call config.save ?
I get a ValueError: Pipe ‘output’ is not open
I know I’m supposed to provide an output, but HOW ?

25.04 was in a transitional phase on the backend between our old auto-generated API documentation and the new one. Hence, not all public API methods are documented. Look at 25.10 API documentation. If you review the documentation for 25.10 there is explicit example of how to generate a downloadable configuration from config.save in the section on middleware jobs.

Not everything is going to be achievable using the midclt command. That tool was initially developed for internal / developer purposes and is a thin shell wrapper around the python API client.

That said, I’m not sure what the point is of running the midclt command locally to save a config file. There’s already a cronjob writes config backups to the configured system dataset. The point of that endpoint is to use with the core.download method to generate a http path / token from which to download the config file remotely.

That said, I opened a ticket to improve documentation for API endpoints like this: Jira

Thanks @awalkerix
Contents — TrueNAS API v25.10.2 documentation is indeed a lot better in coverage at least.
As for the explicit example, I think it’s the same content as on v25.04 and honestly I don’t get it (yet!)

My idea as for using config.save is simply to trigger a config save and get the content from an external system.

To do that you’ll want to use the python API client and not the midclt command. Jobs — TrueNAS API v25.10.2 documentation