Lokasi
Tampilkan daftar, buat, perbarui, arsipkan, cari, dan ambil data lokasi melalui client.locations.
Semua metode lokasi tersedia di client.locations. Instal SDK dan konfigurasikan kunci Anda sebelum menggunakan metode ini; lihat Instalasi dan Panduan awal.
ID lokasi
Metode yang menerima location_id dapat menggunakan ID numerik (16808) atau bentuk ekuivalennya yang dikodekan dalam base64 ("TG9jYXRpb246MTY4MDg="). SDK mengodekan ID numerik secara otomatis, sehingga kedua bentuk tersebut dapat digunakan secara bergantian:
# These are equivalentclient.locations.retrieve(16808)client.locations.retrieve("TG9jYXRpb246MTY4MDg=")locations.add
Buat lokasi dalam satu pemanggilan dengan menyertakan setiap field wajib sebagai argumen kata kunci. Ini adalah cara yang direkomendasikan untuk membuat lokasi. SDK memvalidasi persyaratan pembuatan lokasi dari API di sisi klien dan memunculkan ValidationError sebelum melakukan pemanggilan jaringan apa pun, sehingga payload yang tidak valid langsung gagal dengan pesan yang jelas.
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,) -> APIObjectValidasi di sisi klien memeriksa: name sepanjang 2-150 karakter, description minimal 200 karakter, sub_category_id dan country_iso disertakan, serta city disertakan kecuali hide_address=True.
Nilai yang dikembalikan adalah payload pembuatan: .location berisi lokasi baru. Anda tidak perlu memeriksa flag keberhasilan; SDK memunculkan ValidationError ketika API menolak payload.
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
Ambil daftar lokasi dengan paginasi berbasis kursor. Mengembalikan 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
Ambil satu lokasi berdasarkan ID. Memunculkan NotFoundError jika ID tidak ada.
client.locations.retrieve(location_id: str | int) -> APIObjectloc = client.locations.retrieve(16808)print(loc.name, loc.street, loc.city)locations.list_by_ids
Ambil beberapa lokasi berdasarkan daftar ID (numerik atau base64) dalam satu pemanggilan.
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
Ambil lokasi yang cocok dengan kode toko yang diberikan.
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
Cari lokasi berdasarkan kata kunci pada nama, alamat, atau ID toko. Mengembalikan 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
Buat lokasi dari dict input mentah dengan nama field camelCase. Utamakan locations.add untuk menggunakan argumen kata kunci dan validasi di sisi klien; gunakan create jika Anda sudah memiliki payload camelCase.
client.locations.create(input: dict) -> APIObjectDiwajibkan oleh API: name, description (minimal 200 karakter), subCategoryId, countryIso, dan city (untuk negara yang menggunakan kota dalam sistem pengalamatannya).
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
Perbarui lokasi. Sertakan id beserta field yang ingin diubah (camelCase). id dapat berupa numerik atau base64; SDK mengodekannya secara otomatis.
client.locations.update(input: dict) -> APIObjectresult = client.locations.update({ "id": 16808, "phone": "6443859399", "street": "125 Jump Street",})print("Updated:", result.location.id)locations.archive
Arsipkan satu atau beberapa lokasi.
client.locations.archive(location_ids: list[str | int]) -> APIObjectresult = client.locations.archive([16808, 16809])print(result.to_dict())locations.cancel_archive
Batalkan pengarsipan terjadwal.
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",)Lihat juga
- Postingan: publikasikan pengumuman, acara, dan penawaran
- Profil bisnis: periksa status sinkronisasi per lokasi
- Ulasan: ambil daftar ulasan dan tanggapi ulasan
- Analitik: analitik profil Google, Bing, Facebook