運送設定簡介

你可以透過 ShippingSettings 資源,擷取及更新帳戶的運送設定。

Google 會自動更新部分產品的預估送達時間。 詳情請參閱「啟用自動改善功能」。

讀取、寫入或更新運送設定

如要使用 Merchant API 運送服務,請按照下列步驟操作:

  1. 發出 GET 要求,擷取帳戶的完整運送設定。
  2. 修改運送設定。
  3. 使用修改後的運送設定提出 INSERT 要求。

ETag

Etag 是經過編碼的權杖,可避免非同步更新。只要運送設定資料有任何變更,etag 就會隨之變更。使用者需要將從 GET 要求取得的 etag 複製到 INSERT 要求主體。

如果運送設定資料在 GET 要求和 INSERT 要求之間有所變更,系統會顯示錯誤訊息,要求再次發出 GET 要求,以擷取最新的 Etag 權杖。您需要呼叫 GET 要求,才能擷取新的 etag 權杖,並將新的 etag 權杖複製到 INSERT 要求主體。

新增運送設定

使用 shippingsettings.insert 新增或更新帳戶的運送設定。以下是範例要求,可將帳戶 10 底下名為「GSA Shipping - Free Ship Over $49.99」的運送服務,將 maxTransitDays 更新為 7。

POST https://merchantapi.googleapis.com/accounts/v1/accounts/{accountId}/shippingSettings/

{
  "services": [
    {
      "name": "FedEx",
      "active": true,
      "deliveryCountries": ["US"],
      "currencyCode": "USD",
      "deliveryTime": {
        "minTransitDays": 4,
        "maxTransitDays": 6,
        "minHandlingDays": 0,
        "maxHandlingDays": 0
      },
      "rateGroups": [
        {
          "singleValue": {
            "flatRate": {
              "amountMicros": 5990000,
              "currencyCode": "USD"
            }
          },
          "name": "All products"
        }
      ]
    },
    {
      "name": "GSA Shipping - Free Ship Over $49.99",
      "active": true,
      "deliveryCountries": "US",
      "currencyCode": "USD",
      "deliveryTime": {
        "minTransitDays": 3,
        "maxTransitDays": 7,
        "minHandlingDays": 1,
        "maxHandlingDays": 2
      },
      "rateGroups": [
        {
          "mainTable": {
            "rowHeaders": {
              "prices": [
                {
                  "amountMicros": 49990000,
                  "currencyCode": "USD"
                },
                {
                  "amountMicros": -1,
                  "currencyCode": "USD"
                }
              ]
            },
            "rows": [
              {
                "cells": [
                  {
                    "flatRate": {
                      "amountMicros": 6990000,
                      "currencyCode": "USD"
                    }
                  }
                ]
              },
              {
                "cells": [
                  {
                    "flatRate": {
                      "amountMicros": 0,
                      "currencyCode": "USD"
                    }
                  }
                ]
              }
            ]
          },
          "name": "Free Ship Over $49.99"
        }
      ]
    }
  ]
}

以下是可插入運送設定的範例:

Python

from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping.merchant_accounts_v1 import GetShippingSettingsRequest
from google.shopping.merchant_accounts_v1 import ShippingSettingsServiceClient

_ACCOUNT = configuration.Configuration().read_merchant_info()
_PARENT = f"accounts/{_ACCOUNT}"


def get_shipping_settings():
  """Gets the ShippingSettings for a given Merchant Center account."""

  # Gets OAuth Credentials.
  credentials = generate_user_credentials.main()

  # Creates a client.
  client = ShippingSettingsServiceClient(credentials=credentials)

  # Creates the Shipping Settings name
  name = _PARENT + "/shippingSettings"

  # Creates the request.
  request = GetShippingSettingsRequest(name=name)

  # Makes the request and prints the retrieved ShippingSettings.
  try:
    response = client.get_shipping_settings(request=request)
    print("Retrieved ShippingSettings below")
    print(response)
  except RuntimeError as e:
    print(e)


if __name__ == "__main__":
  get_shipping_settings()

設定倉庫

下列 JSON 範例說明如何使用 Merchant Shipping 設定服務,管理 Merchant Center 帳戶的倉庫資訊:

"warehouses": [
  {
    "name": "warehouse 1",
    "shippingAddress": {
      "streetAddress": {street_address},
      "city": {city},
      "administrativeArea": {administrative_area},
      "postalCode": {postal_code},
      "regionCode": {region_code}
    },
    "cutoffTime": {
      "minutes": {minutes}
    },
    "handlingDays": {handling_days},
    "businessDaysConfig": {
      "businessDays": [
        "MONDAY", "SUNDAY"
      ]
    }
  }
]

