Execute Action

Trigger action execution programmatically within mindzieStudio.

Overview

The Execute Action endpoint allows you to trigger a specific action within mindzieStudio. Actions are queued for asynchronous execution and you receive an execution ID to track progress.

Execute Action

GET /api/{tenantId}/{projectId}/action/execute/{actionId}

Execute a specific action by its ID. The action is added to an execution queue and processed asynchronously.

Request

GET https://your-mindzie-instance.com/api/{tenantId}/{projectId}/action/execute/{actionId}
Authorization: Bearer {your-access-token}

Path Parameters

Parameter Type Required Description
tenantId GUID Yes Your tenant identifier
projectId GUID Yes Your project identifier
actionId GUID Yes The action to execute

Response

Success (200 OK):

{
  "actionId": "87654321-4321-4321-4321-210987654321",
  "actionExecutionId": "11111111-2222-3333-4444-555555555555",
  "dateStarted": "2024-01-15T10:30:00Z",
  "dateEnded": null,
  "status": "Queued",
  "notes": null
}

Response Fields

Field Type Description
actionId GUID The ID of the action being executed
actionExecutionId GUID Unique identifier for this execution instance
dateStarted datetime When the execution was queued
dateEnded datetime When execution completed (null if still running)
status string Current execution status
notes string Additional execution notes or error messages

Error Responses

Action Not Found (404):

{
  "error": "Action not found",
  "actionId": "87654321-4321-4321-4321-210987654321"
}

Execution Creation Failed (404):

{
  "error": "Action can't create execution",
  "actionId": "87654321-4321-4321-4321-210987654321"
}

Unauthorized (401):

HTTP/1.1 401 Unauthorized

{error message describing authorization failure}

Execution Status Values

Status Description
Queued Action is queued and waiting to be processed
Running Action is currently executing
Completed Action completed successfully
Failed Action execution failed

Implementation Examples

cURL

curl -X GET "https://your-mindzie-instance.com/api/12345678-1234-1234-1234-123456789012/87654321-4321-4321-4321-210987654321/action/execute/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN"

JavaScript/Node.js

const TENANT_ID = '12345678-1234-1234-1234-123456789012';
const PROJECT_ID = '87654321-4321-4321-4321-210987654321';
const BASE_URL = 'https://your-mindzie-instance.com';

const executeAction = async (actionId, token) => {
  const url = `${BASE_URL}/api/${TENANT_ID}/${PROJECT_ID}/action/execute/${actionId}`;

  try {
    const response = await fetch(url, {
      method: 'GET',
      headers: {
        'Authorization': `Bearer ${token}`
      }
    });

    if (response.ok) {
      const result = await response.json();
      console.log('Action queued:', result);
      console.log('Execution ID:', result.actionExecutionId);
      return result;
    } else if (response.status === 404) {
      const error = await response.json();
      console.error('Action not found:', error);
      throw new Error(error.error);
    } else {
      throw new Error(`Execution failed: ${response.status}`);
    }
  } catch (error) {
    console.error('Error executing action:', error);
    throw error;
  }
};

// Example usage
executeAction('aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee', 'your_token')
  .then(result => {
    // Store actionExecutionId for tracking
    const executionId = result.actionExecutionId;
  });

Python

import requests

TENANT_ID = '12345678-1234-1234-1234-123456789012'
PROJECT_ID = '87654321-4321-4321-4321-210987654321'
BASE_URL = 'https://your-mindzie-instance.com'

def execute_action(action_id, token):
    """Execute an action and return execution details."""
    url = f'{BASE_URL}/api/{TENANT_ID}/{PROJECT_ID}/action/execute/{action_id}'
    headers = {
        'Authorization': f'Bearer {token}'
    }

    response = requests.get(url, headers=headers)

    if response.ok:
        result = response.json()
        print(f'Action queued: {result}')
        print(f'Execution ID: {result["actionExecutionId"]}')
        return result
    elif response.status_code == 404:
        error = response.json()
        print(f'Action not found: {error}')
        raise Exception(error['error'])
    else:
        raise Exception(f'Execution failed: {response.status_code}')

# Example usage
result = execute_action('aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee', 'your_token')
execution_id = result['actionExecutionId']

C#

using System;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;

public class ActionExecutionResult
{
    public Guid ActionId { get; set; }
    public Guid ActionExecutionId { get; set; }
    public DateTime? DateStarted { get; set; }
    public DateTime? DateEnded { get; set; }
    public string Status { get; set; }
    public string Notes { get; set; }
}

public class ActionApiClient
{
    private readonly HttpClient _httpClient;
    private readonly string _baseUrl;
    private readonly Guid _tenantId;
    private readonly Guid _projectId;

    public ActionApiClient(string baseUrl, Guid tenantId, Guid projectId, string accessToken)
    {
        _baseUrl = baseUrl;
        _tenantId = tenantId;
        _projectId = projectId;
        _httpClient = new HttpClient();
        _httpClient.DefaultRequestHeaders.Authorization =
            new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", accessToken);
    }

    public async Task<ActionExecutionResult> ExecuteActionAsync(Guid actionId)
    {
        var url = $"{_baseUrl}/api/{_tenantId}/{_projectId}/action/execute/{actionId}";
        var response = await _httpClient.GetAsync(url);

        if (response.IsSuccessStatusCode)
        {
            var json = await response.Content.ReadAsStringAsync();
            var result = JsonSerializer.Deserialize<ActionExecutionResult>(json,
                new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
            Console.WriteLine($"Action queued. Execution ID: {result.ActionExecutionId}");
            return result;
        }
        else if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
        {
            throw new Exception($"Action {actionId} not found");
        }
        else
        {
            throw new Exception($"Execution failed: {response.StatusCode}");
        }
    }
}

Best Practices

  • Store Execution ID: Always store the actionExecutionId returned to track execution progress
  • Check Action Exists: Use the Get Action endpoint first to verify the action exists and is enabled
  • Handle Async Nature: Actions execute asynchronously - the response indicates the action was queued, not completed
  • Error Handling: Implement proper error handling for 404 responses (action not found) and 401 (unauthorized)
  • Idempotency: Each call creates a new execution - avoid duplicate calls if not intended