Supervisor API Reboot using Python

I’m trying to create a quick python script (using the remote API proxy) to reboot one of my units running in a specific application within balena cloud. I have referenced the following in the balena documentation:

My code looks like this (I have obfuscated the device uuid and bearer token):

url = 'https://api.balena-cloud.com/supervisor/v1/reboot'
myobj = {'uuid': '--------------------------------'}
hdrs = {'Authorization': 'Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
        'Content-Type':'application/js'}

resp = requests.post(url, data=myobj, headers=hdrs)

print(resp.text)

The response I get is “At least one filter must be specified

I’m sure I am missing something simple in the formatting of the data object, but I can’t seem to figure out what that something simple is.

I should mention I am running balenaOS 2.68.1+rev1 and supervisor 12.10.1

Hi there, what does the generated post request end up looking like I wonder?

are you able to use CURL to trigger a reboot?

I was wondering that same thing. I’m gonna see if I can maybe figure out how to do that.
I’m not a developer by trade, so some of these things aren’t necessarily obvious or easy for me to figure out :slight_smile :grinning:

Hi,

I think your problem is the Content-Type you are specifying.

When I try the proper call with cURL as documented, it works fine; when I change the Content-Type to application/js instead of application/json, I see the same response you are seeing.

I tried using Postman originally to generate the POST and looking at the CURL code snippet I saw this, which isn’t quite the same as what is posted in the balena API docs:

curl --location --request POST 'https://api.balena-cloud.com/supervisor/v1/reboot' \
--header 'Content-Type: application/js' \
--header 'Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' \
--data-raw '{"uuid": "--------------------------------"}'

This also returned the response:
At least one filter must be specified

Hi cathy, did you try what @tjvv suggested and swap application/js for application/json ? :slight_smile:

Oh! I missed that suggestion! Let me try that now. Thanx!

Haha! That worked using Postman TJvV! Thank you!
Now I’ll see if I can get it working using python. Should be a simple change.
Thank you SO much!
And thank you to rcooke-warwick as well!
:grinning: