The notificationChannels query allows you to paginate through all of your alerting notification channels per account. You can also use the notificationChannel query to get a specific notification channel by its ID.
Dica
Note that certain secret fields (for example, passwords or API keys) are obfuscated in the returned fields.
This example returns every field for every notification channel on the supplied account ID, up to the page limit of 200. Note how we use [inline fragments][inline-fragments] to refer to the specific fields on the concrete types implementing the AlertsNotificationChannel interface.
{
actor{
account(id:YOUR_ACCOUNT_ID){
alerts{
notificationChannels{
channels{
id
name
type
...onAlertsXMattersNotificationChannel{
config{
integrationUrl
}
}
...onAlertsWebhookNotificationChannel{
config{
baseUrl
basicAuth{
password
username
}
customHttpHeaders{
name
value
}
customPayloadBody
customPayloadType
}
}
...onAlertsVictorOpsNotificationChannel{
config{
key
routeKey
}
}
...onAlertsUserNotificationChannel{
config{
userId
}
}
...onAlertsSlackNotificationChannel{
config{
teamChannel
url
}
}
...onAlertsPagerDutyNotificationChannel{
config{
apiKey
}
}
...onAlertsOpsGenieNotificationChannel{
config{
apiKey
dataCenterRegion
recipients
tags
teams
}
}
...onAlertsHipChatNotificationChannel{
config{
authToken
baseUrl
roomId
}
}
...onAlertsEmailNotificationChannel{
config{
emails
includeJson
}
}
...onAlertsCampfireNotificationChannel{
config{
room
subdomain
token
}
}
}
totalCount
nextCursor
}
}
}
}
}
If a given account's list of notification channels exceeds the 200 channel page limit, you can use the pagination cursor to retrieve additional pages.
With cursor pagination, you continue to request additional pages using the nextCursor until that field returns empty in the response. An empty nextCursor signals that you have reached the end of the result set.
Here's an example:
{
actor{
account(id:YOUR_ACCOUNT_ID){
alerts{
notificationChannels{
channels{
id
name
type
}
totalCount
nextCursor
}
}
}
}
}
The code above returns a set of results like this:
If you have a specific notification channel's ID, the API allows you to look it up directly. Note that because the specific channel is a concrete type implementing the AlertsNotificationChannel interface, you may need to specify certain fields using the ... on syntax for [inline fragments][inline-fragments].
In this example, we are retrieving a Slack channel:
{
actor{
account(id:YOUR_ACCOUNT_ID){
alerts{
notificationChannel(id:YOUR_CHANNEL_ID){
id
name
type
...onAlertsSlackNotificationChannel{
config{
teamChannel
url
}
}
}
}
}
}
}
This example returns the ID, name, and type for every notification channel on the supplied account ID, as well as a list of every policy that is associated with that channel.
{
actor{
account(id:YOUR_ACCOUNT_ID){
alerts{
notificationChannels{
channels{
id
name
type
associatedPolicies{
policies{
id
name
}
totalCount
}
}
nextCursor
totalCount
}
}
}
}
}
Create a notification channel
In order to create an alert notification channel, you need to know the specific type of notification channel you want to create (for example email, Slack, etc.), as well as the details necessary to configure it (which will depend on the channel type). Once a notification channel has been created, it can be associated with one or more [alert policies][alert-policies]. Once associated, those channels will receive notifications from those policies when conditions are breached.
Cuidado
While you can query for any existing notification channel type, you can only create a subset of them. Specifically, the user channel type has no editable fields, and the Campfire and HipChat channel types are both deprecated.
An example create mutation for an email notification channel:
mutation{
alertsNotificationChannelCreate(
accountId:YOUR_ACCOUNT_ID
notificationChannel:{
email:{
emails:["email@example.com"]
includeJson:true
name:"Some Name <email@example.com>"
}
}
){
notificationChannel{
...onAlertsEmailNotificationChannel{
id
name
type
config{
emails
includeJson
}
}
}
error{
description
errorType
}
}
}
An example create mutation for an OpsGenie notification channel:
mutation{
alertsNotificationChannelCreate(
accountId:YOUR_ACCOUNT_ID
notificationChannel:{
opsGenie:{
apiKey:"api-key-from-opsgenie"
dataCenterRegion:US
name:"OpsGenie notification channel name"
recipients:["user@example.com"]
tags:["tag1","tag2"]
teams:["team1","team2"]
}
}
){
notificationChannel{
...onAlertsOpsGenieNotificationChannel{
id
name
type
config{
apiKey
teams
tags
recipients
dataCenterRegion
}
}
}
error{
description
errorType
}
}
}
An example create mutation for a PagerDuty notification channel:
mutation{
alertsNotificationChannelCreate(
accountId:YOUR_ACCOUNT_ID
notificationChannel:{
pagerDuty:{
name:"PagerDuty notification channel name"
apiKey:"api-key-from-pagerduty"
}
}
){
notificationChannel{
...onAlertsPagerDutyNotificationChannel{
id
name
type
config{
apiKey
}
}
}
error{
description
errorType
}
}
}
An example create mutation for a Slack notification channel:
In order to update an alert notification channel, you need to know the specific type of notification channel you want to change (for example email, Slack, etc.), as well as the details necessary to configure it (which will depend on the channel type). Consistent with other GraphQL APIs, you can update a single field on the channel without knowing anything other than the channel's ID.
Cuidado
While you can query for any existing notification channel type, you can only update a subset of them. Specifically, the user channel type has no editable fields, and the Campfire and HipChat channel types are both deprecated.
An example update mutation for an email notification channel where we're updating only the name:
mutation{
alertsNotificationChannelUpdate(
accountId:YOUR_ACCOUNT_ID
id:YOUR_CHANNEL_ID
notificationChannel:{email:{name:"Updated Name <email@example.com>"}}
){
notificationChannel{
...onAlertsEmailNotificationChannel{
id
name
type
}
}
error{
description
errorType
notificationChannelId
}
}
}
An example update mutation for an OpsGenie notification channel where we're updating only the name:
You can delete a notification channel with only the account ID and the channel ID. Note that deleting a channel dissociates it from all policies, meaning that no further notifications will be sent to that channel.
mutation{
alertsNotificationChannelDelete(
accountId:YOUR_ACCOUNT_ID
id:YOUR_CHANNEL_ID
){
id
error{
description
errorType
notificationChannelId
}
}
}
Associate channels to a policy
Creating an alert notification channel is not enough: Once the channel has been created, it needs to be associated to one or more [policies][alert-policies]. Once associated to a policy, the channel can receive alert notifications when conditions on that policy exceed the threshold.
In this example, we associate two channels with a policy:
In those instances where a notification channel has outlived its usefulness (for example, an email list that has been retired), the time has come to dissociate that channel from the [policy][alert-policies] (or policies) that are sending alert notifications to it. This API call leaves the channel itself intact, but removes it from the specified policy.
In this example, we are removing two channels from a policy (leaving any others in place), and getting back confirmation that those two channel IDs have been removed:
Removing an alert notification channel from a policy does not delete the channel because it might be used by other policies. On the other hand, deleting a channel will cause all associated policies to stop sending alert notifications to that channel.