:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(calendly): sync invitees, form submissions, contacts and hosts (#100169)
Tom Owerscb594729a8e7
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.mdindex ecbfa4034ca7..0f6f5580993a 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md@@ -1141,10 +1141,10 @@ Today (5): `event_types`, `groups`, `organization_memberships`, `routing_forms`,Diffed against: <https://stoplight.io/api/v1/projects/cHJqOjY4NTM/table-of-contents>-- [ ] `List Event Invitees (/scheduled_events/{uuid}/invitees)` — the invitee is the person, cancellation reason, no-show flag, UTM tracking, and Q&A answers — without it scheduled_events is unusable for funnel analysis (high)-- [ ] `List Routing Form Submissions (/routing_form_submissions)` — submissions for the routing_forms we already sync, including questions/answers, tracking, and which event type they routed to (high)-- [ ] `List Contacts (/contacts)` — the person lookup table Calendly resolves invitee emails against (high)-- [ ] `List Event Type Hosts (/event_types/{uuid}/hosts)` — membership table joining the event_types we sync to their hosting users (high)+- [x] `List Event Invitees (/scheduled_events/{uuid}/invitees)` — the invitee is the person, cancellation reason, no-show flag, UTM tracking, and Q&A answers — without it scheduled_events is unusable for funnel analysis (high)+- [x] `List Routing Form Submissions (/routing_form_submissions)` — submissions for the routing_forms we already sync, including questions/answers, tracking, and which event type they routed to (high)+- [x] `List Contacts (/contacts)` — the person lookup table Calendly resolves invitee emails against (high)+- [x] `List Event Type Hosts (/event_type_memberships)` — membership table joining the event_types we sync to their hosting users (high)- [ ] `List Group Relationships (/group_relationships)` — lookup joining the groups we already sync to users and event types (medium)- [ ] `List activity log entries (/activity_log_entries)` — state/transition history for org and user changes; the audit trail for who changed what (medium)- [ ] `List Recaps and Get Transcript (Notetaker)` — meeting recaps and transcripts tied to scheduled events, for content analysis of calls (medium)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/calendly/api_inventory.md b/products/warehouse_sources/backend/temporal/data_imports/sources/calendly/api_inventory.mdindex 40c6af56e194..3c5f1fdb8e51 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/calendly/api_inventory.md+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/calendly/api_inventory.md@@ -7,19 +7,32 @@ Calendly REST API v2 — base URL `https://api.calendly.com`. Auth via a Persona- **Response shape:** list endpoints return `{"collection": [...], "pagination": {"count", "next_page", "next_page_token"}}`.- **Pagination:** cursor-based. Follow `pagination.next_page` (a fully-formed URL carrying all query params); a `null` value ends pagination.-- **Scoping:** every list endpoint below requires an `organization` URI, resolved once per sync from `GET /users/me` → `resource.current_organization`.+- **Scoping:** the top-level list endpoints require an `organization` URI, resolved once per sync from `GET /users/me` → `resource.current_organization`. `/contacts` is account-scoped and takes no such param; the fan-out children are scoped by their parent instead.- **Primary key:** every resource carries a stable `uri`.- **Partitioning:** all endpoints expose a stable `created_at`, used for datetime partitioning.## Endpoints synced-| Endpoint | Path | Incremental | Notes |-| -------------------------- | --------------------------- | ---------------------------------- | -------------------------- |-| `event_types` | `/event_types` | full refresh | no server-side time filter |-| `scheduled_events` | `/scheduled_events` | `min_start_time` (on `start_time`) | `sort=start_time:asc` |-| `groups` | `/groups` | full refresh | no server-side time filter |-| `organization_memberships` | `/organization_memberships` | full refresh | no server-side time filter |-| `routing_forms` | `/routing_forms` | full refresh | no server-side time filter |+| Endpoint | Path | Incremental | Notes |+| -------------------------- | --------------------------- | ---------------------------------- | ------------------------------------- |+| `event_types` | `/event_types` | full refresh | no server-side time filter |+| `scheduled_events` | `/scheduled_events` | `min_start_time` (on `start_time`) | `sort=start_time:asc` |+| `groups` | `/groups` | full refresh | no server-side time filter |+| `organization_memberships` | `/organization_memberships` | full refresh | no server-side time filter |+| `routing_forms` | `/routing_forms` | full refresh | no server-side time filter |+| `contacts` | `/contacts` | full refresh | account-scoped, `sort=created_at:asc` |++### Fanned out over a parent++| Endpoint | Path | Parent | Notes |+| -------------------------- | ------------------------------------- | ------------------ | ------------------------------------------------------ |+| `invitees` | `/scheduled_events/{uuid}/invitees` | `scheduled_events` | parent UUID in the path, `sort=created_at:asc` |+| `routing_form_submissions` | `/routing_form_submissions?form=` | `routing_forms` | parent URI as a query param, `sort=created_at:asc` |+| `event_type_memberships` | `/event_type_memberships?event_type=` | `event_types` | Calendly calls these event type hosts; takes no `sort` |++None of the four accepts a server-side timestamp filter, so all are full refresh and merge on `uri`.+Each object's `uri` is globally unique — an invitee URI embeds its event's UUID — so no fan-out child+needs its parent id in the primary key.## Verification status & caveats@@ -32,8 +45,16 @@ Calendly REST API v2 — base URL `https://api.calendly.com`. Auth via a Personaincremental run; the merge dedupes on `uri` for everything re-fetched. This mirrors the known limitationof the Airbyte connector. Only `scheduled_events` is marked `supports_incremental` because it is the onlyendpoint with a genuine server-side timestamp filter.+- The fanned-out endpoints and `/contacts` were taken from the Stoplight project behind+ developer.calendly.com (project `cHJqOjY4NTM`): paths, query params, required scopes and response shapes+ come from its operation definitions. `event_type_memberships` documents `created_at` but does not mark it+ required, so a row without it lands in the unknown-date partition rather than failing the sync.+- `/contacts` needs the `contacts:read` scope. A token without it gets a 403, which+ `get_non_retryable_errors` already turns into a permanent failure with a message, and only that table+ fails.## Not yet synced-- `scheduled_events/{uuid}/invitees` — valuable (who booked) but requires per-event fan-out; deferred for the- initial alpha.+- `/group_relationships`, `/activity_log_entries`, `/outgoing_communications`,+ `/user_availability_schedules`, the Notetaker recaps and transcripts, and+ `/organizations/{uuid}/invitations`.diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/calendly/calendly.py b/products/warehouse_sources/backend/temporal/data_imports/sources/calendly/calendly.pyindex 06d83e2d3c92..edf9327f6718 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/calendly/calendly.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/calendly/calendly.py@@ -1,6 +1,6 @@import secretsimport dataclasses-from collections.abc import Iterator+from collections.abc import Iterable, Iteratorfrom datetime import UTC, date, datetimefrom typing import Any, Optionalfrom urllib.parse import quote, urlencode, urlsplit@@ -14,6 +14,9 @@ from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.arrfrom products.warehouse_sources.backend.temporal.data_imports.sources.calendly.settings import (CALENDLY_ENDPOINTS,CALENDLY_WEBHOOK_EVENTS,+ PAGE_SIZE,+ PARENT_URI_PARAM_FIELD,+ PARENT_UUID_FIELD,WEBHOOK_SCHEMA_NAMES,CalendlyEndpointConfig,)@@ -27,16 +30,19 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.resRESTAPIConfig,rest_api_resource,)+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.fanout import (+ build_dependent_resource,+)from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.paginators import (JSONResponsePaginator,)+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.typing import ClientConfigfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManagerfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.source_helpers import validate_via_probefrom products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceResponsefrom products.warehouse_sources.backend.temporal.data_imports.sources.common.webhook_s3 import WebhookSourceManagerCALENDLY_BASE_URL = "https://api.calendly.com"-PAGE_SIZE = 100REQUEST_TIMEOUT = 60# Calendly webhook subscriptions are scoped to an organization or a single user. Every table this@@ -75,6 +81,11 @@ def _format_datetime(value: Any) -> str:return str(value)+def _last_uri_segment(uri: str) -> Optional[str]:+ """The trailing path segment of a Calendly URI — its UUID — or None when there is none."""+ return uri.rstrip("/").rsplit("/", 1)[-1] or None++def _get_headers(token: str) -> dict[str, str]:return {"Authorization": f"Bearer {token}",@@ -124,6 +135,69 @@ def _build_initial_params(return params+def _paginator() -> JSONResponsePaginator:+ return JSONResponsePaginator(next_url_path="pagination.next_page")+++def _client_config(token: str, base_url: str) -> ClientConfig:+ return {+ "base_url": base_url,+ "headers": {"Content-Type": "application/json"},+ "auth": {"type": "bearer", "token": token},+ "paginator": _paginator(),+ }+++def _with_parent_lookup_fields(row: dict[str, Any]) -> dict[str, Any]:+ """Derive the values a fan-out child binds into its path from the parent's `uri`.++ `process_parent_data_item` formats the path without escaping, so both variants are prepared+ here: the trailing UUID for `/scheduled_events/{uuid}/invitees`, and a percent-encoded URI for+ the children that take the parent URI as a query param. A row whose URI yields no segment+ keeps the key absent, so the fan-out fails with the framework's named-field error rather than+ requesting a malformed path.+ """+ uri = row.get("uri")+ if isinstance(uri, str):+ segment = _last_uri_segment(uri)+ if segment:+ row[PARENT_UUID_FIELD] = segment+ row[PARENT_URI_PARAM_FIELD] = quote(uri, safe="")+ return row+++def _dependent_rows(+ config: CalendlyEndpointConfig, token: str, base_url: str, team_id: int, job_id: str+) -> Iterable[Any]:+ """Fan the child endpoint out over its parent resource, one child request per parent row."""+ assert config.fanout is not None+ parent_config = CALENDLY_ENDPOINTS[config.fanout.parent_name]+ organization = get_current_organization(token, base_url) if parent_config.scope_param == "organization" else None++ return build_dependent_resource(+ endpoint_configs=CALENDLY_ENDPOINTS,+ child_endpoint=config.name,+ fanout=dataclasses.replace(+ config.fanout,+ parent_params=_build_initial_params(parent_config, organization, False, None),+ child_params={"sort": config.sort} if config.sort else {},+ ),+ client_config=_client_config(token, base_url),+ path_format_values={},+ team_id=team_id,+ job_id=job_id,+ # No child endpoint here exposes a server-side time filter, so they all full refresh.+ db_incremental_field_last_value=None,+ page_size_param="count",+ parent_data_map=_with_parent_lookup_fields,+ # Both requests are declared explicitly because a child path carrying a `{placeholder}`+ # would otherwise be taken for a single-entity endpoint and paginated as one page. The+ # paginator is stateful, so parent and child each get their own instance.+ parent_endpoint_extra={"paginator": _paginator(), "data_selector": "collection"},+ child_endpoint_extra={"paginator": _paginator(), "data_selector": "collection"},+ )++def calendly_source(token: str,endpoint: str,@@ -139,6 +213,12 @@ def calendly_source(base_url = _base_url_for_version(api_version)def get_rows() -> Iterator[Any]:+ if config.fanout is not None:+ # Dependent resources don't support resume in the rest_source framework, so the+ # manager is intentionally not threaded into this path.+ yield from _dependent_rows(config, token, base_url, team_id, job_id)+ return+resume_config = resumable_source_manager.load_state() if resumable_source_manager.can_resume() else Noneinitial_paginator_state: Optional[dict[str, Any]] = None@@ -154,12 +234,7 @@ def calendly_source()rest_config: RESTAPIConfig = {- "client": {- "base_url": base_url,- "headers": {"Content-Type": "application/json"},- "auth": {"type": "bearer", "token": token},- "paginator": JSONResponsePaginator(next_url_path="pagination.next_page"),- },+ "client": _client_config(token, base_url),"resources": [{"name": endpoint,@@ -330,8 +405,7 @@ def _subscription_uuid(subscription: dict[str, Any]) -> Optional[str]:uri = subscription.get("uri")if not isinstance(uri, str):return None- segment = uri.rstrip("/").rsplit("/", 1)[-1]- return segment or None+ return _last_uri_segment(uri)def _delete_subscriptions(session: Session, base_url: str, subscriptions: list[dict[str, Any]]) -> list[str]:diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/calendly/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/calendly/canonical_descriptions.pyindex 16eca4a50a32..74debc8c4da5 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/calendly/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/calendly/canonical_descriptions.py@@ -59,6 +59,34 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {meeting_notes_html="HTML meeting notes.",),},+ "invitees": {+ "description": "A person who booked a scheduled event, with their answers, tracking and cancellation.",+ "docs_url": "https://developer.calendly.com/api-docs/e55b39ce6b6f2-list-event-invitees",+ "columns": _columns(+ email="The invitee's email address.",+ name="The invitee's name (in human-readable format).",+ first_name="First name of the invitee, when the event type collects first and last name separately.",+ last_name="Last name of the invitee, when the event type collects first and last name separately.",+ status="Whether the invitee is active or canceled.",+ event="URI of the scheduled event the invitee booked.",+ questions_and_answers="The invitee's responses to the questions on the booking confirmation form.",+ timezone="Time zone used when displaying times to the invitee.",+ tracking="UTM and Salesforce tracking parameters captured from the booking link.",+ text_reminder_number="Phone number used for text (SMS) reminders.",+ rescheduled="Whether this invitee rescheduled; the replacement is linked in new_invitee.",+ old_invitee="URI of the invitee record that was rescheduled into this one.",+ new_invitee="URI of the invitee record created when this one was rescheduled.",+ cancel_url="Link the invitee uses to cancel the event.",+ reschedule_url="Link the invitee uses to reschedule the event.",+ routing_form_submission="URI of the routing form submission that sent the invitee to this booking page.",+ cancellation="Cancellation details, present when the booking has been canceled.",+ payment="Payment collected for the booking.",+ no_show="No-show record for the invitee, present when they were marked as a no-show.",+ reconfirmation="Reconfirmation request details, when the event type requires reconfirmation.",+ scheduling_method="How the event was scheduled.",+ invitee_scheduled_by="URI of the user who scheduled the event on the invitee's behalf.",+ ),+ },"groups": {"description": "A group within a Calendly organization used to organize members.","docs_url": "https://developer.calendly.com/api-docs/c1957c0e1e44b-list-groups",@@ -86,4 +114,46 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {questions="The questions configured on the routing form.",),},+ "routing_form_submissions": {+ "description": "A completed routing form submission and where the respondent was routed.",+ "docs_url": "https://developer.calendly.com/api-docs/6f5b9ed0f8b76-list-routing-form-submissions",+ "columns": _columns(+ routing_form="URI of the routing form that was submitted.",+ questions_and_answers="The respondent's answers to the routing form questions.",+ tracking="UTM and Salesforce tracking parameters captured with the submission.",+ result="Where the submission routed the respondent: an event type, an external URL, or a custom message.",+ submitter="URI of the invitee resource, when the submission ended in a booked meeting.",+ submitter_type="Type of respondent that submitted the form and scheduled a meeting.",+ ),+ },+ "event_type_memberships": {+ "description": "A host assigned to an event type, joining event types to the users who run them.",+ "docs_url": "https://developer.calendly.com/api-docs/d07d3d2ba5b76-list-event-type-hosts",+ "columns": _columns(+ event_type="The event type the host is assigned to.",+ member="The user hosting the event type.",+ ),+ },+ "contacts": {+ "description": "A person in the Calendly contacts directory, which invitee emails resolve against.",+ "docs_url": "https://developer.calendly.com/api-docs/b3A6NjM0Mzg0MTA-list-contacts",+ "columns": _columns(+ emails="The contact's email addresses (up to 10).",+ name="The contact's name (in human-readable format).",+ phone_numbers="The contact's phone numbers (up to 10).",+ timezone="Time zone used when presenting times to the contact.",+ job_title="The contact's job title.",+ company="The contact's company name.",+ country="Two-letter country code for the contact (ISO 3166-1 alpha-2).",+ state="The contact's state, province, or region.",+ city="The contact's city.",+ linkedin="URL of the contact's LinkedIn profile.",+ custom_fields="Values the contact has for the account's custom contact fields.",+ first_email_date="Time of the earliest email exchanged with the contact.",+ last_email_date="Time of the most recent email exchanged with the contact.",+ next_meeting_date="Time of the next upcoming meeting scheduled with the contact.",+ last_meeting_date="Time of the most recent meeting held with the contact.",+ last_interaction_date="Time of the most recent email or meeting with the contact.",+ ),+ },}diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/calendly/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/calendly/settings.pyindex 2dc13df4228b..38bee7a4772a 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/calendly/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/calendly/settings.py@@ -1,10 +1,20 @@from dataclasses import dataclass, fieldfrom typing import Optional+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.fanout import (+ DependentEndpointConfig,+)from products.warehouse_sources.backend.types import IncrementalField, IncrementalFieldType+PAGE_SIZE = 100-@dataclass+# Binding values derived from a fan-out parent's `uri` (see `_with_parent_lookup_fields`), because+# no Calendly resource carries its own UUID or an escaped copy of its URI.+PARENT_UUID_FIELD = "_uuid"+PARENT_URI_PARAM_FIELD = "_uri_param"+++@dataclass(frozen=True)class CalendlyEndpointConfig:name: strpath: str@@ -18,6 +28,11 @@ class CalendlyEndpointConfig:incremental_filter_param: Optional[str] = None# Sort value passed to keep pagination ordering stable/monotonic.sort: Optional[str] = None+ # Set when the endpoint is scoped to one parent resource and has to be fanned out over it.+ fanout: Optional[DependentEndpointConfig] = None+ # Read by the shared fan-out helper for the `count` param and the incremental cursor.+ page_size: int = PAGE_SIZE+ default_incremental_field: Optional[str] = NoneCALENDLY_ENDPOINTS: dict[str, CalendlyEndpointConfig] = {@@ -34,6 +49,7 @@ CALENDLY_ENDPOINTS: dict[str, CalendlyEndpointConfig] = {path="/scheduled_events",incremental_filter_param="min_start_time",sort="start_time:asc",+ default_incremental_field="start_time",incremental_fields=[{"label": "start_time",@@ -43,6 +59,22 @@ CALENDLY_ENDPOINTS: dict[str, CalendlyEndpointConfig] = {},],),+ # Fanned out over `scheduled_events`: the invitee is the person who booked the meeting, with+ # their answers, tracking and cancellation. The endpoint takes no organization param and no+ # server-side time filter, so every sync re-reads each event's invitees and merges on `uri`.+ "invitees": CalendlyEndpointConfig(+ name="invitees",+ path="/scheduled_events/{uuid}/invitees",+ scope_param=None,+ sort="created_at:asc",+ fanout=DependentEndpointConfig(+ parent_name="scheduled_events",+ resolve_param="uuid",+ resolve_field=PARENT_UUID_FIELD,+ # The invitee row already carries `event`, the parent's URI — nothing to copy down.+ include_from_parent=[],+ ),+ ),"groups": CalendlyEndpointConfig(name="groups",path="/groups",@@ -55,6 +87,42 @@ CALENDLY_ENDPOINTS: dict[str, CalendlyEndpointConfig] = {name="routing_forms",path="/routing_forms",),+ # Fanned out over `routing_forms`. The parent URI rides in a query param rather than the path,+ # which the fan-out helper only binds through a `{placeholder}`, hence the query in `path`.+ "routing_form_submissions": CalendlyEndpointConfig(+ name="routing_form_submissions",+ path="/routing_form_submissions?form={form}",+ scope_param=None,+ sort="created_at:asc",+ fanout=DependentEndpointConfig(+ parent_name="routing_forms",+ resolve_param="form",+ resolve_field=PARENT_URI_PARAM_FIELD,+ # The submission row already carries `routing_form`, the parent's URI.+ include_from_parent=[],+ ),+ ),+ # Calendly calls these event type hosts; the path is `/event_type_memberships`. Fanned out over+ # `event_types`, and the only list endpoint here that accepts no `sort` param.+ "event_type_memberships": CalendlyEndpointConfig(+ name="event_type_memberships",+ path="/event_type_memberships?event_type={event_type}",+ scope_param=None,+ fanout=DependentEndpointConfig(+ parent_name="event_types",+ resolve_param="event_type",+ resolve_field=PARENT_URI_PARAM_FIELD,+ # The membership row embeds the whole parent event type object.+ include_from_parent=[],+ ),+ ),+ # Account-scoped: `/contacts` takes no `organization` param, unlike every other table here.+ "contacts": CalendlyEndpointConfig(+ name="contacts",+ path="/contacts",+ scope_param=None,+ sort="created_at:asc",+ ),}ENDPOINTS = tuple(CALENDLY_ENDPOINTS.keys())diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/calendly/tests/test_calendly.py b/products/warehouse_sources/backend/temporal/data_imports/sources/calendly/tests/test_calendly.pyindex c295827ea584..9802364379eb 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/calendly/tests/test_calendly.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/calendly/tests/test_calendly.py@@ -36,6 +36,13 @@ CALENDLY_SESSION_PATCH = (ORG_URI = "https://api.calendly.com/organizations/ABC123"+# Parent row each fan-out child is bound to, keyed by the child endpoint.+PARENT_URIS = {+ "invitees": "https://api.calendly.com/scheduled_events/EV1",+ "routing_form_submissions": "https://api.calendly.com/routing_forms/RF1",+ "event_type_memberships": "https://api.calendly.com/event_types/ET1",+}+def _response(collection: Optional[list[dict[str, Any]]],@@ -318,6 +325,117 @@ class TestRequestParams:assert "min_start_time" not in snapshots[0]["params"]+class TestFanoutEndpoints:+ """The three child endpoints scoped to a parent resource, fanned out one request per parent."""++ @parameterized.expand(+ [+ (+ "invitees",+ "scheduled_events",+ f"{CALENDLY_BASE_URL}/scheduled_events/EV1/invitees",+ "created_at:asc",+ ),+ (+ "routing_form_submissions",+ "routing_forms",+ f"{CALENDLY_BASE_URL}/routing_form_submissions?form=https%3A%2F%2Fapi.calendly.com%2Frouting_forms%2FRF1",+ "created_at:asc",+ ),+ (+ "event_type_memberships",+ "event_types",+ f"{CALENDLY_BASE_URL}/event_type_memberships?event_type=https%3A%2F%2Fapi.calendly.com%2Fevent_types%2FET1",+ # The only list endpoint that accepts no sort param.+ None,+ ),+ ]+ )+ @mock.patch(CALENDLY_SESSION_PATCH)+ @mock.patch(CLIENT_SESSION_PATCH)+ def test_child_request_is_bound_to_its_parent(+ self,+ endpoint: str,+ parent: str,+ expected_child_url: str,+ expected_sort: Optional[str],+ MockClientSession: mock.MagicMock,+ mock_calendly_session: mock.MagicMock,+ ) -> None:+ mock_calendly_session.return_value.get.return_value = _users_me_response()+ snapshots = _wire(+ MockClientSession.return_value,+ [_response([{"uri": PARENT_URIS[endpoint]}]), _response([{"uri": "child-1"}])],+ )++ rows = _rows(_source(_make_manager(), endpoint=endpoint))++ # The parent walk stays org-scoped; the child carries the parent identity in its path,+ # percent-encoded where it rides in a query param.+ assert snapshots[0]["url"] == f"{CALENDLY_BASE_URL}/{parent}"+ assert snapshots[0]["params"]["organization"] == ORG_URI+ assert snapshots[1]["url"] == expected_child_url+ assert snapshots[1]["params"].get("sort") == expected_sort+ assert snapshots[1]["params"]["count"] == 100+ assert [r["uri"] for r in rows] == ["child-1"]++ @mock.patch(CALENDLY_SESSION_PATCH)+ @mock.patch(CLIENT_SESSION_PATCH)+ def test_child_pages_are_followed_per_parent(+ self, MockClientSession: mock.MagicMock, mock_calendly_session: mock.MagicMock+ ) -> None:+ mock_calendly_session.return_value.get.return_value = _users_me_response()+ next_url = f"{CALENDLY_BASE_URL}/scheduled_events/EV1/invitees?page=2"+ _wire(+ MockClientSession.return_value,+ [+ _response([{"uri": PARENT_URIS["invitees"]}]),+ _response([{"uri": "in-1"}], next_page=next_url),+ _response([{"uri": "in-2"}]),+ ],+ )++ rows = _rows(_source(_make_manager(), endpoint="invitees"))++ assert [r["uri"] for r in rows] == ["in-1", "in-2"]++ @mock.patch(CALENDLY_SESSION_PATCH)+ @mock.patch(CLIENT_SESSION_PATCH)+ def test_fanout_neither_reads_nor_writes_resume_state(+ self, MockClientSession: mock.MagicMock, mock_calendly_session: mock.MagicMock+ ) -> None:+ # Dependent resources cannot resume, so a saved next-page URL must not leak into the+ # fan-out — applying another endpoint's cursor here would request the wrong resource.+ mock_calendly_session.return_value.get.return_value = _users_me_response()+ snapshots = _wire(+ MockClientSession.return_value,+ [_response([{"uri": PARENT_URIS["invitees"]}]), _response([{"uri": "in-1"}])],+ )+ manager = _make_manager(resume_state=CalendlyResumeConfig(next_url=f"{CALENDLY_BASE_URL}/event_types?page=9"))++ _rows(_source(manager, endpoint="invitees"))++ assert snapshots[0]["url"] == f"{CALENDLY_BASE_URL}/scheduled_events"+ manager.save_state.assert_not_called()+++class TestContacts:+ @mock.patch(CALENDLY_SESSION_PATCH)+ @mock.patch(CLIENT_SESSION_PATCH)+ def test_contacts_is_account_scoped_and_sorted(+ self, MockClientSession: mock.MagicMock, mock_calendly_session: mock.MagicMock+ ) -> None:+ snapshots = _wire(MockClientSession.return_value, [_response([{"uri": "contact-1"}])])++ rows = _rows(_source(_make_manager(), endpoint="contacts"))++ # /contacts takes no organization param, so there is no /users/me bootstrap to make.+ mock_calendly_session.assert_not_called()+ assert "organization" not in snapshots[0]["params"]+ assert snapshots[0]["params"]["sort"] == "created_at:asc"+ assert [r["uri"] for r in rows] == ["contact-1"]++class TestCalendlySource:@parameterized.expand([(name,) for name in ENDPOINTS])def test_source_response_shape(self, endpoint: str) -> None: