地域

regions サービスを使用すると、regionalinventory サービスと shippingsettings サービスの両方でターゲットとして使用する地理的リージョンを作成して管理できます。地域は、郵便番号をまとめたものとして定義することも、一部の国では事前定義された地域ターゲティングを使用して定義することもできます。このガイドでは、地域のタイプを定義する方法と、地域別の価格のオーバーライドを作成する方法について例を挙げて説明します。使用可能なすべてのメソッドとパラメータなど、regions サービスの詳細については、リファレンス ドキュメントをご覧ください。

対象となるリージョン

リージョンを作成すると、そのリージョンを他の Content API サービスで使用できるかどうかが、リージョン サービスによって決定されます。regions.create の呼び出しが成功した場合に返されるレスポンス オブジェクトには、regionalInventoryEligibleshippingEligible の 2 つのブール値フィールドが含まれています。これらのフィールドはそれぞれ、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 メソッドを使用すると、郵便番号のコレクションとして定義された地域を作成できます。次の例では、郵便番号の範囲を指定して、米国アリゾナ州の新しいリージョンを作成します。

リージョンを作成するには、次の URL とリクエスト本文を含む POST リクエストを行います。

https://shoppingcontent.googleapis.com/content/v2.1/merchantId/regions?regionId=456789
{
  postalCodeArea: {
    regionCode: "US",
    postalCodes: [
      {
        begin: "850*",
        end: "860*"
      }
    ]
   }
}

regionsshippingsettings のデータは、Merchant Center アカウントごとに 2 MB に制限されています。配送と地域の設定は、MCA からすべてのサブアカウントに内部的にコピーされるため、MCA の規模が大きい場合は、すぐに保存容量の上限に達する可能性があります。この場合は、販売者 ID レベルで regionsshippingsettings を管理してください。リージョンの割り当てを 2 MB の上限を超えて増やす方法はありません。

地域ターゲティングを使用して地域を作成する

ブラジルとロシアの地域では、regions.create メソッドを使用して、地域ターゲティングの集合として定義された地域を作成することもできます。地域ターゲティングのタイプの例には、国、都道府県、都市、区域、空港などがあります。ただし、regions サービスは現在、ブラジルの「州」タイプとロシアの「地域」タイプのみをサポートしています。すべての地域ターゲティング ID の CSV ファイル(regions サービスで使用できる地域ターゲティングを含む)をダウンロードするには、地域ターゲティングをご覧ください。次の例では、ブラジルの 3 つの州の対象地域 ID を指定して、新しい地域を作成します。

リージョンを作成するには、次の URL とリクエスト本文を使用して 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 と 2 つの資格 ステータス フィールドを含むレスポンス オブジェクトを返します。regionalInventoryEligible 値が true の場合は、regionaliventory サービスを使用して、その地域で異なる価格を設定するオーバーライドを作成できます。次の例では、上記の例で作成した郵便番号ベースの地域(regionId が「456789」)を使用して、地域別の価格のオーバーライドを作成します。

オーバーライドを作成するには、次の URL とリクエスト本文を使用して POST リクエストを行います。

https://shoppingcontent.googleapis.com/content/v2.1/merchantId/products/{productId}/regionalinventory
{
  “regionId”: "456789"
  “price”: {
    value: “10”
    currency: “USD”
  },
  “availability”: “in stock”
}