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 3 missing tables to the Mercury source (#119007)

Tom Owers8adc4cdd8141
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 6156933bcdee..6d9cd4c21729 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
@@ -7762,7 +7762,7 @@ Note: Enumerated the official Python SDK resource directory and read resource me
## Mercury — gaps
-Today (15): `AccountStatements`, `Accounts`, `Cards`, `Categories`, `CreditAccounts`, `Customers`, `Events`, `Invoices`, `Merchants`, `Recipients`, `Transactions`, `TreasuryAccounts`, `TreasuryStatements`, `TreasuryTransactions`, `Users`
+Today (18): `AccountStatements`, `Accounts`, `Cards`, `Categories`, `CreditAccounts`, `Customers`, `Events`, `Invoices`, `Merchants`, `RecipientInvites`, `Recipients`, `SafeRequests`, `SendMoneyApprovalRequests`, `Transactions`, `TreasuryAccounts`, `TreasuryStatements`, `TreasuryTransactions`, `Users`
Diffed against: <https://docs.mercury.com/reference/getaccounts>
@@ -7770,9 +7770,9 @@ Diffed against: <https://docs.mercury.com/reference/getaccounts>
- [x] `account statements (GET /api/v1/account/{accountId}/statements)` — period-level opening/closing balances for reconciliation against Accounts (high). Added as `AccountStatements` (fan-out over `Accounts`). The API returns only the ending balance per period.
- [x] `treasury transactions (GET /api/v1/treasury/{treasuryId}/transactions)` — we sync TreasuryAccounts but none of their activity, so treasury yield/flows are unqueryable (high). Added as `TreasuryTransactions` (fan-out over `TreasuryAccounts`).
- [x] `treasury statements (GET /api/v1/treasury/{treasuryId}/statements)` — period balances for treasury accounts (medium). Added as `TreasuryStatements` (fan-out over `TreasuryAccounts`). Rows are statement documents (monthly statements, trade confirmations, tax forms) with no balance fields.
-- [ ] `send money approval requests (GET /api/v1/request-send-money)` — approval state/transition history for outbound payments (medium)
-- [ ] `recipient invites (GET /api/v1/recipient-invites)` — pending recipient onboarding state alongside synced Recipients (low)
-- [ ] `SAFE requests (GET /api/v1/safes)` — fundraising SAFE request records (low)
+- [x] `send money approval requests (GET /api/v1/request-send-money)` — approval state/transition history for outbound payments (medium). Added as `SendMoneyApprovalRequests`. Each row carries its `reviews` history; the endpoint documents no `order` param, so none is sent.
+- [x] `recipient invites (GET /api/v1/recipient-invites)` — pending recipient onboarding state alongside synced Recipients (low). Added as `RecipientInvites`. The real path is `GET /api/v1/recipients/invites`.
+- [x] `SAFE requests (GET /api/v1/safes)` — fundraising SAFE request records (low). Added as `SafeRequests`. The endpoint returns a bare array with no pagination.
Note: Endpoint inventory read from the ReadMe nav slug list embedded in the reference page, then each candidate path confirmed by fetching its individual reference page.
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mercury/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mercury/canonical_descriptions.py
index 0c72559964eb..e2105bb5a9a8 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mercury/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mercury/canonical_descriptions.py
@@ -143,6 +143,23 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"name": "Name of the merchant.",
},
},
+ "RecipientInvites": {
+ "description": "An invite that asks a recipient to submit their payment details through a Mercury onboarding link.",
+ "docs_url": "https://docs.mercury.com/reference/listrecipientinvites",
+ "columns": {
+ "id": "Unique identifier for the invite, also embedded in the onboarding URL.",
+ "recipientId": "The existing recipient this invite is for, if any.",
+ "name": "Recipient name the invite was created for.",
+ "contactEmail": "Recipient contact email the invite was created for.",
+ "status": "Status of the invite: created, completed, expired, or declined.",
+ "onboardingUrl": "URL where the recipient submits their payment details.",
+ "paymentMethods": "Payment methods the recipient may submit details for.",
+ "requireTaxDocument": "Whether the recipient must upload a tax document.",
+ "notes": "Notes shown to the recipient, if any.",
+ "createdAt": "When the invite was created.",
+ "expiresAt": "When the invite expires, if it has an expiry.",
+ },
+ },
"Recipients": {
"description": "A payment recipient saved in your Mercury organization, with routing and payment method details.",
"docs_url": "https://docs.mercury.com/reference/getrecipients",
@@ -161,6 +178,48 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"internationalWireRoutingInfo": "International wire routing details for the recipient.",
},
},
+ "SafeRequests": {
+ "description": "A SAFE (Simple Agreement for Future Equity) request that your organization sent to an investor.",
+ "docs_url": "https://docs.mercury.com/reference/getsaferequests",
+ "columns": {
+ "id": "Unique identifier for the SAFE request.",
+ "investmentAmount": "Amount the investor invests, in dollars.",
+ "investmentDate": "Date of the investment.",
+ "valuationType": "Valuation type of the SAFE: PreMoney, PostMoney, or NoValuation.",
+ "valuationCap": "Valuation cap of the SAFE, in dollars, if any.",
+ "discountRate": "Discount rate of the SAFE, if any.",
+ "includesMostFavoredNationClause": "Whether the SAFE includes a most favored nation clause.",
+ "includesProRataRightsLetter": "Whether the SAFE includes a pro rata rights letter.",
+ "governingState": "US state whose law governs the SAFE, if any.",
+ "investor": "Details about the investor that buys the equity.",
+ "organization": "Details about the organization that sells the equity.",
+ "documentUrl": "URL of the SAFE document.",
+ "expiresAt": "When the SAFE request expires.",
+ "signedByInvestorAt": "When the investor signed the SAFE, if signed.",
+ "signedByOwnerAt": "When the organization signed the SAFE, if signed.",
+ "paidAt": "When the investment was paid, if paid.",
+ "canceledAt": "When the SAFE request was canceled, if canceled.",
+ },
+ },
+ "SendMoneyApprovalRequests": {
+ "description": "A request to send money that needs approval under your organization's approval policies, with its review history.",
+ "docs_url": "https://docs.mercury.com/reference/listsendmoneyapprovalrequests",
+ "columns": {
+ "requestId": "Unique identifier for the send money approval request.",
+ "accountId": "The Mercury account the payment is sent from.",
+ "recipientId": "The recipient of the payment.",
+ "amount": "Amount of the payment, in dollars.",
+ "paymentMethod": "Payment method of the payment, such as ach or domesticWire.",
+ "status": "Status of the request: pendingApproval, approved, rejected, or cancelled.",
+ "memo": "Memo attached to the payment, if any.",
+ "requestedByUserId": "The user who created the payment request.",
+ "numberOfApproversRequired": "Total number of approvals required for the payment to be sent.",
+ "requesterMayApprove": "Whether the approval requirement names the requester as its approver.",
+ "reviews": "Approval decisions recorded against the request, ordered from oldest to most recent.",
+ "scheduledSendDate": "Date on which the payment is scheduled to be sent once fully approved.",
+ "createdAt": "When the payment request was created.",
+ },
+ },
"Transactions": {
"description": "A money movement on any account in your Mercury organization, across all payment rails.",
"docs_url": "https://docs.mercury.com/reference/listtransactions",
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mercury/mercury.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mercury/mercury.py
index 85b6ef18aed6..47b4e629b4a8 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mercury/mercury.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mercury/mercury.py
@@ -81,9 +81,10 @@ def get_resource(name: str, should_use_incremental_field: bool) -> EndpointResou
params: dict[str, Any] = {}
if config.paginated:
params["limit"] = config.page_size
- # Explicit ascending order so cursor pages arrive oldest-first and the incremental
- # watermark only ever advances.
- params["order"] = "asc"
+ if config.sends_order:
+ # Explicit ascending order so cursor pages arrive oldest-first and the incremental
+ # watermark only ever advances.
+ params["order"] = "asc"
if should_use_incremental_field and config.incremental_param is not None:
params[config.incremental_param] = {
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mercury/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mercury/settings.py
index d17e0aebc3f4..a012a4a4ae96 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mercury/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mercury/settings.py
@@ -35,6 +35,8 @@ class MercuryEndpointConfig:
# Body path of the next-page cursor and the query param it is sent back in.
cursor_path: str = "page.nextPage"
cursor_param: str = "start_after"
+ # Some list endpoints document no `order` param, so it is only sent where the API accepts it.
+ sends_order: bool = True
page_size: int = DEFAULT_PAGE_SIZE
# Per-account child endpoints, fanned out over a parent account listing.
fanout: DependentEndpointConfig | None = None
@@ -111,11 +113,35 @@ MERCURY_ENDPOINTS: dict[str, MercuryEndpointConfig] = {
path="/merchants",
data_selector="data",
),
+ "RecipientInvites": MercuryEndpointConfig(
+ name="RecipientInvites",
+ path="/recipients/invites",
+ data_selector="invites",
+ partition_key="createdAt",
+ timestamp_columns=("createdAt", "expiresAt"),
+ ),
"Recipients": MercuryEndpointConfig(
name="Recipients",
path="/recipients",
data_selector="recipients",
),
+ "SafeRequests": MercuryEndpointConfig(
+ name="SafeRequests",
+ path="/safes",
+ # The response body is a bare array with no pagination.
+ data_selector="$",
+ paginated=False,
+ timestamp_columns=("expiresAt", "canceledAt", "paidAt", "signedByInvestorAt", "signedByOwnerAt"),
+ ),
+ "SendMoneyApprovalRequests": MercuryEndpointConfig(
+ name="SendMoneyApprovalRequests",
+ path="/request-send-money",
+ data_selector="requests",
+ primary_keys=("requestId",),
+ partition_key="createdAt",
+ timestamp_columns=("createdAt",),
+ sends_order=False,
+ ),
"Transactions": MercuryEndpointConfig(
name="Transactions",
path="/transactions",
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mercury/tests/test_mercury.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mercury/tests/test_mercury.py
index 049fe2f2776d..f9d2a6ae7b42 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mercury/tests/test_mercury.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mercury/tests/test_mercury.py
@@ -99,6 +99,70 @@ class TestMercurySourceResumeBehavior:
assert result.requests[0].param("order") == "asc"
+class TestMercuryTopLevelEndpoints:
+ @pytest.mark.parametrize(
+ ("endpoint", "bodies", "expected_path", "expected_order", "expected_cursors", "expected_rows"),
+ [
+ (
+ "SendMoneyApprovalRequests",
+ [
+ {"requests": [{"requestId": "r1"}], "page": {"nextPage": "r1"}},
+ {"requests": [{"requestId": "r2"}], "page": {}},
+ ],
+ "/request-send-money",
+ None,
+ [None, "r1"],
+ [{"requestId": "r1"}, {"requestId": "r2"}],
+ ),
+ (
+ "RecipientInvites",
+ [
+ {"invites": [{"id": "inv-1"}], "page": {"nextPage": "inv-1"}},
+ {"invites": [{"id": "inv-2"}], "page": {"nextPage": None}},
+ ],
+ "/recipients/invites",
+ "asc",
+ [None, "inv-1"],
+ [{"id": "inv-1"}, {"id": "inv-2"}],
+ ),
+ (
+ "SafeRequests",
+ [[{"id": "safe-1"}, {"id": "safe-2"}]],
+ "/safes",
+ None,
+ [None],
+ [{"id": "safe-1"}, {"id": "safe-2"}],
+ ),
+ (
+ "SafeRequests",
+ [[]],
+ "/safes",
+ None,
+ [None],
+ [],
+ ),
+ ],
+ )
+ def test_walks_pages_to_the_terminal_page(
+ self,
+ endpoint: str,
+ bodies: list[Any],
+ expected_path: str,
+ expected_order: str | None,
+ expected_cursors: list[str | None],
+ expected_rows: list[dict[str, Any]],
+ ) -> None:
+ result = SourceDriver(MercurySource(), MercurySourceConfig(api_key="test-token")).run(
+ endpoint, [ScriptedResponse(json=body) for body in bodies]
+ )
+
+ assert result.raised is None
+ assert [request.path.split("/api/v1", 1)[-1] for request in result.requests] == [expected_path] * len(bodies)
+ assert [request.param("order") for request in result.requests] == [expected_order] * len(bodies)
+ assert result.params("start_after") == expected_cursors
+ assert result.rows == expected_rows
+
+
class TestMercuryFanoutEndpoints:
@pytest.mark.parametrize(
(