How to send push notifications with my app

To send push notifications with my homey app am I implementing it correctly using the web api?

I currently get a “Missing Scopes” error when trying to send a push notification but I don’ believe i’m missing anything having “homey:manager:api” already.

sendPushNotification(users: User, message: string) {

  const apiToken = await this.homey.api.getOwnerApiToken();

  for (const user of users) {
      this.log(user);
      try {
          
          const response = await this.homeyApi.flow.runFlowCardAction({
              uri: 'homey:manager:mobile',
              id: 'homey:manager:mobile:push_text',
              headers: {
                  'Authorization': `Bearer ${apiToken}`
              },
              args: {
                  user: {
                      athomId: user.id,
                      id: user.id
                  },
                  text: message
              },
          });
          ......

Maybe this Homey script gets you going

Thank you @Peter_Kawa. Though i have a working homeyscript, i will double check the post. I suspect though that my issue is more SDK related.

1 Like

The correct way of using the Web API in an app is by using homey-api:

const { HomeyAPI } = require('homey-api');
...
const api = await HomeyAPI.createAppAPI({ homey: this.homey });
...
await api.flow.runFlowCardAction(...);

Although I’m not sure if this will solve your problem regarding missing scopes.

Documentation here: HomeyAPI - Homey Web API

1 Like

You can create a timeline notication from your app and the user can decide in timeline settings if he want to get an additional push message.

1 Like

Thank you for pointing this out @RonnyW, it’s easy to forget this option also exists. In my case however, this would kind of defeat the purpose of the app, so I’m still banging my head against the wall trying to solve the scopes issue. :smile:

@Jero could you maybe advice on my issue?

I’m on the new Homey Pro 2023. Am I missing something in the code or might this be related to the ongoing changes as outlined in https://community.homey.app/t/sending-notification-will-not-work-in-homeyscript/79235/5 .

Are you using homey-api already with the code I outlined/linked to?

An app is not allowed to start Flow card actions.

1 Like

Yes, thanks. this all works as per the api guides.

So no way to send push notifications to homey mobile trough a homey app? :frowning:

No, not sure how you already are so far in development without being able to test those cards. Although I like the app idea.

Damn! thank you for your support though.
I was just practising based on your videos. Its a fully working app except the scope bounce when sending the notification - thought I just missed something :sweat_smile:.

This works wonders for me in HomeyScript so wanted to make it readily available. Guess ill trash it for now.