Homey App, Permissions HomeyApi => Flow.triggerFlow

Hey Devs,

I’m running into an issue i can’t seem to tackle.
I’m exposing homey flows to a secondary system but I am unable to trigger the flows.

Using Api Playground I am able to execute this code:

Homey.flow.triggerFlow({ id: "c4330edf-8131-4a37-9729-c83872fed6ff" })

From within the homey App I’m developing I have set app.json

  "permissions": [
    "homey:manager:api"
  ]

This is a snippet of my code:

const { HomeyAPI } = require("athom-api");
let homeyApi = await HomeyAPI.forCurrentHomey(this.homey);

...

homeyApi.flow.triggerFlow({ id: "c4330edf-8131-4a37-9729-c83872fed6ff" }).catch((e) => {
  console.warn(e);
});

From the app it doesn’t work, seem to be a permission thing. I am however able to get all flows.
Error i receive:

missing_scopes: Je hebt geen toegang om dit te doen.
at /node_modules/athom-api/dist/index.js:1:1242141
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
code: 403,
cause: t {
__athom_api_type: ‘HomeyAPI.ManagerFlow.Error’,
code: 403,
error: ‘missing_scopes’,
error_description: ‘Je hebt geen toegang om dit te doen.’,
‘$stack’: undefined
}

Does anyone have a clue what I could do to fix this?

AFAIK you can’t, apps don’t have permission to trigger flows like this.

Thanks for the quick response.

at https://apps.developer.homey.app/the-basics/app/permissions it states:

The API permission ("homey:manager:api" ) allows an app to access the Homey Web API. This web api can be used to control all of Homey (devices, Flows, etc) even if they are not part of the App that requested the permission.

Should i create a support case?

Only thing i can try is using this API approach opposed to the one i’m currently using:

(homey-api VS athom-api)

You can try, but they will probably just change the documentation :wink:

athom-api is the predecessor of homey-api, which you should be using anyway :smiley:

Helaas:

'use strict';

const Homey = require('homey');
const { HomeyAPI } = require('homey-api');

class MyApp extends Homey.App {

  /**
   * onInit is called when the app is initialized.
   */
  async onInit() {
    this.homeyApi = await HomeyAPI.createAppAPI({
      homey: this.homey,
    });

    this.homeyApi.flow.triggerFlow({ id: "c4330edf-8131-4a37-9729-c83872fed6ff" }).catch((e) => {
      console.warn(e);
    });

    this.log('MyApp has been initialized');
  }

}

module.exports = MyApp;

Log:

─────────────── Logging stdout & stderr ───────────────
[log] 2023-05-22 09:18:50 [MyApp] MyApp has been initialized
[HomeyAPIError: Je hebt geen toegang om dit te doen.] {
  statusCode: 403,
  description: 'Je hebt geen toegang om dit te doen.'
}

No, Athom will not allow executing flows from apps.
Thats why H.O.O.P was released in the Community Store.