Notifications
API

Notifications API

Introduction

OQ's notifications enable you to notify your users or user groups on various channels.

To notify your users you can use the notify() API. It's important to use the same key which you set to the notification template.

Mutations

notify()

ℹ️

This endpoint is only available from the server side of your application.

The notify() mutation enables you to notify:

  • A single user or multiple users
  • Users of one or multiple user groups
  • All of your users.

You can find the full API doc of this mutation here (opens in a new tab).

The API requires a key parameter that you need to configure in ROQ Console, see instructions here. There are two ways to notify users: with GraphQL query and Node.js SDK

The notified users are defined in the recipients property or variable as shown below:

mutation {
  notify(
    notification: {
      key: "aaa"
      recipients: {
        userIds: ["abc123"]
        userGroups: { operator: AND, userGroupIds: ["xyz789"] }
        excludedUserIds: ["abc123"]
        allUsers: false
      }
      data: [{ key: "xyz789", value: "xyz789" }]
    }
  ) {
    usersNotified {
      count
    }
  }
}
 
ParameterTypeDescription
keystringKey of notification-type that you created in the Console, eg."WELCOME_NOTIFICATION"
recipients:userIdsarrayArray of user IDs that are notified.
recipients:userGroupsobjectAn object that represents a list of user groups and an operator which can be set to "AND"(intersection of users) and "OR" (union of users).
recipients:excludedUserIdsarrayList of user IDs (of ROQ Platform) who shouldn't be notified. A typical use case is when a user performs an action and all users of the same user group should be notified, except for the acting user
recipients:allUsersboolIf set to true then all users will be notified.
dataarrayList of key/value pairs that you can use in the content section of the Notification template

Queries

notifications()

We can fetch notifications by using the notifications() query. You can find the full API doc of this query here (opens in a new tab).

query {
  notifications(page: 0, seen: false) {
    data {
      id
      title
      content
      icon
      seen
      read
    }
  }
}