Regions

借助 regions 服务,您可以创建和管理地理区域 可以用作 regionalinventoryshippingsettings 服务。您可以将地区定义为邮政编码的集合,或在 部分国家/地区使用预定义的 geotargets。本指南提供了 示例,说明如何定义每种类型的区域,以及如何创建区域级 价格替换。如需详细了解 regions 服务, 包括所有可用的方法和参数,请参阅参考文档。

地区资格条件

创建区域时,区域服务将决定您是否可以使用 与其他 Content API 服务对接。为 成功的 regions.create 调用包含两个布尔值字段, regionalInventoryEligibleshippingEligible,用于指示您是否 可以将该区域与 regionalinventoryshippingsettings 服务搭配使用, 。

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*"
      }
    ]
   }
}

regions的数据用量硬性上限为 2MB。 每个 Merchant Center 账号可优惠 shippingsettings。配送和地区设置 会在内部从 MCA 复制到其所有子账号,因此对于大型 MCA 可能很快就会达到存储空间上限。在这种情况下,临时解决方法是 以在商家 ID 一级管理 regionsshippingsettings。没有任何 方法将区域配额增加到超过 2MB 的限制。

使用地理位置定位创建区域

对于巴西和俄罗斯的区域,您还可以使用 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”
}