Skip to content

feat: move business context to the v1 Platform API - #295

Open
msiebert wants to merge 2 commits into
mainfrom
msiebert-business-context-v1-api
Open

msiebert wants to merge 2 commits into
mainfrom
msiebert-business-context-v1-api

Conversation

@msiebert

Copy link
Copy Markdown

Why

mixpanel/analytics#111709 deletes the legacy business-context App API routes (mixpanel.com/api/app/{projects|organizations}/{id}/business-context[/chain]). The replacements are the v1 Platform API endpoints, which are already on analytics master. This PR moves the library and CLI onto them so business context keeps working after the old routes are gone.

Public Python and CLI signatures are unchanged. Callers of Workspace business-context methods and mp business-context ... see no difference, apart from one new field (updated_at, below).

What changed

  • New platform API family. Platform calls go to platform-{us,eu,in}.mixpanel.com/v1/..., one host per region. platform_request sits next to app_request and both share one request helper, so auth headers, retries and rate-limit handling behave the same.
  • RFC 9457 error parsing. v1 error bodies (detail / title) are parsed into the existing exception types; the full problem object stays on the exception.
  • Get and set use the v1 business-context endpoints.
  • Clear is a DELETE on the v1 endpoint.
  • Chain is built from the project GET's nested organization_business_context field instead of a dedicated /chain route.
  • BusinessContext.updated_at is exposed from the v1 response.
  • Docs, plugin reference and CHANGELOG updated.

Environment overrides

  • MP_API_BASE_URL maps platform calls to {base}/api/app/v1.
  • MP_APP_BASE_URL also redirects platform calls, to {app_base}/api/app/v1 (the same webapp mount). This keeps users who override the app host sending business-context traffic to the same host as before.

Conformance

The conformance vectors are intentionally untouched. Per conformance/record/README.md, they get re-pinned in a follow-up conformance PR after this is released.

Test plan

  • just check: ruff check, ruff format --check, mypy (402 files, no issues), interrogate (src 100%, conformance 100%, tests 96.1%), full pytest run, and uv build.
  • pytest: 11720 passed, 1 skipped, 579 deselected. Total coverage 94.60% (gate is 90%).
  • Not run: live tests against the real v1 endpoints.

Deployment plan

  • Merge only after the v1 business-context endpoints are confirmed deployed to prod.
  • This must be merged and released before mixpanel/analytics#111709 merges. Otherwise released versions of the library lose business context.
  • After release, open the follow-up conformance re-pin PR.

🤖 Generated with Claude Code

The legacy business-context App API routes are being removed. Business
context get/set/clear and the organization chain now go through the v1
Platform API (platform-{us,eu,in}.mixpanel.com/v1). Public Python and CLI
signatures are unchanged.

- Add a platform API family with per-region hosts and platform_request,
  sharing a helper with app_request.
- Parse RFC 9457 problem+json errors.
- Clear via DELETE; build the chain from the project's nested
  organization_business_context.
- Add updated_at to BusinessContext.
- MP_API_BASE_URL maps to {base}/api/app/v1; MP_APP_BASE_URL also
  redirects platform calls to {app_base}/api/app/v1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge once the new endpoints are confirmed deployed, as required by the deployment plan.

Diagram

sequenceDiagram
    participant Caller as Python / CLI
    participant Workspace
    participant Client as MixpanelAPIClient
    participant Platform as Regional Platform API
    Caller->>Workspace: Read, write, clear, or chain
    Workspace->>Client: Business-context request
    Client->>Platform: GET / PUT / DELETE
    Platform-->>Client: JSON or 204
    Client-->>Workspace: Parsed response
    Workspace-->>Caller: BusinessContext / BusinessContextChain
Loading

Reviews (2) · Last reviewed commit: "fix: chain updated_at parse error and do..." · Reviewed by Greptile

Comment thread src/mixpanel_headless/workspace.py Resolved
@msiebert msiebert self-assigned this Nov 24, 2026
_parse_updated_at now raises from the underlying ValueError so the cause is
preserved. MP_API_BASE_URL and MP_APP_BASE_URL docs list the platform family
(/api/app/v1) alongside the others.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@msiebert
msiebert marked this pull request as ready for review November 24, 2026 19:49
Copilot AI balanced review requested due to automatic review settings November 24, 2026 19:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Maintainer confirmation is needed for production v1 endpoint availability and release ordering because the linked backend PR was inaccessible and live compatibility was not validated.

No open issues 🎉

What changed in this PR

Moves business-context operations from legacy App API routes to the v1 Platform API before the legacy routes are removed, preserving the public Workspace and CLI signatures.

Changes:

  • Adds regional Platform API routing, environment overrides, shared request handling, and RFC 9457 error parsing.
  • Changes clear to DELETE, builds context chains from one project response, and exposes BusinessContext.updated_at.
  • Updates tests and documentation; leaves conformance vectors for a follow-up re-pin.
File Description
tests/​unit/​test_workspace_business_context.py Tests v1 routes, deletion, nested contexts, timestamps, and errors.
tests/​unit/​test_api_base_url_override.py Tests Platform routing, overrides, and timeouts.
tests/​unit/​test_api_base_url_override_pbt.py Adds Platform prefixes to routing invariants.
tests/​pbt/​test_business_context_pbt.py Updates response fixtures and tests single-request deletion.
src/​mixpanel_headless/​workspace.py Migrates business-context operations and parses timestamps.
src/​mixpanel_headless/​types.py Adds updated_at and updates result documentation.
src/​mixpanel_headless/​cli/​commands/​business_context.py Updates docstrings for clear and chain behavior; no command logic changes.
src/​mixpanel_headless/​_internal/​api_client.py Adds Platform requests, shared transport handling, and v1 operations.
mixpanel-plugin/​skills/​mixpanelyst/​references/​business-context.md Documents deletion and timestamps.
docs/​guide/​business-context.md Updates usage, result fields, and error behavior.
docs/​getting-started/​configuration.md Documents Platform hosts and environment overrides.
docs/​cli/​index.md Updates API override descriptions.
docs/​api/​workspace.md Clarifies deletion in example comments.
docs/​api/​exceptions.md Updates the server-side oversize status to HTTP 422.
CLAUDE.md Adds Platform routing to environment-variable documentation.
CHANGELOG.md Records the migration and API changes under Unreleased.

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants