地点
通过 client.locations 列出、创建、更新、归档、搜索和检索地点。
所有地点方法都位于 client.locations 下。使用这些方法之前,请安装 SDK 并配置您的密钥;请参阅安装和快速入门。
地点 ID
接受 location_id 参数的方法既支持数字 ID(16808),也支持其 base64 编码形式("TG9jYXRpb246MTY4MDg=")。SDK 会自动对数字 ID 进行编码,因此这 2 种形式可以互换使用:
# These are equivalentclient.locations.retrieve(16808)client.locations.retrieve("TG9jYXRpb246MTY4MDg=")locations.add
将所有必填字段作为关键字参数传入,即可通过一次调用创建地点。这是推荐的地点创建方式。SDK 会在客户端验证数据是否满足 API 的创建要求,并在发起任何网络调用之前抛出 ValidationError,因此无效载荷会立即导致调用失败,并返回明确的错误消息。
client.locations.add( *, name: str, description: str, sub_category_id: int, country_iso: str, city: str | None = None, street: str | None = None, state_iso: str | None = None, postal_code: str | None = None, phone: str | None = None, website: str | None = None, store_id: str | None = None, hide_address: bool | None = None, business_hours: list[dict] | None = None, service_area: dict | None = None, place_action_links: list[dict] | None = None, enabled_site_ids: list[int] | None = None, additional_fields: dict | None = None,) -> APIObject客户端验证会检查:name 为 2-150 个字符,description 至少为 200 个字符,已提供 sub_category_id 和 country_iso,并且除非满足 hide_address=True,否则必须提供 city。
返回值为创建操作的载荷:.location 包含新建的地点。您无需检查成功标志;当 API 拒绝载荷时,SDK 会抛出 ValidationError。
result = client.locations.add( name="Acme Dental", description=( "Acme Dental is a family-owned dental practice offering general, " "cosmetic, and pediatric dentistry in the heart of New York. Our " "team provides cleanings, fillings, crowns, whitening, and same-day " "emergency care in a modern, comfortable office with weekend hours " "and easy online booking for new and returning patients." ), sub_category_id=1432, country_iso="US", city="New York", street="123 Jump Street", state_iso="NY", postal_code="10013", phone="6443859313", website="https://acmedental.example.com", store_id="NYC-001", place_action_links=[ {"placeActionType": "APPOINTMENT", "uri": "https://acmedental.example.com/book", "isPreferred": True}, ], enabled_site_ids=[1, 24, 87],)print("Created:", result.location.id, result.location.name)locations.list
使用基于游标的分页列出地点。返回 SyncPage。
client.locations.list( *, first: int | None = None, after: str | None = None, before: str | None = None, last: int | None = None,) -> SyncPage# First page of 25page = client.locations.list(first=25)for loc in page: print(loc.name, loc.city) # Next page manuallyif page.has_more: page2 = page.next_page() # Auto-paginate all locationsfor loc in client.locations.list(first=100).auto_paging_iter(): print(loc.name)locations.retrieve
按 ID 获取单个地点。如果 ID 不存在,则抛出 NotFoundError。
client.locations.retrieve(location_id: str | int) -> APIObjectloc = client.locations.retrieve(16808)print(loc.name, loc.street, loc.city)locations.list_by_ids
通过一次调用,按 ID 列表(数字或 base64 编码形式)获取多个地点。
client.locations.list_by_ids(location_ids: list[str | int]) -> list[APIObject]locs = client.locations.list_by_ids([16808, 16809, "TG9jYXRpb246MTQwMjQ="])for loc in locs: print(loc.id, loc.name)locations.list_by_store_codes
获取与指定门店代码匹配的地点。
client.locations.list_by_store_codes(store_codes: list[str]) -> list[APIObject]locs = client.locations.list_by_store_codes(["SF-001", "NYC-042"])for loc in locs: print(loc.storeId, loc.name)locations.search
按关键词搜索名称、地址或门店 ID 匹配的地点。返回 SyncPage。
client.locations.search( query: str, *, fields: list[str] | None = None, first: int | None = None, after: str | None = None, before: str | None = None, last: int | None = None,) -> SyncPage# Search all fieldspage = client.locations.search("downtown dental", first=10) # Restrict to name onlypage = client.locations.search("Acme Dental", fields=["name"], first=10) for loc in page: print(loc.name, loc.city)locations.create
使用字段名为 camelCase 的原始输入 dict 创建地点。建议优先使用locations.add,以便使用关键字参数和客户端验证;如果您已有 camelCase 载荷,则使用 create。
client.locations.create(input: dict) -> APIObjectAPI 要求提供以下字段:name、description(至少 200 个字符)、subCategoryId、countryIso 和 city(适用于地址包含城市层级的国家)。
result = client.locations.create({ "name": "Acme Dental Brooklyn", "description": ( "Acme Dental Brooklyn is a family-owned dental practice offering " "general, cosmetic, and pediatric dentistry. Our team provides " "cleanings, fillings, crowns, whitening, and same-day emergency " "care in a modern, comfortable office with weekend hours and easy " "online booking for new and returning patients across Brooklyn." ), "subCategoryId": 1432, "countryIso": "US", "city": "Brooklyn", "street": "88 Court St", "stateIso": "NY", "postalCode": "11201", "phone": "6443859314", "storeId": "NYC-002",})print("Created:", result.location.id)locations.update
更新地点。传入 id 以及需要更改的字段(camelCase)。id 可以是数字或 base64 编码形式;SDK 会自动对其进行编码。
client.locations.update(input: dict) -> APIObjectresult = client.locations.update({ "id": 16808, "phone": "6443859399", "street": "125 Jump Street",})print("Updated:", result.location.id)locations.archive
归档 1 个或多个地点。
client.locations.archive(location_ids: list[str | int]) -> APIObjectresult = client.locations.archive([16808, 16809])print(result.to_dict())locations.cancel_archive
取消已安排的归档操作。
client.locations.cancel_archive( location_ids: list[str | int], selection_type: str, changed_by: str,) -> APIObjectclient.locations.cancel_archive( [16808], selection_type="manual", changed_by="admin@example.com",)