Block Execution
Execute Analysis Blocks
Execute individual blocks asynchronously and monitor their processing status. Blocks process data according to their type and configuration.
Execute Block
POST /api/{tenantId}/{projectId}/block/{blockId}/execute
Queues a block for asynchronous execution. The block will process data according to its type and configuration (filter, calculator, alert, etc.). Returns an execution ID for tracking progress.
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
tenantId |
GUID | Yes | The tenant identifier |
projectId |
GUID | Yes | The project identifier |
blockId |
GUID | Yes | The block identifier to execute |
Request Body (Optional)
{
"parameters": {
"dateFrom": "2024-01-01",
"dateTo": "2024-12-31",
"threshold": 1000
}
}
Response (202 Accepted)
{
"blockId": "550e8400-e29b-41d4-a716-446655440000",
"executionId": "770e8400-e29b-41d4-a716-446655440000",
"status": "Queued",
"dateQueued": "2024-01-15T10:30:00Z",
"dateStarted": null,
"dateEnded": null,
"result": null,
"errorMessage": null,
"message": "Block execution has been queued"
}
Response Fields
| Field | Type | Description |
|---|---|---|
blockId |
GUID | The block that was queued |
executionId |
GUID | Unique identifier for this execution |
status |
string | Current execution status |
dateQueued |
datetime | When the execution was queued |
dateStarted |
datetime | When execution started (null if not started) |
dateEnded |
datetime | When execution completed (null if not finished) |
result |
object | Execution result data (null until complete) |
errorMessage |
string | Error details if execution failed |
message |
string | Human-readable status message |
Error Responses
Not Found (404):
{
"Error": "Block not found",
"BlockId": "550e8400-e29b-41d4-a716-446655440000"
}
Unauthorized (401):
{error message describing authorization failure}
Execution Status Values
Block execution progresses through these status values:
| Status | Description |
|---|---|
Queued |
Block is waiting in the execution queue |
Running |
Block is currently processing data |
Success |
Block completed execution successfully |
Failed |
Block execution failed with errors |
Cancelled |
Block execution was cancelled |
Implementation Examples
cURL
# Execute block without parameters
curl -X POST "https://your-mindzie-instance.com/api/12345678-1234-1234-1234-123456789012/87654321-4321-4321-4321-210987654321/block/550e8400-e29b-41d4-a716-446655440000/execute" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json"
# Execute block with parameters
curl -X POST "https://your-mindzie-instance.com/api/12345678-1234-1234-1234-123456789012/87654321-4321-4321-4321-210987654321/block/550e8400-e29b-41d4-a716-446655440000/execute" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"parameters": {"dateFrom": "2024-01-01", "dateTo": "2024-12-31"}}'
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';
class BlockExecutor {
constructor(token) {
this.headers = {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
};
}
async executeBlock(blockId, parameters = null) {
const url = `${BASE_URL}/api/${TENANT_ID}/${PROJECT_ID}/block/${blockId}/execute`;
const body = parameters ? JSON.stringify({ parameters }) : null;
const response = await fetch(url, {
method: 'POST',
headers: this.headers,
body: body
});
if (response.status === 202) {
return await response.json();
}
throw new Error(`Execution failed: ${response.statusText}`);
}
}
// Usage
const executor = new BlockExecutor('your-auth-token');
// Execute without parameters
const result = await executor.executeBlock('block-guid');
console.log(`Execution queued: ${result.executionId}`);
// Execute with parameters
const resultWithParams = await executor.executeBlock('block-guid', {
dateFrom: '2024-01-01',
dateTo: '2024-12-31'
});
Python
import requests
TENANT_ID = '12345678-1234-1234-1234-123456789012'
PROJECT_ID = '87654321-4321-4321-4321-210987654321'
BASE_URL = 'https://your-mindzie-instance.com'
class BlockExecutor:
def __init__(self, token):
self.headers = {
'Authorization': f'Bearer {token}',
'Content-Type': 'application/json'
}
def execute_block(self, block_id, parameters=None):
"""Queue block for execution."""
url = f'{BASE_URL}/api/{TENANT_ID}/{PROJECT_ID}/block/{block_id}/execute'
payload = {'parameters': parameters} if parameters else {}
response = requests.post(url, json=payload, headers=self.headers)
if response.status_code == 202:
return response.json()
else:
raise Exception(f'Failed to execute block: {response.text}')
# Usage
executor = BlockExecutor('your-auth-token')
# Execute without parameters
result = executor.execute_block('block-guid')
print(f"Execution queued: {result['executionId']}")
# Execute with parameters
result = executor.execute_block('block-guid', {
'dateFrom': '2024-01-01',
'dateTo': '2024-12-31',
'threshold': 1000
})
print(f"Status: {result['status']}")
C#
using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
public class ExecuteBlockReturn
{
public Guid BlockId { get; set; }
public Guid ExecutionId { get; set; }
public string Status { get; set; }
public DateTime DateQueued { get; set; }
public DateTime? DateStarted { get; set; }
public DateTime? DateEnded { get; set; }
public object Result { get; set; }
public string ErrorMessage { get; set; }
public string Message { get; set; }
}
public class BlockExecutorClient
{
private readonly HttpClient _httpClient;
private readonly string _baseUrl;
private readonly Guid _tenantId;
private readonly Guid _projectId;
public BlockExecutorClient(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<ExecuteBlockReturn> ExecuteBlockAsync(Guid blockId, object parameters = null)
{
var url = $"{_baseUrl}/api/{_tenantId}/{_projectId}/block/{blockId}/execute";
var payload = parameters != null ? new { parameters } : new { };
var content = new StringContent(
JsonSerializer.Serialize(payload),
Encoding.UTF8,
"application/json");
var response = await _httpClient.PostAsync(url, content);
if (response.StatusCode == System.Net.HttpStatusCode.Accepted)
{
var json = await response.Content.ReadAsStringAsync();
return JsonSerializer.Deserialize<ExecuteBlockReturn>(json,
new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
}
throw new Exception($"Failed to execute block: {response.StatusCode}");
}
}
// Usage
var executor = new BlockExecutorClient(
"https://your-mindzie-instance.com",
Guid.Parse("12345678-1234-1234-1234-123456789012"),
Guid.Parse("87654321-4321-4321-4321-210987654321"),
"your-access-token");
// Execute block
var result = await executor.ExecuteBlockAsync(
Guid.Parse("block-guid"),
new { dateFrom = "2024-01-01", dateTo = "2024-12-31" });
Console.WriteLine($"Execution queued: {result.ExecutionId}");
Best Practices
- Check Block Status: Verify the block is not disabled before executing
- Use Parameters Wisely: Pass runtime parameters to customize execution without modifying block configuration
- Handle Async Nature: Block execution is asynchronous - use the results endpoint to check completion
- Monitor Execution: For long-running blocks, poll the results endpoint to track progress