# Can't save betterlogic variable from Homeyscript

**URL:** <https://community.homey.app/t/cant-save-betterlogic-variable-from-homeyscript/60150>\
**Category:** Questions & Help\
**Tags:** homeyscript\
**Created:** [February 10, 2022, 1:31pm UTC](https://community.homey.app/t/cant-save-betterlogic-variable-from-homeyscript/60150 "2022-02-10T13:31:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mojo](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/mojo/32/51254_2.png) [@Mojo](https://community.homey.app/u/Mojo)\
**Post date:** [February 10, 2022, 1:31pm UTC](https://community.homey.app/t/cant-save-betterlogic-variable-from-homeyscript/60150/1 "2022-02-10T13:31:47Z")

</div>

I try to create and set a betterlogic variable from Homeyscript:

```auto
let varName = "MyVar";

let betterLogicApp = await Homey.apps.getApp({ id: "net.i-dev.betterlogic" } );

let getBetterLogicVar = async (name, defaultValue) => {

  try {

    let x = await betterLogicApp.apiGet(name)

    return x.value

  } catch (error) {

    log("catch");

    betterLogicApp.apiPut(varName + "/" + defaultValue);

    return defaultValue;

  }

}

let t = await getBetterLogicVar(varName, "test");

```

But it does not save - and every run/test I make, the catch section is called.

What am I doing wrong?

Thanks.

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [February 10, 2022, 1:37pm UTC](https://community.homey.app/t/cant-save-betterlogic-variable-from-homeyscript/60150/2 "2022-02-10T13:37:16Z")

</div>

> [@Mojo](#):
>
> …and every run/test I make, the catch section is called.

`log("catch", error)`

---

<div class="post-metadata">

**Author:** ![Mojo](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/mojo/32/51254_2.png) [@Mojo](https://community.homey.app/u/Mojo)\
**Post date:** [February 10, 2022, 2:58pm UTC](https://community.homey.app/t/cant-save-betterlogic-variable-from-homeyscript/60150/3 "2022-02-10T14:58:59Z")

</div>

Sorry I have not been clear enough.

The catch section is not the problem since I expect the apiGet to fail cause there is no variables called “MyVar” yet.

My problem is that the apiPut is not storing the variable.

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [February 10, 2022, 3:04pm UTC](https://community.homey.app/t/cant-save-betterlogic-variable-from-homeyscript/60150/4 "2022-02-10T15:04:04Z")

</div>

> [@Mojo](#):
>
> My problem is that the apiPut is not storing the variable.

Looking [at the app code](https://github.com/PatrickSannes/BetterLogic/blob/master/api.js#L90-L141), you can only update existing variables, otherwise the API [returns an error](https://github.com/PatrickSannes/BetterLogic/blob/master/api.js#L135).
