Skip to content

: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.

feat(data-warehouse): add invoiced tax rates, tasks, credits, events tables (#111880)

Tom Owersacde7accba7f
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.md
index 9137d65ce558..f299c2af810f 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
@@ -4397,14 +4397,14 @@ Note: Full OpenAPI 3.1.1 spec at https://api.intruder.io/v1/swagger.json (linked
## Invoiced — gaps
-Today (9): `coupons`, `credit_notes`, `customers`, `estimates`, `invoices`, `items`, `payments`, `plans`, `subscriptions`
+Today (13): `coupons`, `credit_balance_adjustments`, `credit_notes`, `customers`, `estimates`, `events`, `invoices`, `items`, `payments`, `plans`, `subscriptions`, `tasks`, `tax_rates`
Diffed against: <https://developer.invoiced.com/api/coupons>
-- [ ] `GET /events` — object change/audit event stream — the only way to get invoice and subscription state transitions (high)
-- [ ] `GET /tax_rates` — lookup table resolving the tax rate IDs carried on invoices, items and line items we already sync (high)
-- [ ] `GET /credit_balance_adjustments` — customer credit balance transactions, missing from the AR picture (medium)
-- [ ] `GET /tasks` — AR collection tasks and chasing cadence per customer (medium)
+- [x] `GET /events` — object change/audit event stream — the only way to get invoice and subscription state transitions (high)
+- [x] `GET /tax_rates` — lookup table resolving the tax rate IDs carried on invoices, items and line items we already sync (high)
+- [x] `GET /credit_balance_adjustments` — customer credit balance transactions, missing from the AR picture (medium)
+- [x] `GET /tasks` — AR collection tasks and chasing cadence per customer (medium)
- [ ] `GET /customers/{id}/contacts` — contact-level lookup for the customers we sync (billing vs technical recipients) (medium)
- [ ] `GET /customers/{id}/pending_line_items` — metered billing usage accrued but not yet invoiced (medium)
- [ ] `GET /invoices/{id}/payment_plan` — installment schedule attached to an invoice; explains partial payments (medium)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/invoiced/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/invoiced/canonical_descriptions.py
index 4cbbd7390a76..555673521824 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/invoiced/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/invoiced/canonical_descriptions.py
@@ -182,4 +182,63 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"updated_at": "UNIX timestamp when last updated.",
},
},
+ "tax_rates": {
+ "description": "A tax rate that can be applied to invoices, line items, and subscriptions.",
+ "docs_url": "https://developer.invoiced.com/api/tax-rates",
+ "columns": {
+ "id": "The tax rate's unique ID.",
+ "name": "Tax rate name.",
+ "currency": "3-letter ISO currency code.",
+ "value": "Tax amount.",
+ "inclusive": "When true, pricing is calculated as tax-inclusive.",
+ "is_percent": "When true, the value is a percentage.",
+ "metadata": "Key/value pairs that store additional information about the tax rate.",
+ "created_at": "UNIX timestamp when created.",
+ "updated_at": "UNIX timestamp when last updated.",
+ },
+ },
+ "tasks": {
+ "description": "A to-do item for collection efforts on a customer, such as a phone call or letter.",
+ "docs_url": "https://developer.invoiced.com/api/tasks",
+ "columns": {
+ "id": "The task's unique ID.",
+ "name": "Task name.",
+ "action": "Action type: phone, letter, email, or review.",
+ "customer_id": "Associated customer ID.",
+ "user_id": "ID of the user assigned to the task.",
+ "due_date": "Task due date (UNIX timestamp).",
+ "complete": "Whether the task is complete.",
+ "completed_date": "Date the task was marked complete (UNIX timestamp).",
+ "completed_by_user_id": "ID of the user who completed the task.",
+ "chase_step_id": "ID of the chasing step that created the task.",
+ "created_at": "UNIX timestamp when created.",
+ "updated_at": "UNIX timestamp when last updated.",
+ },
+ },
+ "credit_balance_adjustments": {
+ "description": "An adjustment that adds account credit to a customer without a payment, such as a service outage or referral credit.",
+ "docs_url": "https://developer.invoiced.com/api/credit-balances",
+ "columns": {
+ "id": "The adjustment's unique ID.",
+ "customer": "Customer ID.",
+ "currency": "3-letter ISO currency code.",
+ "amount": "Adjustment amount.",
+ "date": "Adjustment date (UNIX timestamp).",
+ "notes": "Notes.",
+ "created_at": "UNIX timestamp when created.",
+ "updated_at": "UNIX timestamp when last updated.",
+ },
+ },
+ "events": {
+ "description": "An event recording important billing activity in the account, such as an invoice being paid or a customer being updated.",
+ "docs_url": "https://developer.invoiced.com/api/events",
+ "columns": {
+ "id": "The event's unique ID.",
+ "type": "Event type in object.action form, e.g. invoice.paid or subscription.updated.",
+ "timestamp": "UNIX timestamp when the event happened.",
+ "data": "Contains the object that was the subject of the event, plus the changed previous values for update events.",
+ "previous": "The old values that changed during the event, for update events.",
+ "user": "The user who triggered the event.",
+ },
+ },
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/invoiced/invoiced.py b/products/warehouse_sources/backend/temporal/data_imports/sources/invoiced/invoiced.py
index 234360f254b3..16f22b7c7d39 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/invoiced/invoiced.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/invoiced/invoiced.py
@@ -75,9 +75,11 @@ def invoiced_source(
config = INVOICED_ENDPOINTS[endpoint]
# An explicit ascending updated_at sort keeps page traversal deterministic and lets the
- # pipeline checkpoint the incremental watermark per batch (sort_mode="asc"). `sort` is
- # documented on every list endpoint we sync ("Column to sort by, i.e. name asc").
- params: dict[str, Any] = {"per_page": PAGE_SIZE, "sort": "updated_at asc"}
+ # pipeline checkpoint the incremental watermark per batch (sort_mode="asc"). Only endpoints
+ # that document `sort` ("Column to sort by, i.e. name asc") get one.
+ params: dict[str, Any] = {"per_page": PAGE_SIZE}
+ if config.sort:
+ params["sort"] = config.sort
endpoint_config: Endpoint = {
"path": config.path,
@@ -89,10 +91,12 @@ def invoiced_source(
"paginator": HeaderLinkPaginator(),
}
- use_incremental = should_use_incremental_field and db_incremental_field_last_value is not None
+ use_incremental = (
+ config.supports_updated_after and should_use_incremental_field and db_incremental_field_last_value is not None
+ )
if use_incremental:
- # Every list endpoint documents a server-side `updated_after` UNIX-timestamp filter; inject
- # the last synced value as that filter so the sync only pulls rows touched since.
+ # Inject the last synced value as the server-side `updated_after` UNIX-timestamp filter so
+ # the sync only pulls rows touched since.
endpoint_config["incremental"] = {
"start_param": "updated_after",
"cursor_path": "updated_at",
@@ -152,7 +156,7 @@ def invoiced_source(
primary_keys=config.primary_keys,
partition_count=1,
partition_size=1,
- # Rows are requested with an explicit `sort=updated_at asc`.
+ # Incremental endpoints request rows with an explicit `sort=updated_at asc`.
sort_mode="asc",
)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/invoiced/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/invoiced/settings.py
index 1e48e599eaed..6a11e5792ec3 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/invoiced/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/invoiced/settings.py
@@ -3,18 +3,22 @@ from dataclasses import dataclass, field
from products.warehouse_sources.backend.types import IncrementalField, IncrementalFieldType
-@dataclass
+@dataclass(frozen=True)
class InvoicedEndpointConfig:
path: str
# Invoiced object IDs are unique per resource within an account (integers for documents,
# user-assigned strings for catalog objects like items/plans/coupons), so `id` is a safe
# primary key for every top-level list endpoint.
primary_keys: list[str] = field(default_factory=lambda: ["id"])
+ # Endpoints that document the server-side `updated_after` filter can sync incrementally.
+ supports_updated_after: bool = True
+ # Sent as `sort`; None for endpoints whose docs list no `sort` parameter.
+ sort: str | None = "updated_at asc"
-# Invoiced REST API top-level list endpoints (https://developer.invoiced.com/api). Every one of
-# these documents a server-side `updated_after` UNIX-timestamp filter, so `updated_at` is a
-# genuine incremental cursor across the board.
+# Invoiced REST API top-level list endpoints (https://developer.invoiced.com/api). Endpoints that
+# document a server-side `updated_after` UNIX-timestamp filter use `updated_at` as an incremental
+# cursor; the rest are full refresh only.
INVOICED_ENDPOINTS: dict[str, InvoicedEndpointConfig] = {
"customers": InvoicedEndpointConfig(path="/customers"),
"invoices": InvoicedEndpointConfig(path="/invoices"),
@@ -25,6 +29,15 @@ INVOICED_ENDPOINTS: dict[str, InvoicedEndpointConfig] = {
"items": InvoicedEndpointConfig(path="/items"),
"plans": InvoicedEndpointConfig(path="/plans"),
"coupons": InvoicedEndpointConfig(path="/coupons"),
+ "tax_rates": InvoicedEndpointConfig(path="/tax_rates"),
+ # Documents only `sort` and `filter`.
+ "tasks": InvoicedEndpointConfig(path="/tasks", supports_updated_after=False),
+ # Documents no list query parameters.
+ "credit_balance_adjustments": InvoicedEndpointConfig(
+ path="/credit_balance_adjustments", supports_updated_after=False, sort=None
+ ),
+ # Events are immutable (no `updated_at`) and the list documents only a `related_to` filter.
+ "events": InvoicedEndpointConfig(path="/events", supports_updated_after=False, sort=None),
}
ENDPOINTS = tuple(INVOICED_ENDPOINTS.keys())
@@ -39,5 +52,6 @@ _UPDATED_AT_INCREMENTAL_FIELD: IncrementalField = {
}
INCREMENTAL_FIELDS: dict[str, list[IncrementalField]] = {
- endpoint: [_UPDATED_AT_INCREMENTAL_FIELD] for endpoint in ENDPOINTS
+ endpoint: [_UPDATED_AT_INCREMENTAL_FIELD] if config.supports_updated_after else []
+ for endpoint, config in INVOICED_ENDPOINTS.items()
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/invoiced/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/invoiced/source.py
index 7a8f39c76e17..15371254469b 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/invoiced/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/invoiced/source.py
@@ -53,7 +53,7 @@ class InvoicedSource(ResumableSource[InvoicedSourceConfig, InvoicedResumeConfig]
releaseStatus=ReleaseStatus.ALPHA,
caption="""Enter your Invoiced API key to pull your accounts receivable and billing data into the PostHog Data warehouse.
-You can create an API key under **Settings → Developers → API Keys** in [Invoiced](https://www.invoiced.com). The key grants read access to your customers, invoices, payments, credit notes, estimates, subscriptions, and billing catalog.
+You can create an API key under **Settings → Developers → API Keys** in [Invoiced](https://www.invoiced.com). The key grants read access to your customers, invoices, payments, credit notes, credit balance adjustments, estimates, subscriptions, billing catalog, tax rates, collection tasks, and events.
""",
iconPath="/static/services/invoiced.png",
docsUrl="https://posthog.com/docs/cdp/sources/invoiced",
@@ -95,8 +95,6 @@ You can create an API key under **Settings → Developers → API Keys** in [Inv
force_refresh: bool = False,
api_version: str | None = None,
) -> list[SourceSchema]:
- # Every list endpoint documents a server-side `updated_after` UNIX-timestamp filter, so
- # each schema advertises `updated_at` as a genuine incremental cursor.
return build_endpoint_schemas(ENDPOINTS, INCREMENTAL_FIELDS, names)
def validate_credentials(
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/invoiced/tests/test_invoiced.py b/products/warehouse_sources/backend/temporal/data_imports/sources/invoiced/tests/test_invoiced.py
index e2e101f7b92c..39ac8c00a638 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/invoiced/tests/test_invoiced.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/invoiced/tests/test_invoiced.py
@@ -130,6 +130,39 @@ class TestSourcePagination:
assert params["sort"] == "updated_at asc"
assert params["per_page"] == PAGE_SIZE
+ @parameterized.expand(
+ [
+ ("tasks", "updated_at asc"),
+ ("credit_balance_adjustments", None),
+ ("events", None),
+ ]
+ )
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_endpoint_without_updated_after_ignores_cursor(
+ self, endpoint: str, expected_sort: str | None, MockSession
+ ) -> None:
+ # These endpoints document no `updated_after` filter (and only some document `sort`), so a
+ # stale cursor must not leak an undocumented param into the request.
+ session = MockSession.return_value
+ snapshots = _wire(session, [_response([])])
+
+ _rows(
+ invoiced_source(
+ "api-key",
+ endpoint,
+ team_id=1,
+ job_id="j",
+ resumable_source_manager=_make_manager(),
+ should_use_incremental_field=True,
+ db_incremental_field_last_value=1700000000,
+ )
+ )
+
+ params = snapshots[0]["params"]
+ assert "updated_after" not in params
+ assert params.get("sort") == expected_sort
+ assert params["per_page"] == PAGE_SIZE
+
@mock.patch(CLIENT_SESSION_PATCH)
def test_full_refresh_omits_updated_after(self, MockSession) -> None:
session = MockSession.return_value