Code Examples

Code Examples

Complete integration snippets for common use cases. All examples use the flw_test_… sandbox key — replace with your live key for production.

Trigger a Workflow

The most common integration: send data to Flow80 and trigger a workflow execution. Returns 202 Accepted with a run_id you can use to track progress.

json
1// Response: HTTP 202 Accepted2{3  "run_id":   "run_yyyyyyyyyyyyyyyy",4  "flow_id":  "wf_xxxxxxxxxxxxxxxx",5  "status":   "queued",6  "queued_at": "2026-04-08T10:00:00Z"7}

Full example — trigger a workflow

PHP
1<?php2// Trigger a Flow80 workflow via API3$api_key = getenv('FLOW80_API_KEY'); // flw_live_...4 5$payload = json_encode([6    'flow_id' => 'wf_xxxxxxxxxxxxxxxx',7    'trigger' => 'api',8    'payload' => [9        'order_id'      => 'ORD-' . time(),10        'customer_email' => '[email protected]',11        'items'         => [['sku' => 'WIDGET-A', 'qty' => 2]],12    ],13]);14 15$ch = curl_init("https://app.flow80.com/api/v1/flows/execute");16curl_setopt_array($ch, [17    CURLOPT_HTTPHEADER     => [18        'Authorization: Bearer ' . $api_key,19        'Content-Type: application/json',20    ],21    CURLOPT_POST           => true,22    CURLOPT_POSTFIELDS     => $payload,23    CURLOPT_RETURNTRANSFER => true,24    CURLOPT_TIMEOUT        => 30,25]);26$response = curl_exec($ch);27$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);28curl_close($ch);29 30$result = json_decode($response, true);31if ($http_code === 202) {32    echo "Workflow triggered! Run ID: " . $result['run_id'];33} else {34    echo "Error ($http_code): " . ($result['error'] ?? $response);35}

Poll Run Status

After triggering a workflow, poll GET /flows/runs/:id until the run reaches a terminal state. For production, consider using webhooks instead — they're far more efficient than polling.

Poll run status until terminal state

PHP
1<?php2// Poll a workflow run until completion (max 30 attempts, 2s interval)3$run_id  = $result['run_id'] ?? null;4$attempt = 0;5$max_attempts = 30;6 7while ($attempt < $max_attempts) {8    $ch = curl_init("https://app.flow80.com/api/v1/flows/runs/{$run_id}");9    curl_setopt_array($ch, [10        CURLOPT_HTTPHEADER     => ['Authorization: Bearer ' . $api_key],11        CURLOPT_RETURNTRANSFER => true,12    ]);13    $res  = curl_exec($ch);14    $data = json_decode($res, true);15    curl_close($ch);16 17    $status = $data['status'] ?? 'unknown';18    echo "Status: $status\n";19 20    if (in_array($status, ['completed', 'failed', 'cancelled'])) {21        echo "Final status: $status\n";22        break;23    }24 25    sleep(2);26    $attempt++;27}

More Examples

Additional examples are available in each guide: