# Error trying to set environment variable with balena-cli

**URL:** <https://forums.balena.io/t/error-trying-to-set-environment-variable-with-balena-cli/6175>\
**Category:** openBalena\
**Tags:** summary\
**Created:** [April 22, 2019, 1:49pm UTC](https://forums.balena.io/t/error-trying-to-set-environment-variable-with-balena-cli/6175 "2019-04-22T13:49:37Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ajlennon](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/ajlennon/32/63_2.png) [@ajlennon](https://forums.balena.io/u/ajlennon)\
**Post date:** [April 22, 2019, 1:49pm UTC](https://forums.balena.io/t/error-trying-to-set-environment-variable-with-balena-cli/6175/1 "2019-04-22T13:49:37Z")

</div>

Hi all,

I’m trying to view / set an env var with balena-cli for OpenBalena.

`balena envs --application myApp`

I get

```auto
BalenaRequestError: Request error: Internal Server Error

Additional information may be available in debug mode. Prefix the command
line with DEBUG=1, i.e.: DEBUG=1 balena ...
If you need help, don't hesitate in contacting our support forums at
https://forums.balena.io

For bug reports or feature requests, have a look at the GitHub issues or
create a new one at: https://github.com/balena-io/balena-cli/issues/

```

Is this currently supported?

Thanks!

Alex

---

<div class="post-metadata">

**Author:** ![imrehg](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/imrehg/32/36_2.png) [@imrehg](https://forums.balena.io/u/imrehg)\
**Post date:** [April 22, 2019, 3:19pm UTC](https://forums.balena.io/t/error-trying-to-set-environment-variable-with-balena-cli/6175/3 "2019-04-22T15:19:02Z")

</div>

Hey @ajlennon, can you run the request as this, for more debug information?

```auto
DEBUG=1 balena envs --application myApp

```

What version of openBalena are you running? Other than this the rest of the system works normally?

---

<div class="post-metadata">

**Author:** ![ajlennon](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/ajlennon/32/63_2.png) [@ajlennon](https://forums.balena.io/u/ajlennon)\
**Post date:** [April 22, 2019, 4:07pm UTC](https://forums.balena.io/t/error-trying-to-set-environment-variable-with-balena-cli/6175/4 "2019-04-22T16:07:28Z")

</div>

Here’s the output

```auto
ajlennon@ajlennon-VirtualBox:~/git/does-rpi3-dash$ DEBUG=1 balena envs --application myApp
BalenaRequestError: Request error: Internal Server Error
    at /usr/lib/node_modules/balena-cli/node_modules/balena-request/build/request.js:197:17
    at tryCatcher (/usr/lib/node_modules/balena-cli/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/usr/lib/node_modules/balena-cli/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/usr/lib/node_modules/balena-cli/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/usr/lib/node_modules/balena-cli/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/usr/lib/node_modules/balena-cli/node_modules/bluebird/js/release/promise.js:694:18)
    at _drainQueueStep (/usr/lib/node_modules/balena-cli/node_modules/bluebird/js/release/async.js:138:12)
    at _drainQueue (/usr/lib/node_modules/balena-cli/node_modules/bluebird/js/release/async.js:131:9)
    at Async._drainQueues (/usr/lib/node_modules/balena-cli/node_modules/bluebird/js/release/async.js:147:5)
    at Immediate.Async.drainQueues (/usr/lib/node_modules/balena-cli/node_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:810:20)
    at tryOnImmediate (timers.js:768:5)
    at processImmediate [as _immediateCallback] (timers.js:745:5)

If you need help, don't hesitate in contacting our support forums at
https://forums.balena.io

For bug reports or feature requests, have a look at the GitHub issues or
create a new one at: https://github.com/balena-io/balena-cli/issues/

```

---

<div class="post-metadata">

**Author:** ![ajlennon](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/ajlennon/32/63_2.png) [@ajlennon](https://forums.balena.io/u/ajlennon)\
**Post date:** [April 22, 2019, 4:08pm UTC](https://forums.balena.io/t/error-trying-to-set-environment-variable-with-balena-cli/6175/5 "2019-04-22T16:08:48Z")

</div>

Looks like the hash of OpenBalena is #35ab5300e66f66df1c4dc960c47ac899a3993d53

Yes other than this all seems to be working pretty well 🙂

---

<div class="post-metadata">

**Author:** ![dfunckt](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/dfunckt/32/56_2.png) [@dfunckt](https://forums.balena.io/u/dfunckt)\
**Post date:** [April 24, 2019, 7:56am UTC](https://forums.balena.io/t/error-trying-to-set-environment-variable-with-balena-cli/6175/6 "2019-04-24T07:56:41Z")

</div>

Hello @ajlennon, see [this thread for a solution](https://forums.balena.io/t/support-for-device-environment-variables/4357/34) using the API directly. TLDR; there is some dissonance in how env vars are handled between open source and cloud API v5 because the cloud API has some additional functionality that allows it to translate a request and match the model that didn’t make it in openBalena (yet). The next openBalena release will include a fix for this issue, but until then using the API directly is the workaround.

---

<div class="post-metadata">

**Author:** ![ajlennon](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/ajlennon/32/63_2.png) [@ajlennon](https://forums.balena.io/u/ajlennon)\
**Post date:** [April 27, 2019, 12:22pm UTC](https://forums.balena.io/t/error-trying-to-set-environment-variable-with-balena-cli/6175/7 "2019-04-27T12:22:46Z")

</div>

Thanks for that @dfunckt!

---

<div class="post-metadata">

**Author:** ![thgreasi](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/thgreasi/32/454_2.png) [@thgreasi](https://forums.balena.io/u/thgreasi)\
**Post date:** [May 7, 2019, 4:27pm UTC](https://forums.balena.io/t/error-trying-to-set-environment-variable-with-balena-cli/6175/10 "2019-05-07T16:27:25Z")

</div>

Hi,  
Which balena-cli & open-balena-api versions are you using?  
Can you try whether open-balena-api v0.17.0 fixes the issue for you?

---

<div class="post-metadata">

**Author:** ![ajlennon](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/ajlennon/32/63_2.png) [@ajlennon](https://forums.balena.io/u/ajlennon)\
**Post date:** [May 7, 2019, 4:55pm UTC](https://forums.balena.io/t/error-trying-to-set-environment-variable-with-balena-cli/6175/12 "2019-05-07T16:55:50Z")

</div>

It looks like I’m running…

```auto

export OPENBALENA_API_VERSION_TAG=v0.11.8
export OPENBALENA_DB_VERSION_TAG=v2.0.3
export OPENBALENA_REGISTRY_VERSION_TAG=v2.5.0
export OPENBALENA_S3_VERSION_TAG=v2.5.0
export OPENBALENA_VPN_VERSION_TAG=v8.10.0

```

Will try to update

---

<div class="post-metadata">

**Author:** ![ajlennon](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/ajlennon/32/63_2.png) [@ajlennon](https://forums.balena.io/u/ajlennon)\
**Post date:** [May 7, 2019, 4:58pm UTC](https://forums.balena.io/t/error-trying-to-set-environment-variable-with-balena-cli/6175/13 "2019-05-07T16:58:13Z")

</div>

It looks to me like the API is still at this in the OpenBalena repo. How do I go about changing the API version I’m using (and will it break things I’m currently doing?)

> <https://github.com/balena-io/open-balena/blob/master/compose/versions>

Thanks,

Alex

---

<div class="post-metadata">

**Author:** ![richbayliss](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/richbayliss/32/1054_2.png) [@richbayliss](https://forums.balena.io/u/richbayliss)\
**Post date:** [May 8, 2019, 12:08pm UTC](https://forums.balena.io/t/error-trying-to-set-environment-variable-with-balena-cli/6175/16 "2019-05-08T12:08:44Z")

</div>

Alex,

As you have identified, the current openBalena release is using the v0.11.8 version. We pinned them like this so that we could more easily identify which versions people would have just from the openBalena version; in this case v1.0.1

To update the API manually, edit the `versions` file to use `v0.17.0` and then run the following command: `dc pull && dc stop && dc rm && dc up -d`. This will stop and remove all your containers (but not their volumes) and recreate them. You shouldn’t lose any data, but still it would be best to do a backup/snapshot before doing this.

---

<div class="post-metadata">

**Author:** ![ajlennon](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/ajlennon/32/63_2.png) [@ajlennon](https://forums.balena.io/u/ajlennon)\
**Post date:** [May 9, 2019, 9:54am UTC](https://forums.balena.io/t/error-trying-to-set-environment-variable-with-balena-cli/6175/18 "2019-05-09T09:54:43Z")

</div>

Lovely thanks @richbayliss. You guys are great!

```auto
ajlennon@ajlennon-VirtualBox:~/imx-yocto-bsp/build$ balena env add TESTKEY testvalue --application myApp
ajlennon@ajlennon-VirtualBox:~/imx-yocto-bsp/build$ balena envs --application myApp
ID NAME VALUE
6 TESTKEY testvalue

```
