# Run a script from another script

**URL:** <https://community.homey.app/t/run-a-script-from-another-script/153522>\
**Category:** Developers\
**Tags:** homey-pro\
**Created:** [April 8, 2026, 12:41pm UTC](https://community.homey.app/t/run-a-script-from-another-script/153522 "2026-04-08T12:41:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![GD91](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/gd91/32/78099_2.png) [@GD91](https://community.homey.app/u/GD91)\
**Post date:** [April 8, 2026, 12:41pm UTC](https://community.homey.app/t/run-a-script-from-another-script/153522/1 "2026-04-08T12:41:12Z")

</div>

I tried several ways to launch a script from another one  
I’m note sure that my way is the best one  
try {

```
  const url = \`http://127.0.0.1/api/app/com.athom.homeyscript/script/${encodeURIComponent(SCRIPT_ID)}/run\`;

  const response = await fetch(url, {

    method: 'POST',

    headers: {

      'Authorization': \`Bearer ${API_KEY}\`, 

      'Content-Type': 'application/json'

    },

    body: JSON.stringify({ args: \[payload\] })

  });

  if (response.status === 401) {

      console.error("Clé API refusée (401). Vérifier API_KEY .");

      return; 

  }

  const data = await response.json();

  console.log(\`Réponse : OK\`);

} catch (e) {

  console.error(\`Erreur : ${e.message}\`);

}

```

---

<div class="post-metadata">

**Author:** ![Justin\_de\_Knegt](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/justin_de_knegt/32/114526_2.png) [@Justin\_de\_Knegt](https://community.homey.app/u/Justin_de_Knegt)\
**Post date:** [September 3, 2026, 7:37am UTC](https://community.homey.app/t/run-a-script-from-another-script/153522/2 "2026-09-03T07:37:53Z")

</div>

Just to be sure : do you want feedback on this script to optimize it or is this script not working and you want help to get it working ?

I’m a bit confused about what you want to know 🙂

---

<div class="post-metadata">

**Author:** ![smarthomesven](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/smarthomesven/32/79712_2.png) [@smarthomesven](https://community.homey.app/u/smarthomesven)\
**Post date:** [September 3, 2026, 9:35am UTC](https://community.homey.app/t/run-a-script-from-another-script/153522/3 "2026-09-03T09:35:34Z")

</div>

That API key expires quickly AFAIK. You’d need the full token refresh logic as well if this is a permanent solution.
