您可以使用 Merchant API 保留線上區域資訊 產品。包括更新價格和供應情形,以及移除 針對不再販售某項產品的區域
如果經營電子商務平台,可以使用 Merchant API 建立 可供商家更新區域價格和供應情形的介面 我們很重視這類問題
依區域更新價格和供應情形
使用
regionalInventories.insert
敬上
更新產品的區域資訊。這場呼叫會取代
RegionalInventory
敬上
因此,請務必納入所有欄位。請參閱新增區域資訊至
線上產品
程式碼範例和詳細資料
查看現有區域
本節說明如何查看產品相關的區域 讓他們使用服務帳戶
依產品
使用
regionalInventories.list
敬上
列出與自家特定產品相關聯的所有區域性商品目錄資料
讓他們使用服務帳戶使用 region
欄位,識別各個區域商品目錄資料的區域
參照。
你可以使用以下範例列出產品的區域性商品目錄資料:
Java
public static void listRegionalInventories(Config config, String productId) throws Exception {
GoogleCredentials credential = new Authenticator().authenticate();
RegionalInventoryServiceSettings regionalInventoryServiceSettings =
RegionalInventoryServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
String parent = getParent(config.getMerchantId().toString(), productId);
try (RegionalInventoryServiceClient regionalInventoryServiceClient =
RegionalInventoryServiceClient.create(regionalInventoryServiceSettings)) {
// The parent product has the format: accounts/{account}/products/{product}
ListRegionalInventoriesRequest request =
ListRegionalInventoriesRequest.newBuilder().setParent(parent).build();
System.out.println("Sending list regional inventory request:");
ListRegionalInventoriesPagedResponse response =
regionalInventoryServiceClient.listRegionalInventories(request);
int count = 0;
// Iterates over all rows in all pages and prints the regional inventory
// in each row.
for (RegionalInventory element : response.iterateAll()) {
System.out.println(element);
count++;
}
System.out.print("The following count of elements were returned: ");
System.out.println(count);
} catch (Exception e) {
System.out.println(e);
}
}
cURL
curl --location
'https://merchantapi.googleapis.com/inventories/v1beta/accounts/987654321/products/en~US~12345/regionalInventories' \
--header 'Authorization: Bearer <API_TOKEN>'
PHP
class ListRegionalInventories
{
// ENSURE you fill in the merchant account and product ID for the sample to
// work.
private const PARENT = 'accounts/[INSERT_ACCOUNT_HERE]/products/[INSERT_PRODUCT_HERE]';
/**
* Lists all the regional inventories of a given product.
*
* @param string $parent The `name` of the parent product to list `RegionalInventory`
* resources for.
* Format: `accounts/{account}/products/{product}`
*/
function listRegionalInventoriesSample(string $parent): 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);
// Calls the API and catches and prints any network failures/errors.
try {
// Page size is set to the default value. If you are returned more
// responses than your page size, this code will automatically
// re-call the service with the `pageToken` until all responses
// are returned.
$parameters = ['pageSize' => 25000];
/** @var PagedListResponse $response */
$response =
$regionalInventoryServiceClient->listRegionalInventories($parent, $parameters);
/** @var RegionalInventory $element */
foreach ($response as $element) {
printf('RegionalInventory data: %s%s', $element->serializeToJsonString(), PHP_EOL);
}
} catch (ApiException $ex) {
printf('Call failed with message: %s%s', $ex->getMessage(), PHP_EOL);
}
}
// Helper to execute the sample.
function callSample(): void
{
// Lists all the regional inventories of the parent product.
$this->listRegionalInventoriesSample($this::PARENT);
}
}
Python
from examples.authentication import generate_user_credentials
from google.shopping import merchant_inventories_v1beta
# ENSURE you fill in the merchant account and product ID for the sample to
# work.
_ACCOUNT = "[INSERT_ACCOUNT_HERE]"
_PRODUCT = "[INSERT_PRODUCT_HERE]"
_PARENT = f"accounts/{_ACCOUNT}/products/{_PRODUCT}"
def list_regional_inventories():
"""Lists the `RegionalInventory` resources for the given product.
The response might contain fewer items than specified by
`pageSize`. If `pageToken` was returned in previous request, it can be
used to obtain additional results.
`RegionalInventory` resources are listed per product for a given account.
"""
# Gets OAuth Credentials.
credentials = generate_user_credentials.main()
# Creates a client.
client = merchant_inventories_v1beta.RegionalInventoryServiceClient(
credentials=credentials)
# Creates the request.
# Page size is set to the default value.
request = merchant_inventories_v1beta.ListRegionalInventoriesRequest(
parent=_PARENT,
page_size=25000
)
try:
# Makes the request and catch and print any error messages.
# If you are returned more responses than your page size, this code
# will automatically re-call the service with the `pageToken` until all
# responses are returned.
page_result = client.list_regional_inventories(request=request)
# Print the response.
for response in page_result:
print(response)
except Exception as e:
print("List failed")
print(e)
按照客戶篩選
您可以使用
regions.list
方法
透過 Content API for Shopping 查看帳戶的所有區域。
移除區域
以下說明如何移除不再銷售產品的地區。
來自產品
如果某項產品已不再於特定區域販售,請移除該區域
產品的區域商品目錄資訊。別擔心!您可以使用
regionalInventories.delete
敬上
從產品中移除特定的區域性商品目錄資料。
以下範例說明如何從產品中移除區域商品目錄項目:
Java
public static void deleteRegionalInventory(Config config, String productId, String regionId)
throws Exception {
// TODO(brothman): Please add more line comments to explain what each significant step is doing.
// For example:
// Obtains OAuth tokens based on the configuration.
// Creates service settings using the credentials above. Etc
GoogleCredentials credential = new Authenticator().authenticate();
RegionalInventoryServiceSettings regionalInventoryServiceSettings =
RegionalInventoryServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
String name =
RegionalInventoryName.newBuilder()
.setAccount(config.getMerchantId().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);
}
}
cURL
curl --location --request DELETE
'https://merchantapi.googleapis.com/inventories/v1beta/accounts/987654321/products/en~US~12345/regionalInventories/123456' \
--header 'Authorization: Bearer <API_TOKEN>'
PHP
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);
// Calls the API and catches and prints any network failures/errors.
try {
$regionalInventoryServiceClient->deleteRegionalInventory($formattedName);
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);
}
}
Python
from examples.authentication import generate_user_credentials
from google.shopping import merchant_inventories_v1beta
# ENSURE you fill in the merchant account and product ID and region ID
# for the sample to work.
_ACCOUNT = "[INSERT_ACCOUNT_HERE]"
_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_v1beta.RegionalInventoryServiceClient(
credentials=credentials)
# Creates the request.
request = merchant_inventories_v1beta.DeleteRegionalInventoryRequest(
name=_NAME,
)
# Makes the request and catch and print any error messages.
try:
client.delete_regional_inventory(request=request)
print("Delete successful")
except Exception as e:
print("Delete failed")
print(e)
移除 RegionalInventory
項目最多可能需要 30 分鐘
例如產品本身
這項呼叫只會從region
指定的是product
。
從帳戶
您可以使用
regions.delete
方法
,移除您不再販售產品的區域
匯入整個商家帳戶的產品