SOLVED Weird behavior of REST API /pool/id/{id}/scrub endpoint

blindfish

Cadet
Joined
May 9, 2023
Messages
4
Hi all,

I'm trying to trigger scrubbing of a pool using the REST API of TrueNAS SCALE. Specifically (running TrueNAS-SCALE-22.12.2). Specifically, I'm trying to get the poolIdIdScrubPost endpoint to work properly.
If I understand the documentation correctly, the pool's ID is specified in the URL and the request body has to contain an action parameter with a value of either START, STOP or PAUSE.

Using the poolGet endpoint I determined my pool ID to be 1.
So I tried this:
Code:
curl --location --request POST 'http://truenas/api/v2.0/pool/id/1/scrub' \
--header 'Authorization: Bearer xxxxxx' \
--header 'Content-Type: application/json' \
--data-raw '{
    "action": "START"
}'


And this is the reply I got (with code 200)
Code:
186


With each try, the number that is returned increases by one, but scrubbing does not start.
While playing around with the endpoint I decided I wanted to see it fail, so I supplied a pool ID that does not exist. The request succeeded, simply returning the next number.
This is what I have tried:
  • add an "id" parameter to the request body
  • tried the other values for "action"
  • not specifying a request body at all
  • sending an empty request body
  • tried nonsense values for "action" to see it fail - it did not, but returned the next number
  • tried nonsense values for pool ID to see it fail - it did not, but returned the next number
  • added undocumented foobar parameters to the body to see it fail (other endpoints complain about unknown parameters) - it did not, but returned the next number
I have been able to use various other endpoints (GET and POST) without issues, so I tend to rule out a general problem with my configuration and working with the API.

Has anyone ever tried this? Am I missing something or is this behavior something that should be reported?

Thanks!

Best Regards,
blindfish
 

morganL

Captain Morgan
Administrator
Moderator
iXsystems
Joined
Mar 10, 2018
Messages
2,694
Not sure, but typically scrub tasks are scheduled.

Does the pool id work with other API calls... how did you get it?

 
Last edited:

blindfish

Cadet
Joined
May 9, 2023
Messages
4
I am aware that usually scrubbing tasks are used, but since the API offers this possibility, I figured it should work. Also, you are supposed to pause a running scrub using that API endpoint.

As I wrote, I use the /pool endpoint to determine my pool ID. My machine only has a single pool, so I used
Code:
curl --location --request GET 'http://truenas/api/v2.0/pool' \
--header 'Authorization: Bearer xxxxxxxxxxx'

which yielded the expected reply
Code:
[
 {
  "id": 1,
  "name": "main",
  "guid": "14397562763518287732",
  "encrypt": 0,
  "encryptkey": "",
  "path": "/mnt/main",
  "status": "ONLINE",
  ...


And the ID does work with e.g. the /pool/id/{id}/get_disks endpoint:
Code:
curl --location --request POST 'http://truenas/api/v2.0/pool/id/1/get_disks' \
--header 'Authorization: Bearer xxxxxxxxxxx'

returns
Code:
[
 "sdc"
]
 

morganL

Captain Morgan
Administrator
Moderator
iXsystems
Joined
Mar 10, 2018
Messages
2,694
I am aware that usually scrubbing tasks are used, but since the API offers this possibility, I figured it should work. Also, you are supposed to pause a running scrub using that API endpoint.

As I wrote, I use the /pool endpoint to determine my pool ID. My machine only has a single pool, so I used
Code:
curl --location --request GET 'http://truenas/api/v2.0/pool' \
--header 'Authorization: Bearer xxxxxxxxxxx'

which yielded the expected reply
Code:
[
 {
  "id": 1,
  "name": "main",
  "guid": "14397562763518287732",
  "encrypt": 0,
  "encryptkey": "",
  "path": "/mnt/main",
  "status": "ONLINE",
  ...


And the ID does work with e.g. the /pool/id/{id}/get_disks endpoint:
Code:
curl --location --request POST 'http://truenas/api/v2.0/pool/id/1/get_disks' \
--header 'Authorization: Bearer xxxxxxxxxxx'

returns
Code:
[
 "sdc"
]
Feel free to report-a-bug - I can't see any issues with your logic. Thanks.
 

blindfish

Cadet
Joined
May 9, 2023
Messages
4
This is actually mostly resolved and was caused by me misunderstanding this part of the API documentation:
action can be either of "START", "STOP" or "PAUSE".

It made me assume I had to pass an argument with name "action" in the request body, and one of the listed values.
Turns out you just have to pass one of the listed values in the request body.
This works as expected:
Code:
curl --location --request POST 'http://truenas/api/v2.0/pool/id/1/scrub' \
--header 'Authorization: Bearer xxxxxx' \
--header 'Content-Type: application/json' \
--data-raw '"START"'


It will still return that mysterious number, but it actually does start/stop/pause scrubbing of the specified pool.

Best Regards,
blindfish
 

morganL

Captain Morgan
Administrator
Moderator
iXsystems
Joined
Mar 10, 2018
Messages
2,694
This is actually mostly resolved and was caused by me misunderstanding this part of the API documentation:


It made me assume I had to pass an argument with name "action" in the request body, and one of the listed values.
Turns out you just have to pass one of the listed values in the request body.
This works as expected:
Code:
curl --location --request POST 'http://truenas/api/v2.0/pool/id/1/scrub' \
--header 'Authorization: Bearer xxxxxx' \
--header 'Content-Type: application/json' \
--data-raw '"START"'


It will still return that mysterious number, but it actually does start/stop/pause scrubbing of the specified pool.

Best Regards,
blindfish
If the documentation can be improved... please make a suggestion.
 
Top