regions
服務可讓您建立及管理地理區域,並將這些區域做為 regionalinventory
和 shippingsettings
服務的目標。您可以將區域定義為郵遞區號集合,或在部分國家/地區使用預先定義的地理位置目標。本指南提供各類型區域的定義範例,以及如何建立區域價格覆寫。如要進一步瞭解 regions
服務,包括所有可用方法和參數,請參閱參考說明文件。
符合資格的區域
建立區域時,區域服務會判斷您是否能將該區域用於其他 Content API 服務。成功呼叫 regions.create
後傳回的回應物件包含兩個布林值欄位:regionalInventoryEligible
和 shippingEligible
,分別指出您是否能搭配 regionalinventory
和 shippingsettings
服務使用該區域。
regionalInventoryEligible
如要使用 regionalinventory
服務,地區必須符合下列條件:
- 您在建立區域時指定的
regionId
只能包含數字,且至少要有 6 位數。 - 區域必須符合地理區域和線上人口的最低規模規定。
shippingEligible
如要使用 shippingsettings
服務,地區必須符合下列條件:
- 區域必須使用郵遞區號定義。
- 該區域必須位於服務支援的國家/地區。
shippingsettings
範例
以下是完整的程式碼範例,可用於在 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.content.v2_1.samples.regions; import com.google.api.client.googleapis.json.GoogleJsonResponseException; import com.google.api.services.content.model.Region; import com.google.api.services.content.model.RegionPostalCodeArea; import com.google.api.services.content.model.RegionPostalCodeAreaPostalCodeRange; import java.io.IOException; import java.util.ArrayList; import java.util.List; import shopping.content.v2_1.samples.ContentSample; /** * Creates a region. The region created here can be used with the regional inventory service. * Regional availability and pricing lets you provide product availability and variable pricing * based on your business presence and the location of your customer base. Regional availability and * pricing is available for products advertised through Shopping ads on Google Search, and listed in * free listings on the Shopping tab. */ public class RegionCreateSample extends ContentSample { public RegionCreateSample(String[] args) throws IOException { super(args); } @Override public void execute() throws IOException { checkNonMCA(); // Creates a List of Postal Code Area Postal Code Ranges. // This allows you to flexibly define regions as combinations of postal code // ranges. Each postal code range in the list has its own start and end zip code. List<RegionPostalCodeAreaPostalCodeRange> postalCodeRanges = new ArrayList<RegionPostalCodeAreaPostalCodeRange>(); // Creates a new postal code range from two postal code values. // This range is equivalent to all postal codes in the USA state of New York (00501 - 14925) RegionPostalCodeAreaPostalCodeRange postalCodeRange = new RegionPostalCodeAreaPostalCodeRange().setBegin("00501").setEnd("14925"); // Adds the NY State postal code range into the list of postal code ranges that a postal // code area accepts. postalCodeRanges.add(postalCodeRange); // Creates Postal Code Area for the Region that will be inserted, using the NY State postal code // ranges, and the US CLDR territory/country code that the postal code ranges applies to. RegionPostalCodeArea postalCodeArea = new RegionPostalCodeArea().setPostalCodes(postalCodeRanges).setRegionCode("US"); // Creates a region with example values for displayName and postalCodeArea Region region = new Region().setDisplayName("NYState").setPostalCodeArea(postalCodeArea); // Tries to create the region, and catches any exceptions try { System.out.println("Creating region"); Region result = content .regions() .create(this.config.getMerchantId().longValue(), region) .setRegionId("12345678") // User-defined, numeric, minimum of 6 digits .execute(); System.out.println("Listing succesfully created region"); System.out.println(result); } catch (GoogleJsonResponseException e) { checkGoogleJsonResponseException(e); } } public static void main(String[] args) throws IOException { new RegionCreateSample(args).execute(); } }
使用郵遞區號建立區域
您可以使用 regions.create
方法,建立以郵遞區號集合定義的區域。以下範例會指定郵遞區號範圍,為美國亞利桑那州建立新區域。
如要建立區域,請使用下列網址和要求本體提出 POST
要求:
https://shoppingcontent.googleapis.com/content/v2.1/merchantId/regions?regionId=456789
{
postalCodeArea: {
regionCode: "US",
postalCodes: [
{
begin: "850*",
end: "860*"
}
]
}
}
每個 Merchant Center 帳戶的 regions
和 shippingsettings
資料硬性限制為 2 MB。系統會將運送和區域設定從 MCA 內部複製到所有子帳戶,因此如果 MCA 較大,您可能會很快達到儲存空間上限。在這種情況下,解決方法是在商家 ID 層級管理 regions
和 shippingsettings
。區域配額無法超過 2 MB 上限。
使用地理位置目標建立區域
在巴西和俄羅斯,您也可以使用 regions.create
方法建立區域,該區域定義為地理目標的集合,也就是預先定義的地理區域。地理區域目標類型包括國家/地區、州/省、城市、鄰近地區和機場。不過,regions
服務目前只支援巴西的「州」類型和俄羅斯的「區域」類型。如要下載所有地域目標 ID 的 CSV 檔案,包括可搭配 regions
服務使用的地域目標,請參閱「地域目標」。以下範例提供三個巴西州的地理目標 ID,藉此建立新區域。
如要建立區域,請使用下列網址和要求主體提出 POST
要求:
https://shoppingcontent.googleapis.com/content/v2.1/merchantId/regions?regionId=123456
{
geoTargetAreas: {
geotargetCriteriaId: [20106, 20102, 20101] //Sao Paulo, Rio de Janeiro, Parana
}
}
使用區域建立區域價格覆寫
建立區域時,regions
服務會傳回回應物件,其中包含 regionId
和兩個 資格狀態欄位。如果 regionalInventoryEligible
值為 true
,您可以使用 regionaliventory
服務建立覆寫,為該區域設定不同價格。下例會使用上述範例中建立的郵遞區號區域 (regionId
為「456789」),建立區域價格覆寫。
如要建立覆寫,請使用下列網址和要求內容提出 POST
要求:
https://shoppingcontent.googleapis.com/content/v2.1/merchantId/products/{productId}/regionalinventory
{
“regionId”: "456789"
“price”: {
value: “10”
currency: “USD”
},
“availability”: “in stock”
}