Skip to main content
All CollectionsConnectors
Connect Scade to Google sheet
Connect Scade to Google sheet
Updated over a week ago

Overview

This guide explains how to run your Scade flow for each row in column A of a Google Sheet, where the data (e.g., URLs) is stored. While this involves some coding, you can simply copy and paste the necessary scripts.

💡 Understanding API requests is essential, as this method relies on sending API calls to Scade. There is currently no native integration for Google Sheets, so API request handling is required.


Step 1 - Create your server API key

  1. Go to the API keys page.

  2. Create a new server key.


Step 2 - Copy your flow HTTP request

  1. Open your flow in Scade.

  2. Click Publish.

  3. Open Extended settings and navigate to API.

  4. Copy the API request URL for your flow.


Step 3 - Create your Google Sheet

  1. Open Google Sheets.

  2. Create a sample sheet and add URLs or other data to column A.


Step 4 - Open Apps Script

  1. Click on Extensions → Apps Script.

  2. A new script editor window will open.


Step 5 - Rename your script and paste the provided code

  1. Copy the script provided below.

    function runAPIsForEachCell() {
    const token = 'XXXXXXXXXXXXX'; // Your actual token
    const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
    const dataRange = sheet.getRange('A2:A'); // Assuming you want to start from row 2.
    const data = dataRange.getValues();

    data.forEach((row, index) => {
    const videoUrl = row[0]; // The value from column A (video_url).

    if (videoUrl) {
    // Run the POST request
    const postResponse = postScadeFlow(videoUrl, token);
    const taskId = postResponse.id; // Extract task_id from POST response

    // Check the status of the task periodically
    const getResponse = waitForTaskCompletion(taskId, token);

    // Extract the text_review from the response
    const textReview = extractTextReview(getResponse);

    // Store the text_review in column B
    sheet.getRange(index + 2, 2).setValue(textReview);
    }
    });
    }

    function postScadeFlow(videoUrl, token) {
    const url = 'https://app.scade.pro/api/v1/scade/flow/40199/execute';
    const payload = {
    "start_node_id": "axi1-start",
    "end_node_id": "AQ6K-end",
    "result_node_id": "AQ6K-end",
    "node_settings": {
    "axi1-start": {
    "data": {
    "video_url": videoUrl
    }
    }
    }
    };

    const options = {
    method: 'post',
    contentType: 'application/json',
    headers: {
    'Authorization': `Basic ${token}`,
    'Content-Type': 'application/json'
    },
    payload: JSON.stringify(payload)
    };

    const response = UrlFetchApp.fetch(url, options);
    return JSON.parse(response.getContentText()); // Returning the POST response
    }

    function waitForTaskCompletion(taskId, token) {
    const url = `https://api.scade.pro/api/v1/task/${taskId}`;
    const options = {
    method: 'get',
    headers: {
    'Authorization': `Basic ${token}`,
    'Content-Type': 'application/json'
    }
    };

    let isCompleted = false;
    let response;

    // Check task status every 5 seconds for up to 2 minutes (adjust as necessary)
    for (let i = 0; i < 100; i++) { // 24 attempts, 5 seconds each = 2 minutes max
    Utilities.sleep(5000); // Wait for 5 seconds before checking the status again
    response = UrlFetchApp.fetch(url, options);
    const taskStatus = JSON.parse(response.getContentText());

    // Check if the task has been completed
    if (taskStatus.status === 'completed' || taskStatus.state === 'done' || taskStatus.result) {
    isCompleted = true;
    break;
    }
    }

    return JSON.parse(response.getContentText()); // Return the final GET response when completed
    }

    function extractTextReview(response) {
    // Navigate the response to find the text_review
    try {
    const textReview = response.result.success.text_review;
    // Clean up any unwanted characters if needed
    return textReview.replace(/\\n/g, ' ').trim();
    } catch (e) {
    return 'No text_review found';
    }
    }

  2. Paste it into the Apps Script editor.


Step 6 - Paste your server token

  1. Locate the server token in Scade.

  2. Paste it into the script where required.


Step 7 - Save and run

  1. Click Save in the Apps Script editor.

  2. Run the script to initiate API calls.


Step 8 - Allow the script to interact with your spreadsheet

  1. Google will request permission to access your spreadsheet.

  2. Approve the request to allow the script to function properly.

  3. If concerned about security, you can analyze the script using GPT or another tool to verify its safety before running it.


Step 9 - Monitor execution and API requests

  1. When running heavy bulk flows, be patient—each request may take up to 300 seconds.

  2. Check if API requests were successfully sent by opening Run History in your workflow analytics.

By following these steps, you can automate bulk API calls from Google Sheets to Scade, enabling efficient data processing workflows.

Did this answer your question?