# Fetch request - Somfy Protect

**URL:** <https://community.homey.app/t/fetch-request-somfy-protect/95123>\
**Category:** Questions & Help\
**Created:** [November 19, 2023, 5:54pm UTC](https://community.homey.app/t/fetch-request-somfy-protect/95123 "2023-11-19T17:54:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeff\_McFly](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jeff_mcfly/32/91854_2.png) [@Jeff\_McFly](https://community.homey.app/u/Jeff_McFly)\
**Post date:** [November 19, 2023, 5:54pm UTC](https://community.homey.app/t/fetch-request-somfy-protect/95123/1 "2023-11-19T17:54:34Z")

</div>

Hi,

I’d like to control my Somfy Protect (formally known as MyFox) alarm system directly from Homey. Unfortunately, there is currently no app available. However, I have found a few developments that seem to work on other systems:

> **[GitHub - alxscms/homebridge-somfy-protect](https://github.com/alxscms/homebridge-somfy-protect)**
>
> Contribute to alxscms/homebridge-somfy-protect development by creating an account on GitHub.

> **[GitHub - Minims/SomfyProtect2MQTT: Somfy Protect to MQTT](https://github.com/Minims/SomfyProtect2MQTT)**
>
> Somfy Protect to MQTT. Contribute to Minims/SomfyProtect2MQTT development by creating an account on GitHub.

I’m trying to implement the same commands in HomeyScript using the fetch function, but I’m already stuck on the request to obtain a token.

```auto
const CLIENT_ID = "84eddf48-2b8e-11e5-b2a5-124cfab25595_475buqrf8v8kgwoo4gow08gkkc0ck80488wo44s8o48sg84k40";
const CLIENT_SECRET = "4dsqfntieu0wckwwo40kw848gw4o0c8k4owc80k4go0cs0k844";
const CLIENT_USERNAME = "***";
const CLIENT_PASSWORD = "***";

async function getNewToken(){
  const token = await fetch('https://sso.myfox.io/oauth/oauth/v2/token', {
    method: "POST",
    client_id: CLIENT_ID,
    client_secret: CLIENT_SECRET,
    username: CLIENT_USERNAME,
    password: CLIENT_PASSWORD,
    grant_type: 'password'
  });
  const data = await token.json();
  return data;
};

log(await getNewToken());

```

I got the following answer, which is exactly the same as if I put the URL in my browser’s address bar :

```auto
{
  message: 'error.invalid.token',
  data: [],
  uid: '655a49a09b474',
  error: 'invalid_client'
}

```

Could someone help me or explain how to do this, if possible? I’m new to this type of request.

Thx

---

<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:** [November 19, 2023, 8:06pm UTC](https://community.homey.app/t/fetch-request-somfy-protect/95123/2 "2023-11-19T20:06:45Z")

</div>

> [@Jeff\_McFly](#):
>
> ```auto
> const token = await fetch('https://sso.myfox.io/oauth/oauth/v2/token', {
> method: "POST",
> client_id: CLIENT_ID,
> client_secret: CLIENT_SECRET,
> username: CLIENT_USERNAME,
> password: CLIENT_PASSWORD,
> grant_type: 'password'
> });
> 
> ```

Most of the data should be passed as a (probably JSON?) string:

```auto
const token = await fetch('https://sso.myfox.io/oauth/oauth/v2/token', {
    method: "POST",
    headers: { 'content-type' : 'application/json' },
    body: JSON.stringify({
      client_id: CLIENT_ID,
      client_secret: CLIENT_SECRET,
      username: CLIENT_USERNAME,
      password: CLIENT_PASSWORD,
      grant_type: 'password'
    })
  });

```

---

<div class="post-metadata">

**Author:** ![Jeff\_McFly](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jeff_mcfly/32/91854_2.png) [@Jeff\_McFly](https://community.homey.app/u/Jeff_McFly)\
**Post date:** [November 25, 2023, 8:33pm UTC](https://community.homey.app/t/fetch-request-somfy-protect/95123/3 "2023-11-25T20:33:46Z")

</div>

> [@robertklep](#):
>
> ```auto
> const token = await fetch('https://sso.myfox.io/oauth/oauth/v2/token', {
> method: "POST",
> headers: { 'content-type' : 'application/json' },
> body: JSON.stringify({
> client_id: CLIENT_ID,
> client_secret: CLIENT_SECRET,
> username: CLIENT_USERNAME,
> password: CLIENT_PASSWORD,
> grant_type: 'password'
> })
> });
> 
> ```

Thank you very much for your help, it works ! 🙂

---

<div class="post-metadata">

**Author:** ![McGyver](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/mcgyver/32/16562_2.png) [@McGyver](https://community.homey.app/u/McGyver)\
**Post date:** [February 6, 2025, 9:49pm UTC](https://community.homey.app/t/fetch-request-somfy-protect/95123/4 "2025-02-06T21:49:32Z")

</div>

Hi! Can you help me which steps I need to take to have Somfy Protect in Homey? I’m not technical but would love to send a command to Somfy Protect from my Homey.
