# How do I use Homey.flow.updateFlow() in a homeyscript

**URL:** <https://community.homey.app/t/how-do-i-use-homey-flow-updateflow-in-a-homeyscript/42003>\
**Category:** Questions & Help\
**Tags:** homeyscript, flow\
**Created:** [January 29, 2021, 2:35pm UTC](https://community.homey.app/t/how-do-i-use-homey-flow-updateflow-in-a-homeyscript/42003 "2021-01-29T14:35:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![OH2TH](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/oh2th/32/111414_2.png) [@OH2TH](https://community.homey.app/u/OH2TH)\
**Post date:** [January 29, 2021, 2:35pm UTC](https://community.homey.app/t/how-do-i-use-homey-flow-updateflow-in-a-homeyscript/42003/1 "2021-01-29T14:35:36Z")

</div>

I’m trying to re-enable disabled flows and here I have a simplified sample of the script:

```
// Get all flows
let flows = await Homey.flow.getFlows();

// Iterate all flows
_.forEach(flows, flow => {
    // Find flows that are disabled
    if(!flow.enabled) {
        console.log(flow.id + ' ' + flow.name + ' ' + flow.enabled);
        // Enable the flow
        flow.enabled = true;
        Homey.flow.updateFlow({id: flow.id});
    }
});

return true;

```

Now that prints out the disabled flows nicely, but how do i set flow.enabled = true in that loop and update the flow. The Web API documentation doesn’t really give me the clue how to use updateFlow().  
[http://developer.athom.com/docs/api/HomeyAPI.ManagerFlow.html#updateFlow](http://developer.athom.com/docs/api/HomeyAPI.ManagerFlow.html#updateFlow)

Somehow I do not understand the document syntax and how to use those methods and opts.

Is it even possible to enable said flows from homeyscript?

---

<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:** [January 29, 2021, 2:43pm UTC](https://community.homey.app/t/how-do-i-use-homey-flow-updateflow-in-a-homeyscript/42003/2 "2021-01-29T14:43:03Z")

</div>

The documentation states that `updateFlow` take an optional (I have no idea why it’s optional, doesn’t make sense) argument `opts`, which is an object that should have two parameters (“properties” is the correct term): `id` and `flow`.

Which means this should work:

```auto
Homey.flow.updateFlow({ id : flow.id, flow })

```

(where `flow` is short for `flow: flow`)

Since the method is async, you may run into performance issues if you have lots of flows that need to be enabled in the same loop. In that case, you can do this to update each flow sequentially (instead of in parallel, which your code is doing now):

```auto
_.forEach(flows, async flow => {
  ...
       await Homey.flow.updateFlow({id: flow.id});
  ...
});

```

---

<div class="post-metadata">

**Author:** ![Dijker](https://avatars.discourse-cdn.com/v4/letter/d/b9bd4f/32.png) [@Dijker](https://community.homey.app/u/Dijker)\
**Post date:** [January 29, 2021, 4:12pm UTC](https://community.homey.app/t/how-do-i-use-homey-flow-updateflow-in-a-homeyscript/42003/3 "2021-01-29T16:12:30Z")

</div>

This was possible before Homey 2.0  
even with the correct code you can’t as HomeyScript has not the correct Permission in Homey \>= v2.0:

You need:  
**Required OAuth scopes:**

- homey.flow

but only have Readonly as stated in [HomeyScript scopes / authorization](https://community.homey.app/t/homeyscript-scopes-authorization/21513)

o, and BTW: You can from the Web API Playground, and see teh Disable/enable all Apps fe.

> [@Developer Web API Playground - Notes of geeky oneliners](https://community.homey.app/t/developer-web-api-playground-notes-of-geeky-oneliners/24392/1):
>
> ```auto
> // Search for disabled flows: by Le_Cactus
> Homey.flow.getFlows().then(f => Object.values(f).reduce((r,b)=>Object.assign(r, {[b.name]:b.enabled}), {}));
> 
> ```
