Restart Service on Device using Remote API

Hi all,

I’m trying to restart a device remotely using supervisor remote api as per:
https://www.balena.io/docs/reference/supervisor/supervisor-api/#restart-a-service-post-v2applicationsappidrestart-service

Most of the API endpoints on this page have description on how to use the same function remotely except these service related endpoints. Are these useable remotely? If so I believe the format would be:

   curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer <token here>" \
--data '{ "uuid" : "uuid of device", "data" : { "serviceName" : "name of service" } }' \
"https://api.balena.local/supervisor/v1/applications/{application id number}/restart-service"

I can’t see anyway to achieve this with the cli either. I have been doing this via SSH up to not but am trying to build myself some shortcut scripts. :slight_smile:

Worst case I can make script open SSH - run command and close.

Any help appreciated.

Cheers
Chris

Hi,

The operation on the supervisor you are trying to run is v2/applications/{application id number}/restart-service. It seems like you are trying to run v1/applications/{application id number}/restart-service.

Can you try the following?

   curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer <token here>" \
--data '{ "uuid" : "uuid of device", "data" : { "serviceName" : "name of service" } }' \
"https://api.balena.local/supervisor/v2/applications/{application id number}/restart-service"

Cheers,
Andreas

That works! Rookie mistake on my part.

Thanks for your help.

I am using this snippets to start the services. Just post here if this help for others.

    var options = {
          method: 'POST',
          url: `https://api.balena-cloud.com/supervisor/v2/applications/${BALENA_APP_ID}/restart-service`,
          headers: {
            'Authorization': `Bearer ${BALENA_AUTH_TOKEN}`
          },
          json: {
            "uuid": device_id,
            "data":
              { "serviceName": service_name }
          }
        };
        request(options, function (err, res, body) {
          if (err != null) {
            console.error("error", err);
          } else {
            console.log(body);
          }
        });