配送设置概览

借助 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. 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 配置当天送达配送服务。当天送达配送服务的 shipment_typelocal_delivery。目前,所有 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 进行迁移,请参阅迁移配送设置管理