Actie Uitvoeren

Start programmatisch de uitvoering van een actie binnen mindzieStudio.

Overzicht

De Execute Action endpoint stelt je in staat om een specifieke actie binnen mindzieStudio te starten. Acties worden in de wachtrij geplaatst voor asynchrone uitvoering en je ontvangt een uitvoering-ID om de voortgang te volgen.

Actie Uitvoeren

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

Voer een specifieke actie uit op basis van het ID. De actie wordt toegevoegd aan een uitvoering wachtrij en asynchroon verwerkt.

Request

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

Path Parameters

Parameter Type Vereist Beschrijving
tenantId GUID Ja Jouw tenant identificatie
projectId GUID Ja Jouw project identificatie
actionId GUID Ja De uit te voeren actie

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 Velden

Veld Type Beschrijving
actionId GUID Het ID van de uitgevoerde actie
actionExecutionId GUID Unieke identificatie voor deze uitvoering instantie
dateStarted datetime Wanneer de uitvoering in de wachtrij werd geplaatst
dateEnded datetime Wanneer de uitvoering voltooid is (null als nog bezig)
status string Huidige uitvoeringsstatus
notes string Extra uitvoeringsnotities of foutmeldingen

Fout Antwoorden

Actie Niet Gevonden (404):

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

Uitvoering Maken Mislukt (404):

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

Niet Geautoriseerd (401):

HTTP/1.1 401 Unauthorized

{error message describing authorization failure}

Uitvoeringsstatus Waarden

Status Beschrijving
Queued Actie staat in de wachtrij en wacht op verwerking
Running Actie wordt momenteel uitgevoerd
Completed Actie succesvol voltooid
Failed Uitvoering van de actie is mislukt

Implementatie Voorbeelden

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('Actie in wachtrij geplaatst:', result);
      console.log('Uitvoerings-ID:', result.actionExecutionId);
      return result;
    } else if (response.status === 404) {
      const error = await response.json();
      console.error('Actie niet gevonden:', error);
      throw new Error(error.error);
    } else {
      throw new Error(`Uitvoering mislukt: ${response.status}`);
    }
  } catch (error) {
    console.error('Fout bij uitvoeren van actie:', error);
    throw error;
  }
};

// Voorbeeld gebruik
executeAction('aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee', 'your_token')
  .then(result => {
    // Sla actionExecutionId op voor 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):
    """Voer een actie uit en retourneer uitvoeringsgegevens."""
    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'Actie in wachtrij geplaatst: {result}')
        print(f'Uitvoerings-ID: {result["actionExecutionId"]}')
        return result
    elif response.status_code == 404:
        error = response.json()
        print(f'Actie niet gevonden: {error}')
        raise Exception(error['error'])
    else:
        raise Exception(f'Uitvoering mislukt: {response.status_code}')

# Voorbeeld gebruik
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($"Actie in wachtrij geplaatst. Uitvoerings-ID: {result.ActionExecutionId}");
            return result;
        }
        else if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
        {
            throw new Exception($"Actie {actionId} niet gevonden");
        }
        else
        {
            throw new Exception($"Uitvoering mislukt: {response.StatusCode}");
        }
    }
}

Beste Praktijken

  • Bewaar Uitvoerings-ID: Sla altijd de actionExecutionId op om de voortgang van de uitvoering te volgen
  • Controleer Of Actie Bestaat: Gebruik eerst de Get Action endpoint om te verifiĆ«ren of de actie bestaat en ingeschakeld is
  • Houd Rekening Met Asynchrone Uitvoering: Acties worden asynchroon uitgevoerd - het antwoord geeft aan dat de actie in de wachtrij staat, niet dat deze voltooid is
  • Foutafhandeling: Implementeer correcte foutafhandeling voor 404 responses (actie niet gevonden) en 401 (niet geautoriseerd)
  • Idempotentie: Elke aanroep creĆ«ert een nieuwe uitvoering - vermijd dubbele aanroepen als dat niet de bedoeling is