Use the MindStudio API

Learn how to activate API functionality for your app.

Overview

With the MindStudio API you can enable the programmatically invocation of workflows. This feature opens up several use cases, particularly in conjunction with logic blocks and launch variables. It allows for the integration of AI workflows as a step in larger automation processes.

Access and Enable the API

  1. Select the Root folder of your AI.

  2. Under the Access section, select API Access.

  3. Select the Enable button.

  4. Note the following to make API requests:

    • App ID: Unique App value.

    • API Key: Unique secret key. Do not share this with others.

Make Requests

Use the API to:

Run a Workflow

Use the following code snippet to invoke a specific Workflow in your app, optionally passing Variables that the Workflow can use.

Ensure to replace your-app-id and your-api-key with the APP ID and API Key values you obtained earlier.

Example API Request to Run a Workflow

import fetch from 'node-fetch';

const APP_ID = "your-app-id";
const API_KEY = "your-api-key";

const response = await fetch("https://api.youai.ai/developer/v1/apps/run", {
    method: 'POST',
    body: JSON.stringify({
        appId: APP_ID,
        // Optional. Invoke the app with specific variables that can
        // be accessed as, e.g., {{$launchVariables->demoVariable}}
        variables: {
          demoVariable: 'demoValue',
        },
        // Optional. If not included, default entry workflow will be invoked.
        workflow: 'Main.flow'
    }),
    headers: {
        "Content-Type": "application/json",
        authorization: `Bearer ${API_KEY}`,
    }
});
const data = await response.json();

console.log(data.threadId);
console.log(data.thread);

Example API Request to Run a Workflow Asynchronously

import fetch from 'node-fetch';

const APP_ID = "67acb41a-72d6-401f-83d4-39bf75aa3240";
const API_KEY = "skdf90ca6daeff20fac873f350424942b3b3bd20a3ae5b32876839d7131f57ac44ac80864d2e79acead292ebe86ba4d5050d5253182645c7be0c08e654dfc3ee0a";

const response = await fetch("https://api.youai.ai/developer/v1/apps/run", {
    method: 'POST',
    body: JSON.stringify({
        appId: APP_ID,
        // Proide a callback URL. When the execution is finished,
        // the API will make a POST request to the callback URL with
        // the thread available in the body of the request.
        callbackUrl: 'https://example.com/hooks/callback/XXXXXXXXX',
        // Optional. Invoke the app with specific variables that can
        // be accessed as, e.g., {{$launchVariables->demoVariable}}
        variables: {
          demoVariable: 'demoValue',
        },
        // Optional. If not included, default entry workflow will be invoked.
        workflow: 'Main.flow'
    }),
    headers: {
        "Content-Type": "application/json",
        authorization: `Bearer ${API_KEY}`,
    }
});

Load an Existing Thread

The code snippet below is a request that fetches the details of an existing thread.

Ensure to replace your-app-id and your-api-key with the APP ID and API Key values you obtained earlier.

Example API Request to Load an Existing Thread

import fetch from 'node-fetch';

const APP_ID = "your-app-id";
const API_KEY = "your-api-key";
const THREAD_ID = "replace with the ID of a thread you have created";

const response = await fetch("https://api.youai.ai/developer/v1/apps/load-thread", {
    method: 'POST',
    body: JSON.stringify({
      appId: APP_ID,
      threadId: THREAD_ID,
    }),
    headers: {
        "Content-Type": "application/json",
        authorization: `Bearer ${API_KEY}`,
    }
});
const data = await response.json();

console.log(data.thread);

Specify Onboarding Variables in an API Request

Pre-fill Onboarding Variables and invoke Workflows with specific data. These Variables can be used to connect to automation tools like Zapier, providing a wide range of use cases.

Specify the Onboarding Variables and their values after Line 12 in the example API request to run a Workflow.

Last updated