在 Merchant API 中,您可以將地理區域做為與 accounts.products.regionalInventories 資源相關服務的目標。您可以將區域定義為郵遞區號的集合,或在部分國家/地區使用預先定義的地理區域目標。詳情請參閱「設定區域」一文。
如要建立及更新區域,可以使用下列方法:
擷取區域
如要擷取 Merchant Center 帳戶中定義的區域,請使用
accounts.regions.get
方法。
以下是範例要求:
GET https://merchantapi.googleapis.com/accounts/v1/accounts/125222396/regions/234567?key=[YOUR_API_KEY]
以下是成功呼叫的回應範例:
HTTP/1.1 200
{
  "name": "accounts/125222396/regions/234567",
  "displayName": "Canada",
  "postalCodeArea": {
    "regionCode": "CA",
    "postalCodes": [
      {
        "begin": "L6A"
      }
    ]
  }
列出所有區域
如要在 Merchant Center 帳戶中列出區域,請使用
accounts.regions.list
方法。
以下是範例要求:
GET https://merchantapi.googleapis.com/accounts/v1/accounts/125222396/regions?pageSize=100&key=[YOUR_API_KEY]
以下是成功呼叫的回應範例:
HTTP/1.1 200
{
  "regions": [
    {
      "name": "accounts/125222396/regions/234567",
      "displayName": "Canada",
      "postalCodeArea": {
        "regionCode": "CA",
        "postalCodes": [
          {
            "begin": "L6A"
          }
        ]
      },
      "regionalInventoryEligible": true,
      "shippingEligible": true
    },
    {
      "name": "accounts/125222396/regions/Inline region",
      "displayName": "Inline region",
      "postalCodeArea": {
        "regionCode": "CA",
        "postalCodes": [
          {
            "begin": "M7B"
          }
        ]
      },
      "regionalInventoryEligible": false,
      "shippingEligible": true
    },
  ]
}
插入區域
如要在 Merchant Center 帳戶中插入區域定義,請使用
accounts.regions.create
方法。執行這項方法需要管理員存取權。
以下是範例要求:
POST https://merchantapi.googleapis.com/accounts/v1/accounts/102959835/regions?regionId=987654&key=[YOUR_API_KEY]
{
  "displayName": "TestRegion",
  "name": "987654",
  "postalCodeArea": {
    "postalCodes": [
      {
        "begin": "98109"
      }
    ],
    "regionCode": "US"
  }
}
以下是成功呼叫的回應範例:
{
     "name": "accounts/102959835/regions/987654",
  "displayName": "TestRegion",
  "postalCodeArea": {
    "regionCode": "US",
    "postalCodes": [
      {
        "begin": "98109"
      }
    ]
  },
  "regionalInventoryEligible": true,
  "shippingEligible": true
}
如要使用 AreaCode 建立新區域,請按照下列步驟操作:
以下是範例要求:
POST https://merchantapi.googleapis.com/accounts/v1/accounts/102959835/regions?regionId=168888&key=[YOUR_API_KEY] HTTP/1.1
{
  "displayName": "WA_test",
  "name": "168888",
  "geotargetArea": {
    "geotargetCriteriaIds": [
      20101
    ]
  }
}
以下是成功呼叫的回應範例:
{
  "name": "accounts/102959835/regions/168888",
  "displayName": "WA_test",
  "geotargetArea": {
    "geotargetCriteriaIds": [
      "20101"
    ]
  },
  "regionalInventoryEligible": true,
  "shippingEligible": false
}
如要更新所建立區域的 displayName 和 GeoTargetCriteriaIds,請按照下列步驟操作:
以下是範例要求:
PATCH https://merchantapi.googleapis.com/accounts/v1/accounts/102959835/regions/168888?updateMask=displayName%2CgeotargetArea&key=[YOUR_API_KEY] HTTP/1.1
{
  "displayName": "BR_test",
  "geotargetArea": {
    "geotargetCriteriaIds": [
      20100
    ]
  }
}
以下是成功呼叫的回應範例:
HTTP/1.1 200
{
  "name": "accounts/102959835/regions/168888",
  "displayName": "BR_test",
  "geotargetArea": {
    "geotargetCriteriaIds": [
      "20100"
    ]
  },
  "regionalInventoryEligible": true,
  "shippingEligible": false
}
更新區域
如要在 Merchant Center 帳戶中更新區域定義,請使用
accounts.regions.patch
方法。執行這項方法需要管理員存取權。
以下是範例要求:
PATCH https://merchantapi.googleapis.com/accounts/v1/accounts/102959835/regions/987654?updateMask=displayName%2CpostalCodeArea&key=[YOUR_API_KEY] HTTP/1.1
Authorization: Bearer [YOUR_ACCESS_TOKEN]
Accept: application/json
Content-Type: application/json
{
  "displayName": "Test",
  "postalCodeArea": {
    "postalCodes": [
      {
        "begin": "98108"
      }
    ],
    "regionCode": "US"
  }
}
以下是成功呼叫的回應範例:
{
  "name": "accounts/102959835/regions/987654",
  "displayName": "Test",
  "postalCodeArea": {
    "regionCode": "US",
    "postalCodes": [
      {
        "begin": "98108"
      }
    ]
  },
  "regionalInventoryEligible": true,
  "shippingEligible": true
}
刪除區域
如要從 Merchant Center 帳戶刪除區域定義,請使用
accounts.regions.delete
方法。執行這項方法需要管理員存取權。
以下是範例要求:
DELETE https://merchantapi.googleapis.com/accounts/v1/accounts/102959835/regions/987654?key=[YOUR_API_KEY] HTTP/1.1
以下是成功呼叫的回應範例:
HTTP/1.1 200
{}
批次作業
如果管理多個區域,Merchant API 提供批次端點,讓您在單一呼叫中建立、更新及刪除最多 100 個區域。詳情請參閱「管理區域批次處理」。