Delete a notification channel

Demonstrates how to delete a notification channel.

Explore further

For detailed documentation that includes this code sample, see the following:

Code sample


using Google.Cloud.Monitoring.V3;
using System;

partial class AlertSnippets
    public void DeleteNotificationChannel(
        string channelName = "projects/your-project-id/notificationChannels/123")
        var client = NotificationChannelServiceClient.Create();
            name: NotificationChannelName.Parse(channelName),
            force: true);
        Console.WriteLine("Deleted {0}.", channelName);


import (

	monitoring ""
	monitoringpb ""

// deleteChannel deletes the given channel. channelName should be of the form
// "projects/[PROJECT_ID]/notificationChannels/[CHANNEL_ID]".
func deleteChannel(w io.Writer, channelName string) error {
	ctx := context.Background()

	client, err := monitoring.NewNotificationChannelClient(ctx)
	if err != nil {
		return err
	defer client.Close()

	req := &monitoringpb.DeleteNotificationChannelRequest{
		Name: channelName,

	if err := client.DeleteNotificationChannel(ctx, req); err != nil {
		return fmt.Errorf("DeleteNotificationChannel: %v", err)

	fmt.Fprintf(w, "Deleted channel %q", channelName)
	return nil


static void deleteNotificationChannel(String channelName) throws IOException {
  String projectId = System.getProperty("projectId");
  try (NotificationChannelServiceClient client = NotificationChannelServiceClient.create()) {
    NotificationChannelName name = NotificationChannelName.of(projectId, channelName);
    client.deleteNotificationChannel(channelName, false);
    System.out.println("Deleted notification channel " + channelName);


// Imports the Google Cloud client library
const monitoring = require('@google-cloud/monitoring');

// Creates a client
const client = new monitoring.NotificationChannelServiceClient();

async function deleteChannels() {
   * TODO(developer): Uncomment the following lines before running the sample.
  // const projectId = 'YOUR_PROJECT_ID';
  // const filter = 'A filter for selecting policies, e.g. description:"cloud"';

  const request = {
    name: client.projectPath(projectId),
  const channels = await client.listNotificationChannels(request);
  for (const channel of channels[0]) {
    console.log(`Deleting channel ${channel.displayName}`);
    try {
      await client.deleteNotificationChannel({
    } catch (err) {
      // ignore error


use Google\Cloud\Monitoring\V3\NotificationChannelServiceClient;

 * @param string $projectId Your project ID
function alert_delete_channel($projectId, $channelId)
    $channelClient = new NotificationChannelServiceClient([
        'projectId' => $projectId,
    $channelName = $channelClient->notificationChannelName($projectId, $channelId);

    printf('Deleted notification channel %s' . PHP_EOL, $channelName);


def delete_notification_channels(project_name, channel_ids, force=None):
    """Delete alert notification channels.

        project_name (str): The Google Cloud Project to use. The project name
            must be in the format - 'projects/<PROJECT_NAME>'.
        channel_ids list(str): List of IDs of notification channels to delete.
        force (bool): If true, the notification channels are deleted regardless
            of its in use by alert policies. If false, channels that are still
            referenced by an existing alerting policy will fail to be deleted.

    channel_client = monitoring_v3.NotificationChannelServiceClient()
    for channel_id in channel_ids:
        channel_name = "{}/notificationChannels/{}".format(project_name, channel_id)
            channel_client.delete_notification_channel(name=channel_name, force=force)
            print("Channel {} deleted".format(channel_name))
        except ValueError:
            print("The parameters are invalid")
        except Exception as e:
            print("API call failed: {}".format(e))

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.