Notifications
API

Notifications API

Introduction

ROQ's notifications enable you to notify your users or user groups on various channels. Please refer to the notifications feature guide for more information and instructions.

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 requiers a key parameter which you need to configure in ROQ Console, see instructions here. The notified users are defined in the recipients 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 of the acting user
recipients:allUsersboolIf set to true then all users will be notified.
dataarrayList of key/value pairs which you can use in the content section of the Notification template

Queries

notifications()

The Notification Modal UI component fetches 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
    }
  }
}