拠点
client.locationsを使用して、拠点の一覧取得、作成、更新、アーカイブ、検索、取得を行います。
拠点に関するすべてのメソッドは client.locations にあります。これらを使用する前に、SDK をインストールしてキーを設定してください。インストールとクイックスタートを参照してください。
拠点 ID
location_id を受け取るメソッドには、数値 ID(16808)またはそれを base64 でエンコードした値("TG9jYXRpb246MTY4MDg=")を指定できます。SDK は数値 ID を自動的にエンコードするため、どちらの形式も同じように使用できます。
# These are equivalentclient.locations.retrieve(16808)client.locations.retrieve("TG9jYXRpb246MTY4MDg=")locations.add
すべての必須フィールドをキーワード引数として指定し、1 回の呼び出しで拠点を作成します。拠点の作成には、この方法を推奨します。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 を指定して 1 つの拠点を取得します。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)のリストを指定し、1 回の呼び出しで複数の拠点を取得します。
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",)