# Curl into https request - url

**URL:** <https://forums.balena.io/t/curl-into-https-request-url/361643>\
**Category:** Product support\
**Tags:** support\
**Created:** [August 30, 2022, 11:59am UTC](https://forums.balena.io/t/curl-into-https-request-url/361643 "2022-08-30T11:59:11Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![shpixel](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@shpixel](https://forums.balena.io/u/shpixel)\
**Post date:** [August 30, 2022, 11:59am UTC](https://forums.balena.io/t/curl-into-https-request-url/361643/1 "2022-08-30T11:59:11Z")

</div>

Hello, I was wondering how to convert the balena supervisor address into a https command. for example this:

```auto
curl --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$BALENA_APP_ID/restart-service?apikey=$BALENA_SUPERVISOR_API_KEY" -d '{"serviceName": "venue"}'

```

and break down the address so we can use it in the url:  
`HttpRequestMessage(new HttpMethod(type), $"http://{URL}/"))`

---

<div class="post-metadata">

**Author:** ![kworz](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/kworz/32/8355_2.png) [@kworz](https://forums.balena.io/u/kworz)\
**Post date:** [August 30, 2022, 12:15pm UTC](https://forums.balena.io/t/curl-into-https-request-url/361643/2 "2022-08-30T12:15:19Z")

</div>

Hey,

Following the [balena docs](https://www.balena.io/docs/reference/supervisor/supervisor-api/#interacting-with-the-balena-supervisor) you can access the supervisor using IP address:

`127.0.0.1:48484`

```javascript
const URL = "127.0.0.1:48484";

```

---

<div class="post-metadata">

**Author:** ![shpixel](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@shpixel](https://forums.balena.io/u/shpixel)\
**Post date:** [August 30, 2022, 12:58pm UTC](https://forums.balena.io/t/curl-into-https-request-url/361643/3 "2022-08-30T12:58:11Z")

</div>

> [@shpixel](#):
>
> `"$BALENA_SUPERVISOR_ADDRESS/v2/applications/$BALENA_APP_ID/restart-service?apikey=$BALENA_SUPERVISOR_API_KEY"`

So all of the “`$BALENA_SUPERVISOR_ADDRESS/v2/applications/$BALENA_APP_ID/restart-service?apikey=$BALENA_SUPERVISOR_API_KEY`” can just be “`127.0.0.1:48484/v2/applications/$BALENA_APP_ID/restart-service?apikey=$BALENA_SUPERVISOR_API_KEY`”?  
what about the key, app id and restart service?

---

<div class="post-metadata">

**Author:** ![kworz](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/kworz/32/8355_2.png) [@kworz](https://forums.balena.io/u/kworz)\
**Post date:** [August 30, 2022, 1:11pm UTC](https://forums.balena.io/t/curl-into-https-request-url/361643/4 "2022-08-30T13:11:15Z")

</div>

Well,

It depends you use case. but i if understood your problem correctly, doing from inside a container

```javascript
HttpRequestMessage(new HttpMethod(type), "http://127.0.0.1:48484/v2/applications/$BALENA_APP_ID/restart-service?apikey=$BALENA_SUPERVISOR_API_KEY"))

```

Where $BALENA\_APP\_ID is the container id your want to restart and  
$BALENA\_SUPERVISOR\_API\_KEY is given by the hypervisor as an environment variable from the container.

This should do the trick.

---

<div class="post-metadata">

**Author:** ![shpixel](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@shpixel](https://forums.balena.io/u/shpixel)\
**Post date:** [August 30, 2022, 4:51pm UTC](https://forums.balena.io/t/curl-into-https-request-url/361643/5 "2022-08-30T16:51:27Z")

</div>

for some reason I am getting `401 Unauthorized Response`, my code:

```auto
public static async Task<string> htttpBalenaClientPostRequestAsync(string contentType, string type, string URL, string content, string authenticationToken)
        {
            using (var httpClient = new HttpClient())
            {
                using (var request = new HttpRequestMessage(new HttpMethod(type), $"http://127.0.0.1:48484/{URL}/"))
                {
                    request.Content = new StringContent(content);
                    request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse(contentType);
                    var response = await httpClient.SendAsync(request);
                    return response.StatusCode.ToString();
                }
            }
        }

```

the command in the url is:`v2/applications/ $BALENA_APP_ID/restart-service?apikey=$BALENA_SUPERVISOR_API_KEY`, and I `echo` for the Id and the Key, it is a post request. did I not add the key?

---

<div class="post-metadata">

**Author:** ![kworz](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/kworz/32/8355_2.png) [@kworz](https://forums.balena.io/u/kworz)\
**Post date:** [August 31, 2022, 8:30am UTC](https://forums.balena.io/t/curl-into-https-request-url/361643/6 "2022-08-31T08:30:36Z")

</div>

From this code, the key is missing.

---

<div class="post-metadata">

**Author:** ![hraftery](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/hraftery/32/8021_2.png) [@hraftery](https://forums.balena.io/u/hraftery)\
**Post date:** [August 31, 2022, 4:55pm UTC](https://forums.balena.io/t/curl-into-https-request-url/361643/7 "2022-08-31T16:55:19Z")

</div>

If `URL` is:

`v2/applications/ $BALENA_APP_ID/restart-service?apikey=$BALENA_SUPERVISOR_API_KEY`

then `$"http://127.0.0.1:48484/{URL}/"` becomes:

`$"http://127.0.0.1:48484/v2/applications/ $BALENA_APP_ID/restart-service?apikey=$BALENA_SUPERVISOR_API_KEY/"` which is not quite right.

Perhaps try make sure there is no whitespace in `URL`, and change:

`$"http://127.0.0.1:48484/{URL}/` to  
`$"http://127.0.0.1:48484/{URL}`

so the last `/` doesn’t mess with your URL?

---

<div class="post-metadata">

**Author:** ![shpixel](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@shpixel](https://forums.balena.io/u/shpixel)\
**Post date:** [August 31, 2022, 5:52pm UTC](https://forums.balena.io/t/curl-into-https-request-url/361643/9 "2022-08-31T17:52:10Z")

</div>

perhaps I need to use in the url only until service?

like this:

```auto
public static async Task<string> SetClientBalena (string type, string param, string content)
        {
            const string AUTHENTICATION_ENV_VAR = "BALENA_API_KEY";
            string balenaAppId = Environment.GetEnvironmentVariable("BALENA_APP_ID");

            string authenticationToken = Environment.GetEnvironmentVariable(AUTHENTICATION_ENV_VAR);
            
            string balenaURL = "http://127.0.0.1:48484/v2/applications/";
            balenaURL += balenaAppId;
            if (string.IsNullOrEmpty(authenticationToken))
            {
                Logger.LogError($"Failed getting Balena Environment Variable (Authentication) {AUTHENTICATION_ENV_VAR}");
                return null;
            }
           
            authenticationToken = "Bearer " + authenticationToken;
            using (var httpClient = new HttpClient())
            {
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authenticationToken);
                using (var request = new HttpRequestMessage(new HttpMethod(type), balenaURL + param))
                {
                    request.Headers.TryAddWithoutValidation("Authorization", authenticationToken);
                    request.Content = new StringContent(content);
                    request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");

                    var response = await httpClient.SendAsync(request);
                    return response.StatusCode.ToString();
                }
            }
        }

```

where type is `POST` , content is: `"{\"serviceName\": \"venue\"}"` and my param is` "/restart-service"`
