--- title: "Recipes: Run a workflow via API (Polling)" slug: "recipes" updated: 2026-02-11T22:14:46Z published: 2026-02-11T22:15:21Z canonical: "support.fullcast.com/recipes" stale: true --- > ## Documentation Index > Fetch the complete documentation index at: https://support.fullcast.com/llms.txt > Use this file to discover all available pages before exploring further. # Recipes: Run a workflow via API (Polling) This guide walks you through the complete workflow of triggering a copy.ai workflow run via the API and polling for the result. ## **Step 1: Initiate run** Trigger the workflow run ```javascript let api_key = "[API key goes here]";        let workflow_id = "[workflow uuid goes here]";        let workflow_url = 'https://api.copy.ai/api/workflow/'+ workflow_id + '/run';        let input_data = {        "startVariables": {        "":""        },        "metadata": {        "":""        }        };        const options = {        method: 'POST',        headers: {"Content-Type": 'application/json', 'x-copy-ai-api-key': api_key },        body:JSON.stringify(input_data)        };        let run = await fetch(workflow_url, options)        .then(response => response.json())        .then(response => console.log(response))        .catch(err => console.error(err)); ``` ## **Step 2: Poll for result** Once you initiate a run, you can poll for the response with the given run id. ```javascript let run_id = run.data.id;        let run_url = 'https://api.copy.ai/api/workflow/'+ workflow_id + '/run/' + run_id;        const poll_options = {        method: 'GET',        headers: {"Content-Type": 'application/json', 'x-copy-ai-api-key': api_key },        };        let result = await fetch(workflow_url, options)        .then(response => response.json())        .then(response => console.log(response))        .catch(err => console.error(err)); ``` ### **Full Code** ```javascript let api_key = "[API key goes here]";        let workflow_id = "[workflow uuid goes here]";        let workflow_url = 'https://api.copy.ai/api/workflow/'+ workflow_id + '/run';        let input_data = {        "startVariables": {        "":""        },        "metadata": {        "":""        }        };        const options = {        method: 'POST',        headers: {"Content-Type": 'application/json', 'x-copy-ai-api-key': api_key },        body:JSON.stringify(input_data)        };        let run = await fetch(workflow_url, options)        .then(response => response.json())        .then(response => console.log(response))        .catch(err => console.error(err));        let run_id = run.data.id;        let run_url = 'https://api.copy.ai/api/workflow/'+ workflow_id + '/run/' + run_id;        const poll_options = {        method: 'GET',        headers: {"Content-Type": 'application/json', 'x-copy-ai-api-key': api_key },        };        let result = await fetch(workflow_url, options)        .then(response => response.json())        .then(response => console.log(response))        .catch(err => console.error(err)); ``` ### Expected response ```json //Response from initial trigger        {        "status": "success",        "data": {        "id": ""        }        }        //Response from polling        {        "status": "success",        "data":        {        "id": "",        "input":        {        ...        },        "status": "PROCESSING",        "output":        {        ...        },        "createdAt": "2022-11-18T20:30:07.434Z"        }        } ```