Delete a notification subscription
Stay organized with collections
Save and categorize content based on your preferences.
Merchant API code sample to delete a notification subscription.
Java
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package shopping.merchant.samples.notifications.v1;
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.notifications.v1.DeleteNotificationSubscriptionRequest;
import com.google.shopping.merchant.notifications.v1.NotificationSubscriptionName;
import com.google.shopping.merchant.notifications.v1.NotificationsApiServiceClient;
import com.google.shopping.merchant.notifications.v1.NotificationsApiServiceSettings;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/**
* This class demonstrates how to delete a specific Notification Subscription for a given Merchant
* Center account.
*/
public class DeleteNotificationSubscriptionSample {
public static void deleteNotificationSubscription(Config config) throws Exception {
// Obtains OAuth token based on the user's configuration.
GoogleCredentials credential = new Authenticator().authenticate();
// Creates service settings using the credentials retrieved above.
NotificationsApiServiceSettings notificationsApiServiceSettings =
NotificationsApiServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
// Replace "YOUR_NOTIFICATION_SUBSCRIPTION_ID" with the actual ID. This must match
// the ID used when creating/getting the subscription.
String notificationSubscriptionId = "YOUR_NOTIFICATION_SUBSCRIPTION_ID";
// Creates notification subscription name to identify the subscription.
String name =
NotificationSubscriptionName.newBuilder()
.setAccount(config.getAccountId().toString())
.setNotificationSubscription(notificationSubscriptionId)
.build()
.toString();
// Calls the API and catches and prints any network failures/errors.
try (NotificationsApiServiceClient notificationSubscriptionServiceClient =
NotificationsApiServiceClient.create(notificationsApiServiceSettings)) {
// The name has the format:
// accounts/{account}/notificationSubscription/{notification_subscription_id}
DeleteNotificationSubscriptionRequest request =
DeleteNotificationSubscriptionRequest.newBuilder().setName(name).build();
System.out.println("Sending delete Notification Subscription request:");
notificationSubscriptionServiceClient.deleteNotificationSubscription(request);
System.out.println("Deleted Notification Subscription: " + name);
} catch (Exception e) {
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
deleteNotificationSubscription(config);
}
}
PHP
<?php
/**
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
require_once __DIR__ . '/../../../vendor/autoload.php';
require_once __DIR__ . '/../../Authentication/Authentication.php';
require_once __DIR__ . '/../../Authentication/Config.php';
use Google\ApiCore\ApiException;
use Google\Shopping\Merchant\Notifications\V1\Client\NotificationsApiServiceClient;
use Google\Shopping\Merchant\Notifications\V1\DeleteNotificationSubscriptionRequest;
/**
* Deletes a Notification Subscription.
*/
class DeleteNotificationSubscription
{
/**
* Deletes a specific Notification Subscription for a given Merchant Center account.
*
* @param array $config
* Configuration data for authentication and account details.
* @param string $notificationSubscriptionId
* The ID of the notification subscription to delete.
* @throws ApiException
*/
public static function deleteNotificationSubscriptionSample($config, $notificationSubscriptionId): void
{
// Get OAuth credentials.
$credentials = Authentication::useServiceAccountOrTokenFile();
// Set up client options.
$options = ['credentials' => $credentials];
// Create a client instance.
$notificationsApiServiceClient = new NotificationsApiServiceClient($options);
// Construct the resource name.
$name = "accounts/" . $config['accountId'] .
"/notificationsubscriptions/" . $notificationSubscriptionId;
// Create the request object.
$request = new DeleteNotificationSubscriptionRequest(['name' => $name]);
print "Sending delete Notification Subscription request:\n";
// Make the API call.
try {
$notificationsApiServiceClient->deleteNotificationSubscription($request);
print "Deleted Notification Subscription: " . $name . "\n";
} catch (ApiException $e) {
print "Request failed:\n";
print $e->getMessage() . "\n";
}
}
/**
* Execute the sample.
*
* @throws ApiException
*/
public function callSample(): void
{
$config = Config::generateConfig();
// Replace with the actual notification subscription ID.
$notificationSubscriptionId = "YOUR_NOTIFICATION_SUBSCRIPTION_ID";
self::deleteNotificationSubscriptionSample($config, $notificationSubscriptionId);
}
}
// Run the script.
$sample = new DeleteNotificationSubscription();
$sample->callSample();
Python
# -*- coding: utf-8 -*-
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""A module to delete NotificationSubscription."""
from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping.merchant_notifications_v1 import DeleteNotificationSubscriptionRequest
from google.shopping.merchant_notifications_v1 import NotificationsApiServiceClient
_ACCOUNT = configuration.Configuration().read_merchant_info()
def delete_notification_subscription():
"""Deletes a specific Notification Subscription for a given Merchant Center account."""
# Gets OAuth Credentials.
credentials = generate_user_credentials.main()
# Creates a client.
client = NotificationsApiServiceClient(credentials=credentials)
# Replace "YOUR_NOTIFICATION_SUBSCRIPTION_ID" with the actual ID.
notification_subscription_id = "YOUR_NOTIFICATION_SUBSCRIPTION_ID"
# Creates notification subscription name to identify the subscription.
name = f"accounts/{_ACCOUNT}/notificationsubscriptions/{notification_subscription_id}"
# Creates the request.
request = DeleteNotificationSubscriptionRequest(name=name)
print("Sending delete Notification Subscription request:")
# Makes the request and catches and prints any error messages.
try:
client.delete_notification_subscription(request=request)
print(f"Deleted Notification Subscription: {name}")
except RuntimeError as e:
print(e)
if __name__ == "__main__":
delete_notification_subscription()
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-13 UTC.
[null,null,["Last updated 2025-08-13 UTC."],[],[],null,["# Delete a notification subscription\n\nMerchant API code sample to delete a notification subscription. \n\n### Java\n\n // Copyright 2025 Google LLC\n //\n // Licensed under the Apache License, Version 2.0 (the \"License\");\n // you may not use this file except in compliance with the License.\n // You may obtain a copy of the License at\n //\n // https://www.apache.org/licenses/LICENSE-2.0\n //\n // Unless required by applicable law or agreed to in writing, software\n // distributed under the License is distributed on an \"AS IS\" BASIS,\n // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n // See the License for the specific language governing permissions and\n // limitations under the License.\n\n package shopping.merchant.samples.notifications.v1;\n\n import com.google.api.gax.core.FixedCredentialsProvider;\n import com.google.auth.oauth2.GoogleCredentials;\n import com.google.shopping.merchant.notifications.v1.DeleteNotificationSubscriptionRequest;\n import com.google.shopping.merchant.notifications.v1.NotificationSubscriptionName;\n import com.google.shopping.merchant.notifications.v1.NotificationsApiServiceClient;\n import com.google.shopping.merchant.notifications.v1.NotificationsApiServiceSettings;\n import shopping.merchant.samples.utils.Authenticator;\n import shopping.merchant.samples.utils.Config;\n\n /**\n * This class demonstrates how to delete a specific Notification Subscription for a given Merchant\n * Center account.\n */\n public class DeleteNotificationSubscriptionSample {\n\n public static void deleteNotificationSubscription(Config config) throws Exception {\n\n // Obtains OAuth token based on the user's configuration.\n GoogleCredentials credential = new Authenticator().authenticate();\n\n // Creates service settings using the credentials retrieved above.\n NotificationsApiServiceSettings notificationsApiServiceSettings =\n NotificationsApiServiceSettings.newBuilder()\n .setCredentialsProvider(FixedCredentialsProvider.create(credential))\n .build();\n\n // Replace \"YOUR_NOTIFICATION_SUBSCRIPTION_ID\" with the actual ID. This must match\n // the ID used when creating/getting the subscription.\n String notificationSubscriptionId = \"YOUR_NOTIFICATION_SUBSCRIPTION_ID\";\n\n // Creates notification subscription name to identify the subscription.\n String name =\n NotificationSubscriptionName.newBuilder()\n .setAccount(config.getAccountId().toString())\n .setNotificationSubscription(notificationSubscriptionId)\n .build()\n .toString();\n\n // Calls the API and catches and prints any network failures/errors.\n try (NotificationsApiServiceClient notificationSubscriptionServiceClient =\n NotificationsApiServiceClient.create(notificationsApiServiceSettings)) {\n\n // The name has the format:\n // accounts/{account}/notificationSubscription/{notification_subscription_id}\n DeleteNotificationSubscriptionRequest request =\n DeleteNotificationSubscriptionRequest.newBuilder().setName(name).build();\n\n System.out.println(\"Sending delete Notification Subscription request:\");\n notificationSubscriptionServiceClient.deleteNotificationSubscription(request);\n\n System.out.println(\"Deleted Notification Subscription: \" + name);\n\n } catch (Exception e) {\n System.out.println(e);\n }\n }\n\n public static void main(String[] args) throws Exception {\n Config config = Config.load();\n deleteNotificationSubscription(config);\n }\n } \n https://github.com/google/merchant-api-samples/blob/c6de994268c785ce22af0065932518a9ac5b3c03/java/src/main/java/shopping/merchant/samples/notifications/v1/DeleteNotificationSubscriptionSample.java\n\n### PHP\n\n \u003c?php\n /**\n * Copyright 2025 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n require_once __DIR__ . '/../../../vendor/autoload.php';\n require_once __DIR__ . '/../../Authentication/Authentication.php';\n require_once __DIR__ . '/../../Authentication/Config.php';\n use Google\\ApiCore\\ApiException;\n use Google\\Shopping\\Merchant\\Notifications\\V1\\Client\\NotificationsApiServiceClient;\n use Google\\Shopping\\Merchant\\Notifications\\V1\\DeleteNotificationSubscriptionRequest;\n\n /**\n * Deletes a Notification Subscription.\n */\n class DeleteNotificationSubscription\n {\n /**\n * Deletes a specific Notification Subscription for a given Merchant Center account.\n *\n * @param array $config\n * Configuration data for authentication and account details.\n * @param string $notificationSubscriptionId\n * The ID of the notification subscription to delete.\n * @throws ApiException\n */\n public static function deleteNotificationSubscriptionSample($config, $notificationSubscriptionId): void\n {\n // Get OAuth credentials.\n $credentials = Authentication::useServiceAccountOrTokenFile();\n\n // Set up client options.\n $options = ['credentials' =\u003e $credentials];\n\n // Create a client instance.\n $notificationsApiServiceClient = new NotificationsApiServiceClient($options);\n\n // Construct the resource name.\n $name = \"accounts/\" . $config['accountId'] .\n \"/notificationsubscriptions/\" . $notificationSubscriptionId;\n\n // Create the request object.\n $request = new DeleteNotificationSubscriptionRequest(['name' =\u003e $name]);\n\n print \"Sending delete Notification Subscription request:\\n\";\n\n // Make the API call.\n try {\n $notificationsApiServiceClient-\u003edeleteNotificationSubscription($request);\n print \"Deleted Notification Subscription: \" . $name . \"\\n\";\n } catch (ApiException $e) {\n print \"Request failed:\\n\";\n print $e-\u003egetMessage() . \"\\n\";\n }\n }\n\n /**\n * Execute the sample.\n *\n * @throws ApiException\n */\n public function callSample(): void\n {\n $config = Config::generateConfig();\n // Replace with the actual notification subscription ID.\n $notificationSubscriptionId = \"YOUR_NOTIFICATION_SUBSCRIPTION_ID\";\n\n self::deleteNotificationSubscriptionSample($config, $notificationSubscriptionId);\n }\n }\n\n // Run the script.\n $sample = new DeleteNotificationSubscription();\n $sample-\u003ecallSample(); \n https://github.com/google/merchant-api-samples/blob/c6de994268c785ce22af0065932518a9ac5b3c03/php/examples/notifications/v1/DeleteNotificationSubscriptionSample.php\n\n### Python\n\n # -*- coding: utf-8 -*-\n # Copyright 2025 Google LLC\n #\n # Licensed under the Apache License, Version 2.0 (the \"License\");\n # you may not use this file except in compliance with the License.\n # You may obtain a copy of the License at\n #\n # http://www.apache.org/licenses/LICENSE-2.0\n #\n # Unless required by applicable law or agreed to in writing, software\n # distributed under the License is distributed on an \"AS IS\" BASIS,\n # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n # See the License for the specific language governing permissions and\n # limitations under the License.\n \"\"\"A module to delete NotificationSubscription.\"\"\"\n\n from examples.authentication import configuration\n from examples.authentication import generate_user_credentials\n from google.shopping.merchant_notifications_v1 import DeleteNotificationSubscriptionRequest\n from google.shopping.merchant_notifications_v1 import NotificationsApiServiceClient\n\n\n _ACCOUNT = configuration.Configuration().read_merchant_info()\n\n\n def delete_notification_subscription():\n \"\"\"Deletes a specific Notification Subscription for a given Merchant Center account.\"\"\"\n\n # Gets OAuth Credentials.\n credentials = generate_user_credentials.main()\n\n # Creates a client.\n client = NotificationsApiServiceClient(credentials=credentials)\n\n # Replace \"YOUR_NOTIFICATION_SUBSCRIPTION_ID\" with the actual ID.\n notification_subscription_id = \"YOUR_NOTIFICATION_SUBSCRIPTION_ID\"\n\n # Creates notification subscription name to identify the subscription.\n name = f\"accounts/{_ACCOUNT}/notificationsubscriptions/{notification_subscription_id}\"\n\n # Creates the request.\n request = DeleteNotificationSubscriptionRequest(name=name)\n\n print(\"Sending delete Notification Subscription request:\")\n # Makes the request and catches and prints any error messages.\n try:\n client.delete_notification_subscription(request=request)\n print(f\"Deleted Notification Subscription: {name}\")\n except RuntimeError as e:\n print(e)\n\n\n if __name__ == \"__main__\":\n delete_notification_subscription() \n https://github.com/google/merchant-api-samples/blob/c6de994268c785ce22af0065932518a9ac5b3c03/python/examples/notifications/v1/delete_notification_subscription_sample.py"]]