Kestra JavaScript SDK​Kestra ​Java​Script ​S​D​K

Release: 1.0.0

Install JavaScript SDK

You can use the Kestra JavaScript SDK in Node.js and the browser.

Node.js

For Node.js, publish the library as an npm package (see Publishing npm packages). Once published, install it with:

shell
npm install @kestra-io/kestra-sdk --save

Build the module with:

shell
npm run build

Local development

To work with the library locally (without publishing to a registry), change into the directory containing package.json (referred to as JAVASCRIPT_CLIENT_DIR) and run:

shell
npm install

Then link it globally:

shell
npm link

In your application project, link the local SDK:

shell
npm link /path/to/<JAVASCRIPT_CLIENT_DIR>

Finally, build the module:

shell
npm run build

Git

If the library is hosted in a Git repository (for example, https://github.com/GIT_USER_ID/GIT_REPO_ID), install it via:

shell
npm install GIT_USER_ID/GIT_REPO_ID --save

Browser installation

The library also works in the browser via npm and browserify. After following the Node.js steps and installing browserify (npm install -g browserify), bundle your entry file (assume main.js):

shell
browserify main.js > bundle.js

Then include bundle.js in your HTML.


Getting started

After installation, initialize the SDK and call the API:

javascript
var KestraIoKestraSdk = require('@kestra-io/kestra-sdk');

var api = new KestraIoKestraSdk.AIApi()
var tenant = "tenant_example"; // {String} 
var flowGenerationPrompt = new KestraIoKestraSdk.FlowGenerationPrompt(); // {FlowGenerationPrompt} Prompt and context required for flow generation
var callback = function(error, data, response) {
  if (error) {
    console.error(error);
  } else {
    console.log('API called successfully. Returned data: ' + data);
  }
};
api.generateFlow(tenant, flowGenerationPrompt, callback);

Create flow

Create or update a flow using the createFlow method:

javascript
import KestraIoKestraSdk from '@kestra-io/kestra-sdk';
let defaultClient = KestraIoKestraSdk.ApiClient.instance;
// Configure HTTP basic authorization: basicAuth
let basicAuth = defaultClient.authentications['basicAuth'];
basicAuth.username = 'YOUR USERNAME';
basicAuth.password = 'YOUR PASSWORD';
// Configure Bearer (Bearer) access token for authorization: bearerAuth
let bearerAuth = defaultClient.authentications['bearerAuth'];
bearerAuth.accessToken = "YOUR ACCESS TOKEN"

let apiInstance = new KestraIoKestraSdk.FlowsApi();
let tenant = "tenant_example"; // String | 
let body = "body_example"; // String | The flow source code
apiInstance.createFlow(tenant, body, (error, data, response) => {
  if (error) {
    console.error(error);
  } else {
    console.log('API called successfully. Returned data: ' + data);
  }
});

Execute a flow

Execute a flow using the createExecution method:

javascript
import KestraIoKestraSdk from '@kestra-io/kestra-sdk';
let defaultClient = KestraIoKestraSdk.ApiClient.instance;
// Configure HTTP basic authorization: basicAuth
let basicAuth = defaultClient.authentications['basicAuth'];
basicAuth.username = 'YOUR USERNAME';
basicAuth.password = 'YOUR PASSWORD';
// Configure Bearer (Bearer) access token for authorization: bearerAuth
let bearerAuth = defaultClient.authentications['bearerAuth'];
bearerAuth.accessToken = "YOUR ACCESS TOKEN"

let apiInstance = new KestraIoKestraSdk.ExecutionsApi();
let namespace = "namespace_example"; // String | The flow namespace
let id = "id_example"; // String | The flow id
let wait = false; // Boolean | If the server will wait the end of the execution
let tenant = "tenant_example"; // String | 
let opts = {
  'labels': ["null"], // [String] | The labels as a list of 'key:value'
  'revision': 56, // Number | The flow revision or latest if null
  'scheduleDate': new Date("2013-10-20T19:20:30+01:00"), // Date | Schedule the flow on a specific date
  'breakpoints': "breakpoints_example", // String | Set a list of breakpoints at specific tasks 'id.value', separated by a coma.
  'kind': new KestraIoKestraSdk.ExecutionKind() // ExecutionKind | Specific execution kind
};
apiInstance.createExecution(namespace, id, wait, tenant, opts, (error, data, response) => {
  if (error) {
    console.error(error);
  } else {
    console.log('API called successfully. Returned data: ' + data);
  }
});

Was this page helpful?