API reference · Analytics

Request background analytics refresh

POST /v1/analytics/refresh

Queue a workspace analytics refresh and return immediately. Requests are deduplicated while a job is active, with a five-minute start cooldown. Recent eligible content is checked first through bounded continuations on a separate queue. Stored reports remain available. The same operation is available through get_analytics with refresh=true in MCP.

Request

Authenticate with a bearer API key. Agents calling over MCP authorise with OAuth instead and never handle the key.

curl -X POST https://api.postlake.dev/v1/analytics/refresh \
  -H "Authorization: Bearer $POSTLAKE_API_KEY"

Response

Queued, already active, or within the start cooldown (202).

FieldTypeRequiredWhat it is
jobIdstringNo
statestring (queued, running, complete, failed)No
startedAtstringNo
updatedAtstringNo
postsintegerNo
errorsintegerNo
cursorstring or nullNo

Example

{
  "jobId": "…",
  "state": "queued",
  "startedAt": "2026-08-16T07:00:00Z",
  "updatedAt": "2026-08-16T07:00:00Z",
  "posts": 0,
  "errors": 0,
  "cursor": "…"
}

Limits

Write operations are limited per account, and rate-limit responses include Retry-After. Do not automatically retry a write unless this operation explicitly documents idempotency.

Calling this from an agent

Agents do not call REST. They call tools. Over the hosted MCP server this operation is get_analytics, and the agent authorises with OAuth so your API key is never pasted into a chat or seen by the model. The reply comes back in the same normalised shape you see above, which is what lets an agent reason about it without a per-network branch.

You control what any one agent may do with it: which brands it may act for, which networks it may reach, how much it may do in a day, and whether it may spend credits you bought up front. See the MCP server.

Errors

Every failure uses one shape: a stable type, a granular code, the field at fault in param, and a plain-language fix. An agent can act on it without a person reading the message. See Errors and retries.

Check the result before retrying a write. Only operations that explicitly support idempotency can safely replay an Idempotency-Key.

Common questions

Can an AI agent do this without the REST API?

Yes. Over MCP the same job is the get_analytics tool. The agent authorises with OAuth, so no API key is pasted into a chat or seen by the model, and the answer comes back in the same normalised shape.

Is it safe to retry this call?

Do not automatically repeat a write after a timeout unless that endpoint explicitly documents idempotency. First read the resulting state; a second request could repeat the action.

What happens when it fails?

You get one error shape: a stable type, a granular code you can branch on, the offending field in param, and a fix written so an agent can correct itself rather than stop. Full list on Errors and retries.

Related