更改下列內容:

  • {street_address}:倉庫地址的街道層級部分。
  • {city}:倉庫所在的城市、城鎮或公社。
  • {administrative_area}:國家/地區的行政細分區域。例如,州/省行政區。
  • {postal_code}:郵遞區號。
  • {region_code}:字串形式的國家/地區代碼。
  • {minutes}:截止時間的分鐘數,訂單必須在這個時間前成立,才能在同一個工作天處理。
  • {handling_days}:倉庫包裝及運送商品所需的天數。

warehouses 資源是倉庫清單。每個倉庫都可以透過 warehouse.name,由運送服務的倉庫運送時間參照。

管理倉庫

如要使用 Merchant API 管理倉庫,請按照下列步驟操作:

  1. 提出 GET 要求,擷取所有現有的 shippingsettings 和倉庫。
  2. GET 要求中的 shippingsettings 複製到 UPDATE 要求。

  3. 如要在 INSERT 要求的 warehouses 部分使用倉庫,請填入倉庫。

  4. 發出包含 shippingsettingswarehouses 資源的 UPDATE 要求。

以下是 INSERT 要求主體的範例,其中 Warehouse 1 的倉庫已從紐約更新為山景城:

{
  "services": [
    {
      "name": "Standard Shipping",
      "active": true,
      "deliveryCountries": ["US", "UK"],
      "currencyCode": "USD",
      "deliveryTime": {
        "minHandlingDays": 0,
        "maxHandlingDays": 1,
        "warehouseBasedDeliveryTimes": [
{"carrier": "Fedex"
 "carrierService": "ground"
 "warehouse": "Warehouse 1"
},
{"carrier": "Fedex"
 "carrierService": "2 days"
 "warehouse": "Warehouse 2"
}
]
      },
      "rateGroups": [
        {
          "singleValue": {
            "flatRate": {
              "amountMicros": 0,
              "currencyCode": "USD"
            }
          },
          "name": "Standard Shipping"
        }
      ],
    },
    {
      "name": "Expedited",
            "flatRate": {
              "amountMicros": 9990000,
              "currencyCode": "USD"
            }
          },
          "name": "Expedited"
        }
      ],
    }
  ],
  "warehouses": [
    {
      "name": "Warehouse1",
      "shippingAddress": [
        {
        "streetAddress": "1111 shoreline street"
          "city": "Mountain View",
          "administrativeArea": "CA"
        }
      ]
    },
    {
      "name": "Warehouse 2",
      "country": "US",
      "postalCodeRanges": [
        {
        "streetAddress": "1111 5th avenue"
          "city": "New York",
          "administrativeArea": "NY"
        }
      ]
    }
  ]
}

新增當天到貨服務

如果你有店面商品目錄資料,就可以透過 Content API for Shopping 設定當天到貨運送服務。當天到貨運送服務的local_deliveryshipment_type。目前所有 local_delivery 運送服務都視為當天到貨。

你無法變更當地配送的 delivery_time 資訊。使用 shippingsettings.insert 為店面商品目錄產品設定當天到貨服務。

以下是要求主體範例,可為帳戶的所有商店新增當天到貨服務:

{
  "name": "accounts/accountId/shippingSettings",
  "services": [
    {
      "name": "Local Delivery",
      "active": true,
      "shipmentType": "local_delivery",
      "deliveryCountries": "US",
      "currencyCode": "USD",
      "rateGroups": [
        {
          "singleValue": {
            "flatRate": {
              "amountMicros": 0,
              "currencyCode": "USD"
            }
          }
        }
      ],
      "storeConfig": {
        "storeServiceType": "all stores",
        "storeCodes": [],
        "cutoffConfig": {
          "storeCloseOffsetHours": 2,
          "noDeliveryPostCutoff": true
        },
        "serviceRadius": {
          "value": 4,
          "unit": "Miles"
        }
      }
    }
  ]
}

新增次日到貨服務

如果訂單是在當天到貨服務的截止時間過後建立,系統預設會安排在隔天送達。如要關閉次日到貨功能,請將 no_delivery_post_cutoff 欄位設為 true。如果關閉次日到貨功能,運送服務只會在每天的截止時間前顯示。

次日到貨服務僅適用於shipment_typelocal_delivery時。

瞭解詳情

如要瞭解如何從 Content API for Shopping 遷移,請參閱「遷移運送設定管理」。