# supervisor api restart service

**URL:** <https://forums.balena.io/t/supervisor-api-restart-service/349405>\
**Category:** Project help\
**Tags:** api\
**Created:** [September 23, 2021, 10:13am UTC](https://forums.balena.io/t/supervisor-api-restart-service/349405 "2021-09-23T10:13:02Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![fx\_sl](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/fx_sl/32/7408_2.png) [@fx\_sl](https://forums.balena.io/u/fx_sl)\
**Post date:** [September 23, 2021, 10:13am UTC](https://forums.balena.io/t/supervisor-api-restart-service/349405/1 "2021-09-23T10:13:02Z")

</div>

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](https://www.balena.io/docs/reference/supervisor/supervisor-api/#post-v2applicationsappidrestart-service)  
Here is my post url call : POST [https://api.balena-cloud.com/supervisor/v2/applications/1111111/restart-service](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 :

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

```

and the api answer is :

```auto
{
    "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

---

<div class="post-metadata">

**Author:** ![maggie0002](https://avatars.discourse-cdn.com/v4/letter/m/e19b73/32.png) [@maggie0002](https://forums.balena.io/u/maggie0002)\
**Post date:** [September 23, 2021, 10:28pm UTC](https://forums.balena.io/t/supervisor-api-restart-service/349405/2 "2021-09-23T22:28:24Z")

</div>

I’m a little confused as to what you are trying to do. The guide you mentioned ([Interacting with the balena Supervisor - Balena Documentation](https://www.balena.io/docs/reference/supervisor/supervisor-api/#post-v2applicationsappidrestart-service)) 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.

---

<div class="post-metadata">

**Author:** ![maggie0002](https://avatars.discourse-cdn.com/v4/letter/m/e19b73/32.png) [@maggie0002](https://forums.balena.io/u/maggie0002)\
**Post date:** [September 23, 2021, 10:42pm UTC](https://forums.balena.io/t/supervisor-api-restart-service/349405/3 "2021-09-23T22:42:55Z")

</div>

Maybe this, following the public url route: [Actions - Balena Documentation](https://www.balena.io/docs/learn/manage/actions/#restart-application) ?

I haven’t done it before though.

---

<div class="post-metadata">

**Author:** ![fx\_sl](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/fx_sl/32/7408_2.png) [@fx\_sl](https://forums.balena.io/u/fx_sl)\
**Post date:** [September 24, 2021, 8:33am UTC](https://forums.balena.io/t/supervisor-api-restart-service/349405/4 "2021-09-24T08:33:08Z")

</div>

Hi Maggie,

Thanks for your answer.

 ![Capture d’écran de 2021-09-24 10-28-06](https://global.discourse-cdn.com/balena/original/2X/0/0038efaf959df2645ad49774cdb85c8000c342c0.png)

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

The request is composed of :

```auto
appId	integer
data	{
    appId	integer
    imageId	integer
}
deviceId	integer

```

and the response is ok.

I wanna do the same with curl call.

---

<div class="post-metadata">

**Author:** ![maggie0002](https://avatars.discourse-cdn.com/v4/letter/m/e19b73/32.png) [@maggie0002](https://forums.balena.io/u/maggie0002)\
**Post date:** [September 25, 2021, 2:21am UTC](https://forums.balena.io/t/supervisor-api-restart-service/349405/5 "2021-09-25T02:21:01Z")

</div>

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](https://www.balena.io/docs/reference/sdk/node-sdk/#balena.models.application.restart)

---

<div class="post-metadata">

**Author:** ![maggie0002](https://avatars.discourse-cdn.com/v4/letter/m/e19b73/32.png) [@maggie0002](https://forums.balena.io/u/maggie0002)\
**Post date:** [September 25, 2021, 2:28am UTC](https://forums.balena.io/t/supervisor-api-restart-service/349405/6 "2021-09-25T02:28:25Z")

</div>

Or try some of the methods in other posts on the forums: [Restart Service on Device using Remote API](https://forums.balena.io/t/restart-service-on-device-using-remote-api/7176)

---

<div class="post-metadata">

**Author:** ![fx\_sl](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/fx_sl/32/7408_2.png) [@fx\_sl](https://forums.balena.io/u/fx_sl)\
**Post date:** [September 27, 2021, 7:51am UTC](https://forums.balena.io/t/supervisor-api-restart-service/349405/7 "2021-09-27T07:51:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mpous](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/mpous/32/4742_2.png) [@mpous](https://forums.balena.io/u/mpous)\
**Post date:** [September 27, 2021, 10:40am UTC](https://forums.balena.io/t/supervisor-api-restart-service/349405/8 "2021-09-27T10:40:44Z")

</div>

@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 @maggie0002 for your support! you rock!

---

<div class="post-metadata">

**Author:** ![fx\_sl](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/fx_sl/32/7408_2.png) [@fx\_sl](https://forums.balena.io/u/fx_sl)\
**Post date:** [September 27, 2021, 10:59am UTC](https://forums.balena.io/t/supervisor-api-restart-service/349405/10 "2021-09-27T10:59:53Z")

</div>

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

More precisely, this code was :

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

```

whereas my code was :

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

```

Maybe i misunderstood the documentation.
