execute_code
Run custom JavaScript in a stateful sandbox to query Klaviyo and Shopify analytics, preserving data between calls for multi-step workflows.
Instructions
execute_code(code: string) -> { ok, result, stdout, state, durationMs } state: current globalThis stash (auto-populated, summary-form — read this to see what data from prior calls is available without re-fetching)
Sandbox globals: klaviyo, shopify, console, pick, topN, summarize, globalThis (persists across calls)
Discovery: search_docs / read_doc surface SDK paths, parameter shapes, and recipes. The SDK uses JSON:API conventions (sort keys, sparse fieldsets) that differ from typical JS SDKs — search_docs FIRST for unfamiliar methods.
Reference example (real API surface — note JSON:API request shape): const metricId = await klaviyo.getConversionMetricId(); const report = await klaviyo.reporting.campaignValues({ data: { type: 'campaign-values-report', attributes: { timeframe: { key: 'last_30_days' }, conversion_metric_id: metricId, statistics: ['recipients', 'open_rate', 'conversion_value'], }} }); globalThis.report = report; return topN(report.data.attributes.results, 5, r => r.statistics.conversion_value);
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | JavaScript (or TypeScript-like) to execute in the stateful sandbox. Async; return a value via `return ...`. Globals: klaviyo, shopify, console, pick, topN, summarize, globalThis. No fetch/process/require/import. Add `// @timeout 2m` (max 5m) to extend the 30s wall-clock limit. |