アクションの実行
mindzieStudio内でプログラム的にアクションをトリガーして実行します。
概要
Execute Actionエンドポイントを使用すると、mindzieStudio内の特定のアクションをトリガーできます。アクションは非同期実行のためにキューに追加され、進行状況を追跡するための実行IDが返されます。
アクションの実行
GET /api/{tenantId}/{projectId}/action/execute/{actionId}
特定のアクションIDでアクションを実行します。アクションは実行キューに追加され、非同期で処理されます。
リクエスト
GET https://your-mindzie-instance.com/api/{tenantId}/{projectId}/action/execute/{actionId}
Authorization: Bearer {your-access-token}
パスパラメータ
| パラメータ | 型 | 必須 | 説明 |
|---|---|---|---|
tenantId |
GUID | はい | テナント識別子 |
projectId |
GUID | はい | プロジェクト識別子 |
actionId |
GUID | はい | 実行するアクション |
レスポンス
成功 (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
}
レスポンスフィールド
| フィールド | 型 | 説明 |
|---|---|---|
actionId |
GUID | 実行されるアクションのID |
actionExecutionId |
GUID | この実行インスタンスの一意識別子 |
dateStarted |
datetime | 実行がキューに追加された日時 |
dateEnded |
datetime | 実行が完了した日時(未完了の場合はnull) |
status |
string | 現在の実行状態 |
notes |
string | 追加の実行ノートまたはエラーメッセージ |
エラーレスポンス
アクションが見つからない (404):
{
"error": "Action not found",
"actionId": "87654321-4321-4321-4321-210987654321"
}
実行作成失敗 (404):
{
"error": "Action can't create execution",
"actionId": "87654321-4321-4321-4321-210987654321"
}
認証失敗 (401):
HTTP/1.1 401 Unauthorized
{認証失敗を説明するエラーメッセージ}
実行ステータスの値
| ステータス | 説明 |
|---|---|
| Queued | アクションがキューに入り、処理を待機中 |
| Running | アクションが現在実行中 |
| Completed | アクションが正常に完了 |
| Failed | アクションの実行が失敗 |
実装例
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('アクションがキューに入りました:', result);
console.log('実行ID:', result.actionExecutionId);
return result;
} else if (response.status === 404) {
const error = await response.json();
console.error('アクションが見つかりません:', error);
throw new Error(error.error);
} else {
throw new Error(`実行に失敗しました: ${response.status}`);
}
} catch (error) {
console.error('アクション実行中のエラー:', error);
throw error;
}
};
// 使用例
executeAction('aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee', 'your_token')
.then(result => {
// 追跡のためにactionExecutionIdを保存
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):
"""アクションを実行し、実行内容を返す。"""
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'アクションがキューに入りました: {result}')
print(f'実行ID: {result["actionExecutionId"]}')
return result
elif response.status_code == 404:
error = response.json()
print(f'アクションが見つかりません: {error}')
raise Exception(error['error'])
else:
raise Exception(f'実行に失敗しました: {response.status_code}')
# 使用例
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($"アクションがキューに入りました。実行ID: {result.ActionExecutionId}");
return result;
}
else if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
{
throw new Exception($"アクション {actionId} が見つかりません");
}
else
{
throw new Exception($"実行に失敗しました: {response.StatusCode}");
}
}
}
ベストプラクティス
- 実行IDを保存: 実行進行の追跡のために、返される
actionExecutionIdは必ず保存してください - アクション存在確認: 事前にGet Actionエンドポイントでアクションが存在し、有効かを確認してください
- 非同期性の理解: アクションは非同期で実行されます。レスポンスはキューに入ったことを示し、完了ではありません
- エラーハンドリング: 404(アクション未検出)や401(認証エラー)に対して適切なエラーハンドリングを実装してください
- 冪等性: 各呼び出しは新しい実行を作成します。意図しない重複呼び出しは避けてください