Architecture
Machine API versus browser session API
Which endpoints are public contracts, which are dashboard-only, and how the Next.js BFF forwards the session cookie.
Start with your marketing task
After sign-in, Home offers Analyze, Discover, Campaigns, Tracking, and Saved work. Paste a public profile, post link, hashtag, or topic. DataPI previews the target and asks you to resolve ambiguous platform or input types. Collection begins only after you select Analyze. You do not create or paste an API token in the dashboard. API tokens are for external integrations.
Tasks, evidence, and external API equivalents
| Task | What you provide and receive | Machine API |
|---|---|---|
| Analyze | A public target → editable preview → explicit collection → dated evidence, supported metrics, and coverage warnings. Live sources vary by platform and target type. | POST /v1/experience/preview; POST /v1/experience/runs; GET /v1/experience/runs/{run_id} |
| Campaigns | A name, dates, timezone, up to 20 targets, and include/exclude phrases → a saved workspace and distinct sampled posts with per-target coverage. Results do not imply reach, sales, or ROI. | POST /v1/experience/campaigns; POST /v1/experience/campaigns/{campaign_id}/runs |
| Tracking | A live analysis or campaign and frequency → scheduled observations. Samples cannot be tracked. Workspace permissions are checked again when work executes. | POST /v1/experience/schedules; GET /v1/experience/schedules |
Read coverage before making a decision
Surface ownership
| Surface | Host and base | Audience | Credential |
|---|---|---|---|
| Machine API | api.datapi.ir/v1 | Server-side integrations and public contracts | Workspace bearer token |
| Browser workspace API | app.datapi.ir/api/v1 | The signed-in dashboard only | HttpOnly session cookie |
| Next.js BFF | app.datapi.ir/api/machine | Dashboard API explorer only | Bearer token supplied per request, never persisted |
Why the split exists
The browser session cookie is scoped to app.datapi.ir and is never accepted by the machine host. The machine API uses workspace bearer tokens only. This prevents a stolen browser cookie from becoming a server credential and keeps browser mutations subject to same-origin/Origin checks. The dashboard BFF is a proxy, not an additional public API: it forwards only the cookie and allowlisted headers over the private network.