supervisor api restart service

Hi,

I’m using Balena Supervisor API to try to make cron tasks in PHP. I would like to restart some services when they are going wild, but the API killed me.

I’m using currently POSTMAN to test API response.
I’m following this documentation page : Interacting with the balena Supervisor - Balena Documentation
Here is my post url call : POST https://api.balena-cloud.com/supervisor/v2/applications/1111111/restart-service (the appId have been changed)
For authentification i’m using the bearer token (which works in another requests)
In Body, i send raw json like this :

{
    "uuid":"my-uuid",
    "serviceName": "ui.browser"
}

and the api answer is :

{
    "status": "failed",
    "message": "This endpoint requires one of imageId or serviceName"
}

How should i declare serviceName so that the api can detect it ?

Thanks for your help !

FX

I’m a little confused as to what you are trying to do. The guide you mentioned (Interacting with the balena Supervisor - Balena Documentation) is for calls from within the Balena device. I.e. from within one container, you can call the API of the device that container is stored on, and request a reboot. But you mention using Postman? Postname is on your computer? How are you communicating with the device?

If you are looking to communicate with the device via the cloud/VPN then I don’t think they are the right docs.

Maybe this, following the public url route: Actions - Balena Documentation ?

I haven’t done it before though.

Hi Maggie,

Thanks for your answer.

when i click on the restart button on balena page, it launches :
https://api.balena-cloud.com/supervisor/v2/applications/11111111/restart-service

The request is composed of :

appId	integer
data	{
    appId	integer
    imageId	integer
}
deviceId	integer

and the response is ok.

I wanna do the same with curl call.

Not sure about that one, sorry. Never tried a remote restart.

Someone may have an answer. In the meantime you may be able to work it out by looking at the SDK docs and see how that does it. Could be this: Balena Node.js SDK - Balena Documentation

Or try some of the methods in other posts on the forums: Restart Service on Device using Remote API

1 Like

thanks for your help, i managed to fix what was wrong (serviceName must be in data object).

@fx_sl nice that you could solve your problem. Could you please introduce the complete solution for your problem so in the future the community can read it?

Thank you @Maggie for your support! you rock!

i’ve adapted the code provided in maggie’s link to understand where i’ve mistaken.

More precisely, this code was :

json: {
            "uuid": device_id,
            "data":
              { "serviceName": service_name }
          }

whereas my code was :

json: {
            "uuid": device_id,
            "serviceName": service_name 
          }

Maybe i misunderstood the documentation.

1 Like