運送設定簡介

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/v1beta/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_v1beta import GetShippingSettingsRequest
from google.shopping.merchant_accounts_v1beta 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 設定服務,管理商家帳戶的倉庫資訊:

"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. shippingsettingsGET 要求複製到 UPDATE 要求。

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

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

以下是 INSERT 要求主體範例,其中「倉庫 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 遷移,請參閱「遷移運送設定管理」一文。