Repository navigation
feat(api): public metrics API v1 under /api/v1 with docs - #422
Merged
Merged
Conversation
Expose the existing API-key-authenticated metric endpoints under a versioned, canonical /api/v1 path (thin re-exports of the /api/mcp REST handlers), add the two missing read surfaces (citations, ai-traffic), and document the whole surface as a Metrics API reference page in the docs site. Lets agencies pull visibility/SoV/citations/traffic data into Looker Studio, Sheets or custom dashboards next to GA4 data. No schema changes: the api_keys table, Settings -> API Keys UI and ans_ bearer auth already exist.
6 of 9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a versioned, documented Public Metrics API so agencies can pull AI visibility metrics into Looker Studio, Google Sheets, Power BI or custom dashboards next to their GA4 / Search Console data.
The heavy lifting already existed — the
api_keystable, the Settings → API Keys UI,ans_bearer auth (mcp-auth.ts) and the org-ownership-checked data layer (lib/mcp/data.ts) all shipped with the MCP server. What was missing was a canonical public path and docs:/api/v1/*surface — 9 read-only endpoints. Seven are thin re-exports of the existing/api/mcp/*REST handlers (whoami,brands,visibility-summary,visibility-trend,competitor-comparison,prompt-performance,shopping-cards), keeping one source of truth; both paths serve identical responses.GET /api/v1/citations(withsource_filter=all|owned|competitor|external) andGET /api/v1/ai-traffic(platform / top-page / country breakdown). Their data functions existed for MCP tools but had no REST surface.api-reference/metrics.mdxpage (auth, conventions, endpoint reference, Looker Studio notes), added tomint.jsonnavigation, plus an API-keys section inapi-reference/authentication.mdx.No schema changes and no new auth code.
Follow-ups (out of scope)
Related Issue
N/A — built directly on request (agency user story: blend Ansvisor metrics with GA4/Search Console in one dashboard).
Type of Change
How to Test
ans_...token.curl http://localhost:3000/api/v1/whoami -H "Authorization: Bearer ans_..."→ returns your user/org ids; a bogus key returns 401.curl "http://localhost:3000/api/v1/brands" -H "Authorization: Bearer ans_..."→ lists your org's brands; grab an id.visibility-trend,citationsandai-trafficwithbrand_id+ a date range → JSON matches what the dashboard shows for the same window./api/mcp/visibility-trendand/api/v1/visibility-trendreturn identical payloads.cd docs && npx mint dev→ "Metrics API" appears under API Reference.Checklist
npx tsc --noEmitpassesnpm testpasses (45/45)