Bölgesel envanteri silme
Koleksiyonlar ile düzeninizi koruyun
İçeriği tercihlerinize göre kaydedin ve kategorilere ayırın.
Bölgesel envanteri silmek için Merchant API kod örneği.
Java
// Copyright 2023 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.inventories.v1;
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.inventories.v1.DeleteRegionalInventoryRequest;
import com.google.shopping.merchant.inventories.v1.RegionalInventoryName;
import com.google.shopping.merchant.inventories.v1.RegionalInventoryServiceClient;
import com.google.shopping.merchant.inventories.v1.RegionalInventoryServiceSettings;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/** This class demonstrates how to delete a regional inventory for a given product */
public class DeleteRegionalInventorySample {
public static void deleteRegionalInventory(Config config, String productId, String regionId)
throws Exception {
GoogleCredentials credential = new Authenticator().authenticate();
RegionalInventoryServiceSettings regionalInventoryServiceSettings =
RegionalInventoryServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
String name =
RegionalInventoryName.newBuilder()
.setAccount(config.getAccountId().toString())
.setProduct(productId)
.setRegion(regionId)
.build()
.toString();
try (RegionalInventoryServiceClient regionalInventoryServiceClient =
RegionalInventoryServiceClient.create(regionalInventoryServiceSettings)) {
DeleteRegionalInventoryRequest request =
DeleteRegionalInventoryRequest.newBuilder().setName(name).build();
System.out.println("Sending deleteRegionalInventory request");
regionalInventoryServiceClient.deleteRegionalInventory(
request); // no response returned on success
System.out.println(
"Delete successful, note that it may take up to 30 minutes for the delete to update in"
+ " the system.");
} catch (Exception e) {
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
// An ID assigned to a product by Google. In the format
// channel:contentLanguage:feedLabel:offerId
String productId = "online:en:label:1111111111";
// The ID uniquely identifying each region.
String regionId = "1111111";
deleteRegionalInventory(config, productId, regionId);
}
}
PHP
<?php
/**
* Copyright 2023 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';
use Google\ApiCore\ApiException;
use Google\Shopping\Merchant\Inventories\V1\Client\RegionalInventoryServiceClient;
use Google\Shopping\Merchant\Inventories\V1\DeleteRegionalInventoryRequest;
/**
* Deletes the specified `RegionalInventory` resource from the given product
* in your merchant account. It might take up to an hour for the
* `RegionalInventory` to be deleted from the specific product.
* Once you have received a successful delete response, wait for that
* period before attempting a delete again.
*/
class DeleteRegionalInventory
{
// ENSURE you fill in the merchant account, product, and region ID for the
// sample to work.
private const ACCOUNT = 'INSERT_ACCOUNT_ID_HERE';
private const PRODUCT = 'INSERT_PRODUCT_ID_HERE';
private const REGION = 'INSERT_REGION_ID_HERE';
/**
* Deletes a specific regional inventory of a given product.
*
* @param string $formattedName The name of the `RegionalInventory` resource
* to delete.
* Format: `accounts/{account}/products/{product}/regionalInventories/{region}`
* Please see {@see RegionalInventoryServiceClient::regionalInventoryName()}
* for help formatting this field.
*/
function deleteRegionalInventorySample(string $formattedName): void
{
// Gets the OAuth credentials to make the request.
$credentials = Authentication::useServiceAccountOrTokenFile();
// Creates options config containing credentials for the client to use.
$options = ['credentials' => $credentials];
// Creates a client.
$regionalInventoryServiceClient = new RegionalInventoryServiceClient($options);
// Prepare the request message.
$request = (new DeleteRegionalInventoryRequest())
->setName($formattedName);
// Calls the API and catches and prints any network failures/errors.
try {
$regionalInventoryServiceClient->deleteRegionalInventory($request);
print 'Delete call completed successfully.' . PHP_EOL;
} catch (ApiException $ex) {
printf('Call failed with message: %s%s', $ex->getMessage(), PHP_EOL);
}
}
/**
* Helper to execute the sample.
*/
function callSample(): void
{
// These variables are defined at the top of the file.
$formattedName = RegionalInventoryServiceClient::regionalInventoryName(
$this::ACCOUNT,
$this::PRODUCT,
$this::REGION
);
// Deletes the specific regional inventory of the parent product.
$this->deleteRegionalInventorySample($formattedName);
}
}
$sample = new DeleteRegionalInventory();
$sample->callSample();
Python
# -*- coding: utf-8 -*-
# Copyright 2024 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 a Regional Inventory."""
from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping import merchant_inventories_v1
# ENSURE you fill in the product ID and region ID
# for the sample to work.
_ACCOUNT = configuration.Configuration().read_merchant_info()
_PRODUCT = "[INSERT_PRODUCT_HERE]"
_REGION = "[INSERT_REGION_HERE]"
_NAME = f"accounts/{_ACCOUNT}/products/{_PRODUCT}/regionalInventories/{_REGION}"
def delete_regional_inventory():
"""Deletes the specified `RegionalInventory` resource from the given product.
It might take up to an hour for the `RegionalInventory` to be deleted
from the specific product. Once you have received a successful delete
response, wait for that period before attempting a delete again.
"""
# Gets OAuth Credentials.
credentials = generate_user_credentials.main()
# Creates a client.
client = merchant_inventories_v1.RegionalInventoryServiceClient(
credentials=credentials)
# Creates the request.
request = merchant_inventories_v1.DeleteRegionalInventoryRequest(
name=_NAME,
)
# Makes the request and catch and print any error messages.
try:
client.delete_regional_inventory(request=request)
print("Delete successful")
except RuntimeError as e:
print("Delete failed")
print(e)
if __name__ == "__main__":
delete_regional_inventory()
Aksi belirtilmediği sürece bu sayfanın içeriği Creative Commons Atıf 4.0 Lisansı altında ve kod örnekleri Apache 2.0 Lisansı altında lisanslanmıştır. Ayrıntılı bilgi için Google Developers Site Politikaları'na göz atın. Java, Oracle ve/veya satış ortaklarının tescilli ticari markasıdır.
Son güncelleme tarihi: 2025-08-21 UTC.
[null,null,["Son güncelleme tarihi: 2025-08-21 UTC."],[[["\u003cp\u003eThis page provides code samples in Java, cURL, PHP, and Python demonstrating how to delete a regional inventory for a product.\u003c/p\u003e\n"],["\u003cp\u003eThe samples cover the process of authenticating, building the request, and sending it to the Google Merchant Center API.\u003c/p\u003e\n"],["\u003cp\u003eDeleting a regional inventory removes product availability information for a specific region.\u003c/p\u003e\n"],["\u003cp\u003eNote: It may take up to 30 minutes for the delete to be fully reflected in the system.\u003c/p\u003e\n"]]],[],null,["# Delete a regional inventory\n\nMerchant API code sample to delete a regional inventory. \n\n### Java\n\n // Copyright 2023 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.inventories.v1;\n import com.google.api.gax.core.FixedCredentialsProvider;\n import com.google.auth.oauth2.GoogleCredentials;\n import com.google.shopping.merchant.inventories.v1.DeleteRegionalInventoryRequest;\n import com.google.shopping.merchant.inventories.v1.RegionalInventoryName;\n import com.google.shopping.merchant.inventories.v1.RegionalInventoryServiceClient;\n import com.google.shopping.merchant.inventories.v1.RegionalInventoryServiceSettings;\n import shopping.merchant.samples.utils.Authenticator;\n import shopping.merchant.samples.utils.Config;\n\n /** This class demonstrates how to delete a regional inventory for a given product */\n public class DeleteRegionalInventorySample {\n\n public static void deleteRegionalInventory(Config config, String productId, String regionId)\n throws Exception {\n\n GoogleCredentials credential = new Authenticator().authenticate();\n\n RegionalInventoryServiceSettings regionalInventoryServiceSettings =\n RegionalInventoryServiceSettings.newBuilder()\n .setCredentialsProvider(FixedCredentialsProvider.create(credential))\n .build();\n\n String name =\n RegionalInventoryName.newBuilder()\n .setAccount(config.getAccountId().toString())\n .setProduct(productId)\n .setRegion(regionId)\n .build()\n .toString();\n\n try (RegionalInventoryServiceClient regionalInventoryServiceClient =\n RegionalInventoryServiceClient.create(regionalInventoryServiceSettings)) {\n DeleteRegionalInventoryRequest request =\n DeleteRegionalInventoryRequest.newBuilder().setName(name).build();\n\n System.out.println(\"Sending deleteRegionalInventory request\");\n regionalInventoryServiceClient.deleteRegionalInventory(\n request); // no response returned on success\n System.out.println(\n \"Delete successful, note that it may take up to 30 minutes for the delete to update in\"\n + \" the system.\");\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 // An ID assigned to a product by Google. In the format\n // channel:contentLanguage:feedLabel:offerId\n String productId = \"online:en:label:1111111111\";\n // The ID uniquely identifying each region.\n String regionId = \"1111111\";\n\n deleteRegionalInventory(config, productId, regionId);\n }\n } \n https://github.com/google/merchant-api-samples/blob/c6de994268c785ce22af0065932518a9ac5b3c03/java/src/main/java/shopping/merchant/samples/inventories/v1/DeleteRegionalInventorySample.java\n\n### PHP\n\n \u003c?php\n\n /**\n * Copyright 2023 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 use Google\\ApiCore\\ApiException;\n use Google\\Shopping\\Merchant\\Inventories\\V1\\Client\\RegionalInventoryServiceClient;\n use Google\\Shopping\\Merchant\\Inventories\\V1\\DeleteRegionalInventoryRequest;\n\n /**\n * Deletes the specified `RegionalInventory` resource from the given product\n * in your merchant account. It might take up to an hour for the\n * `RegionalInventory` to be deleted from the specific product.\n * Once you have received a successful delete response, wait for that\n * period before attempting a delete again.\n */\n\n class DeleteRegionalInventory\n {\n\n // ENSURE you fill in the merchant account, product, and region ID for the\n // sample to work.\n private const ACCOUNT = 'INSERT_ACCOUNT_ID_HERE';\n private const PRODUCT = 'INSERT_PRODUCT_ID_HERE';\n private const REGION = 'INSERT_REGION_ID_HERE';\n\n /**\n * Deletes a specific regional inventory of a given product.\n *\n * @param string $formattedName The name of the `RegionalInventory` resource\n * to delete.\n * Format: `accounts/{account}/products/{product}/regionalInventories/{region}`\n * Please see {@see RegionalInventoryServiceClient::regionalInventoryName()}\n * for help formatting this field.\n */\n function deleteRegionalInventorySample(string $formattedName): void\n {\n // Gets the OAuth credentials to make the request.\n $credentials = Authentication::useServiceAccountOrTokenFile();\n\n // Creates options config containing credentials for the client to use.\n $options = ['credentials' =\u003e $credentials];\n\n // Creates a client.\n $regionalInventoryServiceClient = new RegionalInventoryServiceClient($options);\n\n\n // Prepare the request message.\n $request = (new DeleteRegionalInventoryRequest())\n -\u003esetName($formattedName);\n\n // Calls the API and catches and prints any network failures/errors.\n try {\n $regionalInventoryServiceClient-\u003edeleteRegionalInventory($request);\n print 'Delete call completed successfully.' . PHP_EOL;\n } catch (ApiException $ex) {\n printf('Call failed with message: %s%s', $ex-\u003egetMessage(), PHP_EOL);\n }\n }\n\n /**\n * Helper to execute the sample.\n */\n function callSample(): void\n {\n // These variables are defined at the top of the file.\n $formattedName = RegionalInventoryServiceClient::regionalInventoryName(\n $this::ACCOUNT,\n $this::PRODUCT,\n $this::REGION\n );\n\n // Deletes the specific regional inventory of the parent product.\n $this-\u003edeleteRegionalInventorySample($formattedName);\n }\n }\n\n\n $sample = new DeleteRegionalInventory();\n $sample-\u003ecallSample(); \n https://github.com/google/merchant-api-samples/blob/c6de994268c785ce22af0065932518a9ac5b3c03/php/examples/inventories/v1/DeleteRegionalInventorySample.php\n\n### Python\n\n # -*- coding: utf-8 -*-\n # Copyright 2024 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 a Regional Inventory.\"\"\"\n\n from examples.authentication import configuration\n from examples.authentication import generate_user_credentials\n from google.shopping import merchant_inventories_v1\n\n # ENSURE you fill in the product ID and region ID\n # for the sample to work.\n _ACCOUNT = configuration.Configuration().read_merchant_info()\n _PRODUCT = \"[INSERT_PRODUCT_HERE]\"\n _REGION = \"[INSERT_REGION_HERE]\"\n _NAME = f\"accounts/{_ACCOUNT}/products/{_PRODUCT}/regionalInventories/{_REGION}\"\n\n\n def delete_regional_inventory():\n \"\"\"Deletes the specified `RegionalInventory` resource from the given product.\n\n It might take up to an hour for the `RegionalInventory` to be deleted\n from the specific product. Once you have received a successful delete\n response, wait for that period before attempting a delete again.\n \"\"\"\n\n # Gets OAuth Credentials.\n credentials = generate_user_credentials.main()\n\n # Creates a client.\n client = merchant_inventories_v1.RegionalInventoryServiceClient(\n credentials=credentials)\n\n # Creates the request.\n request = merchant_inventories_v1.DeleteRegionalInventoryRequest(\n name=_NAME,\n )\n\n # Makes the request and catch and print any error messages.\n try:\n client.delete_regional_inventory(request=request)\n print(\"Delete successful\")\n except RuntimeError as e:\n print(\"Delete failed\")\n print(e)\n\n\n if __name__ == \"__main__\":\n delete_regional_inventory()\n\n https://github.com/google/merchant-api-samples/blob/c6de994268c785ce22af0065932518a9ac5b3c03/python/examples/inventories/v1/delete_regional_inventory_sample.py"]]