{"openapi":"3.1.0","info":{"title":"OptiMonk popup builder API","version":"1.0.0","description":"Headless access to the popup builder. Every endpoint accepts either a static API key (omk_live_…) issued in Settings, or an OAuth access token (omk_at_…) from the Connect flow.\n\nPublishing is deliberately absent. Taking a campaign live is reachable only from a browser session today; an OAuth grant will be able to once the om-backend service-token exchange lands.\n\nBuilds are asynchronous: start one, then subscribe to its event stream rather than polling. Send an Idempotency-Key on the start so a retry cannot pay for a second generation."},"servers":[{"url":"https://agentic.optimonk.com"}],"security":[{"bearerAuth":[]}],"tags":[{"name":"identity","description":"Which account a credential acts as"},{"name":"builds","description":"Generating and editing popups"},{"name":"campaigns","description":"Campaign drafts and settings"},{"name":"uploads","description":"Reference images"}],"paths":{"/app/api/me":{"get":{"tags":["identity"],"operationId":"getIdentity","summary":"Which account this credential acts as, and what it may do","description":"Call this first when something returns 404 or a scope error: both read the same whether the credential is aimed at the wrong account or the object really is missing.","responses":{"200":{"description":"The caller's identity.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Identity"}}}},"401":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}},"429":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}}}}},"/app/api/v3/runs":{"get":{"tags":["builds"],"operationId":"listBuilds","deprecated":true,"summary":"Always returns an empty list","description":"A stub. It has never listed anything and is documented only so its emptiness is not mistaken for an account with no builds. Read a build by id instead.","responses":{"200":{"description":"Always `{ items: [] }`.","content":{"application/json":{"schema":{"type":"object","required":["items"],"properties":{"items":{"type":"array","maxItems":0,"items":{}}}}}}}}}},"/app/api/v3/runs/{runId}":{"get":{"tags":["builds"],"operationId":"getBuild","summary":"Read a build and its generated HTML","parameters":[{"name":"runId","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"The run.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/BuildRun"}}}},"401":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}},"403":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}},"404":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}},"429":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}},"500":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}}}}},"/app/api/v3/runs/{runId}/events":{"get":{"tags":["builds"],"operationId":"streamBuildEvents","summary":"Server-sent events for a build's progress","description":"text/event-stream, not JSON. Each frame is a snapshot or a terminal done. Prefer this over polling. Heartbeats every 20 seconds; the stream closes after 30 minutes.","parameters":[{"name":"runId","in":"path","required":true,"schema":{"type":"string"}},{"name":"detail","in":"query","required":false,"schema":{"type":"string","enum":["full"]},"description":"`full` opts into complete snapshots. Otherwise html, layout, trace and layers are omitted from snapshots and replaced by hasHtml. The terminal done frame is always complete either way."}],"responses":{"200":{"description":"Event stream.","content":{"text/event-stream":{"schema":{"type":"string"}}}},"401":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}},"403":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}},"404":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}},"429":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}},"500":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}}}}},"/app/api/v3/runs/{runId}/edit":{"post":{"tags":["builds"],"operationId":"editBuild","summary":"Ask for a change to a finished popup","parameters":[{"name":"runId","in":"path","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/EditBuildRequest"}}}},"responses":{"202":{"description":"Edit queued. Read the returned run.","content":{"application/json":{"schema":{"type":"object","required":["id","viewport"],"properties":{"id":{"type":"string"},"viewport":{"type":"string","enum":["desktop","mobile"]}}}}}},"400":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}},"401":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}},"403":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}},"404":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}},"409":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}},"429":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}},"500":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}},"503":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}}}}},"/app/api/campaigns":{"get":{"tags":["campaigns"],"operationId":"listCampaigns","summary":"List this account's campaigns","parameters":[{"name":"domain","in":"query","required":false,"schema":{"type":"string"},"description":"Restrict to one store hostname."}],"responses":{"200":{"description":"Up to 50 campaigns. `legacy` summarises the account's classic-admin campaigns — the bridge signal behind the \"your existing campaigns live in the classic admin\" affordances. Both counts are 0 on a machine credential, which has no classic-admin session to summarise, and on an account that has no classic campaigns.","content":{"application/json":{"schema":{"type":"object","required":["items","legacy"],"properties":{"items":{"type":"array","items":{"$ref":"#/components/schemas/Campaign"}},"legacy":{"type":"object","required":["count","active"],"properties":{"count":{"type":"integer","description":"Classic-admin campaigns on the account, archived ones excluded — counted over the whole set, so it is unaffected by the cap on the campaign rows themselves."},"active":{"type":"integer","description":"How many of those OM reports as running right now."}}}}}}}},"400":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}},"401":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}},"403":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}},"429":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}},"500":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}}}}},"/app/api/campaigns/{campaignId}":{"get":{"tags":["campaigns"],"operationId":"getCampaign","summary":"Read one campaign","parameters":[{"name":"campaignId","in":"path","required":true,"description":"A uuid, or the numeric OptiMonk campaign id.","schema":{"type":"string"}}],"responses":{"200":{"description":"The campaign, with its settings summary and variants.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Campaign"}}}},"401":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}},"403":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}},"404":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}},"429":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}},"500":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}}}},"delete":{"tags":["campaigns"],"operationId":"deleteCampaign","summary":"Not available to a machine credential","description":"Always 403 `forbidden_for_api_key`. Deleting a campaign is browser-only, like publishing and billing. Documented so the refusal reads as the rule it is rather than as a bug.","parameters":[{"name":"campaignId","in":"path","required":true,"description":"A uuid, or the numeric OptiMonk campaign id.","schema":{"type":"string"}}],"responses":{"403":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}}}}},"/app/api/campaigns/by-run/{runId}":{"get":{"tags":["campaigns"],"operationId":"getCampaignByRun","summary":"The campaign for a build, or the draft settings it would use","parameters":[{"name":"runId","in":"path","required":true,"schema":{"type":"string"}},{"name":"force","in":"query","required":false,"schema":{"type":"string","enum":["1"]},"description":"Recompute the suggested settings instead of reusing the cache."}],"responses":{"200":{"description":"Either an existing campaign, or `campaign: null` with the draft settings a create would apply.","content":{"application/json":{"schema":{"type":"object","properties":{"campaign":{"oneOf":[{"$ref":"#/components/schemas/Campaign"},{"type":"null"}]},"settings":{"type":"object","additionalProperties":true},"summary":{"type":"object","additionalProperties":true}}}}}},"401":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}},"403":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}},"404":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}},"429":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}},"500":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}}}}},"/app/api/campaigns/by-run/{runId}/create":{"post":{"tags":["campaigns"],"operationId":"createCampaignFromBuild","summary":"Create a draft campaign from a finished build","description":"Creates a draft and does not push it live: going live needs a browser session today. Takes no request body.","parameters":[{"name":"runId","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"201":{"description":"The created draft campaign and its settings summary.","content":{"application/json":{"schema":{"type":"object","required":["campaign","summary"],"properties":{"campaign":{"$ref":"#/components/schemas/Campaign"},"summary":{"type":"object","additionalProperties":true}}}}}},"401":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}},"403":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}},"409":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}},"429":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}},"500":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}}}}},"/app/api/uploads/reference-image":{"post":{"tags":["uploads"],"operationId":"uploadReferenceImage","summary":"Upload a reference image to build from","description":"multipart/form-data. Use the returned publicUrl as referenceUrl when starting a build. Max 20 MB; png, jpeg or webp.","requestBody":{"required":true,"content":{"multipart/form-data":{"schema":{"type":"object","required":["file"],"properties":{"file":{"type":"string","format":"binary"}}}}}},"responses":{"200":{"description":"Stored.","content":{"application/json":{"schema":{"type":"object","required":["storageKey","publicUrl"],"properties":{"storageKey":{"type":"string"},"publicUrl":{"type":"string","format":"uri"}}}}}},"400":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}},"401":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}},"403":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}},"429":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}},"500":{"description":"Typed error. Machine callers always get this shape.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineError"}}}}}}}},"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","description":"A static API key (omk_live_…) from Settings, or an OAuth access token (omk_at_…) from Connect. Scopes are enforced on both: build:read, build:write, campaign:read, campaign:write."}},"schemas":{"MachineError":{"type":"object","required":["error"],"properties":{"error":{"type":"object","required":["type","code","message"],"properties":{"type":{"type":"string","enum":["auth_error","permission_error","invalid_request_error","not_found_error","rate_limit_error","api_error"],"description":"Branch on this, not on the message."},"code":{"type":"string","description":"Stable machine label, e.g. insufficient_scope, rate_limited, invalid_domain."},"message":{"type":"string","description":"Human sentence, and free to change. On a 5xx it is deliberately generic — quote request_id instead."},"request_id":{"type":"string","description":"Also returned as the X-Request-Id header. Quote it in a report."}},"additionalProperties":true}}},"Identity":{"type":"object","required":["accountId","loginId","via","credential","scopes","canPublish","canWriteLive"],"properties":{"accountId":{"type":"integer"},"loginId":{"type":["string","null"]},"via":{"type":"string","enum":["cookie","apiKey","oauth"]},"credential":{"type":"string","description":"The key's name, or the connected app's name. Never a secret."},"scopes":{"type":"array","items":{"type":"string"}},"canPublish":{"type":"boolean","description":"Always false for a static key, whatever scopes it holds: going live is a property of how you authenticated, not of the scope list."},"canWriteLive":{"type":"boolean","description":"Whether a change to a campaign that is live in OptiMonk reaches it. False for a key or connected app: the change is saved, the live campaign keeps running the previous version until it is republished in the OptiMonk web app."}}},"StartBuildRequest":{"type":"object","required":["referenceUrl","domain"],"properties":{"referenceUrl":{"type":"string","description":"An absolute http(s) URL to a png, jpeg or webp, or an /app/ path from uploadReferenceImage. Private, loopback and link-local addresses are refused."},"domain":{"type":"string","description":"Target store hostname."},"referenceWidth":{"type":"integer","minimum":1},"referenceHeight":{"type":"integer","minimum":1}}},"EditBuildRequest":{"type":"object","required":["message"],"properties":{"message":{"type":"string","minLength":1,"maxLength":2000,"description":"What to change, in plain language."},"viewport":{"type":"string","enum":["desktop","mobile"],"default":"desktop"},"imageUrls":{"type":"array","items":{"type":"string"},"minItems":1,"maxItems":8,"description":"Reference images for the change. The same URL rules apply."},"abBaseRunId":{"type":"string","maxLength":128}}},"BuildRun":{"type":"object","description":"A build and what is known about it. Only the fields a client acts on are listed; the payload carries more.","required":["id","shortId","status","desktop","mobile","error","campaignId","campaignStatus","createdAt","endedAt"],"properties":{"id":{"type":"string"},"shortId":{"type":"string"},"status":{"type":"string","enum":["queued","running","completed","interrupted","error","stopped"],"description":"`interrupted` is NOT terminal — the run resumes, so keep watching. `stopped` is terminal: the user stopped the build, and it is not resumable."},"desktop":{"oneOf":[{"$ref":"#/components/schemas/Viewport"},{"type":"null"}]},"mobile":{"oneOf":[{"$ref":"#/components/schemas/Viewport"},{"type":"null"}]},"error":{"type":["string","null"]},"campaignId":{"type":["string","null"]},"campaignStatus":{"type":["string","null"]},"createdAt":{"type":"string","format":"date-time"},"endedAt":{"type":["string","null"],"format":"date-time"}},"additionalProperties":true},"Viewport":{"type":"object","properties":{"html":{"type":["string","null"]},"hasHtml":{"type":"boolean","description":"Present instead of html on slim event snapshots."}},"additionalProperties":true},"Campaign":{"type":"object","required":["id","name","status"],"properties":{"id":{"type":"string"},"name":{"type":"string"},"status":{"type":"string","enum":["draft","published"]},"archived":{"type":"boolean"},"domain":{"type":["string","null"]},"previewUrl":{"type":["string","null"]},"v3RunId":{"type":["string","null"]},"omCampaignId":{"type":["string","null"]},"omStatus":{"type":["string","null"]},"createdAt":{"type":"string","format":"date-time"},"updatedAt":{"type":"string","format":"date-time"}},"additionalProperties":true}}}}