Windmill Client SDK

1.688.0 · active · verified Tue Apr 21

The Windmill Client is the official JavaScript/TypeScript SDK for interacting with the Windmill API, designed for both browser and Node.js environments. It simplifies API calls, variable management, and task execution within the Windmill ecosystem. Currently at version 1.688.0, the package follows a rapid release cycle, suggesting frequent updates and feature additions. Its primary purpose is to provide a robust, type-safe interface for integrating Windmill functionalities into applications, abstracting away direct HTTP requests and handling authentication and data serialization. It's a key tool for developers building applications that leverage Windmill for backend tasks, workflows, or serverless functions by providing a consistent client experience across different JavaScript runtimes.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to initialize the Windmill client, authenticate using an API token, and retrieve a variable from the Windmill API, handling potential errors and suggesting secure token management.

import { Windmill } from 'windmill-client';

async function runExample() {
  // Initialize the client. For Node.js, ensure WINDMILL_API_TOKEN is set in environment variables.
  // For browsers, an API token might be provided client-side or retrieved securely.
  // Replace 'https://app.windmill.dev/api/' with your Windmill instance URL if self-hosting.
  const client = new Windmill({
    apiUrl: process.env.WINDMILL_API_URL || 'https://app.windmill.dev/api/',
    // In a real application, retrieve the token securely (e.g., from environment variables,
    // a secure store, or a browser cookie/local storage with appropriate security measures).
    // This example assumes it's available as an environment variable for Node.js.
    apiToken: process.env.WINDMILL_API_TOKEN ?? '' // Ensure token is provided securely
  });

  try {
    // Retrieve a variable from Windmill
    // Replace 'u/foo/my_variable' with the actual path to your variable
    const myVariable = await client.getVariable('u/foo/my_variable');
    console.log('Retrieved variable:', myVariable);

    // Example: Run a script
    // await client.runScript('u/bar/my_script', { payload: { data: 'test_data' } });
    // console.log('Script executed successfully.');

  } catch (error) {
    console.error('Error interacting with Windmill:', error);
    if (error instanceof Error) {
        console.error('Error message:', error.message);
    }
  }
}

runExample();

view raw JSON →