Are notifications available via API?

Resolved

We would like to include Bettermode notifications in our own notification centre. We will build a similar notification feed to Bettermode's (bell icon, click to reveal notification feed) and would like to include Bettermode notifications amongst our own notifications.

Best case scenario: a new post appears in a user's communtity space. We are notified via API of the new notification and reflect it in our notification centre. We will handle the logic for the notification being "seen".

Is this possible? I can see that notifications can be queried in the API documentation but there's no additional info.

Thanks in advance

Best reply by Siavash Mahmoudian

Hi, Ed Jones. You can query notifications using notifications query. Here is an example of how it can look like:

query {
  notifications(limit: 10) {
    nodes {
      id
      createdAt
      actor {
        id
        name
      }
      meta {
        title
        body
        textBody
        reason
        url
      }
      read
      verb
    }
  }
}

You can also get the full objects for the target or object. But in most cases the above should be sufficient.

You can mark a notification as read using the following mutation:

mutation {
  readNotification(notificationId: "123") {
    status
  }
}

Most likely, you want to cache these queries so that when the notifications are loaded on your side, it will be almost instant to fetch Community notifications.

We do not have any webhooks for notifications at this time. The main reason is that in some cases one post can cause thousands of notifications and using regular webhook requests can cause huge loads on target servers.

However, you can listen on post-creation webhook as an example, and run any logic you have in mind and notify the relevant members.

View original
1 reply