ブロック管理

分析ブロックの取得、更新、および削除

ノートブック内の分析ブロックを管理します。ブロックはデータ変換、計算、フィルタリング操作、およびアラートを実行する基本的な分析単位です。

接続テスト

認証なしPing

GET /api/{tenantId}/{projectId}/block/unauthorized-ping

認証不要のテストエンドポイントです。Block APIがアクセス可能かどうかを確認するために使用します。

レスポンス

Ping Successful

認証済みPing

GET /api/{tenantId}/{projectId}/block/ping

特定のテナントとプロジェクトのAPIアクセスを確認するための認証済みPingエンドポイントです。

レスポンス (200 OK)

Ping Successful (tenant id: {tenantId})

レスポンス (401 Unauthorized)

{error message describing authorization failure}

ブロック詳細取得

GET /api/{tenantId}/{projectId}/block/{blockId}

特定の分析ブロックの構成、実行履歴、およびメタデータを含む詳細情報を取得します。

パスパラメータ

パラメータ 種類 必須 説明
tenantId GUID 必須 テナント識別子
projectId GUID 必須 プロジェクト識別子
blockId GUID 必須 ブロック識別子

レスポンス (200 OK)

{
  "blockId": "550e8400-e29b-41d4-a716-446655440000",
  "notebookId": "660e8400-e29b-41d4-a716-446655440000",
  "blockType": "Filter",
  "blockTitle": "Date Range Filter",
  "blockDescription": "Filters data for the last 30 days",
  "blockOrder": 0,
  "configuration": "{\"filterType\": \"dateRange\", \"startDate\": \"2024-01-01\"}",
  "isDisabled": false,
  "dateCreated": "2024-01-15T10:30:00Z",
  "dateModified": "2024-01-15T14:45:00Z",
  "createdBy": "user@example.com",
  "modifiedBy": "user@example.com",
  "lastExecutionDate": "2024-01-15T14:45:00Z",
  "lastExecutionStatus": "Success",
  "executionCount": 12
}

レスポンスフィールド

フィールド 種類 説明
blockId GUID ブロックの一意識別子
notebookId GUID このブロックを含むノートブックのID
blockType string ブロックの種類(Filter、Calculator、Alertなど)
blockTitle string ブロックの表示タイトル
blockDescription string ブロックの目的の説明
blockOrder integer ノートブック内のブロックの順序(デフォルト: 0)
configuration string ブロック設定を含むJSON文字列
isDisabled boolean ブロックが無効化されているかどうか
dateCreated datetime ブロックの作成日時
dateModified datetime ブロックの最終更新日時
createdBy string ブロック作成者のユーザー名
modifiedBy string ブロックの最終更新者のユーザー名
lastExecutionDate datetime ブロックが最後に実行された日時
lastExecutionStatus string 最後の実行ステータス
executionCount integer ブロックが実行された回数

エラー応答

Not Found (404):

{
  "Error": "Block not found",
  "BlockId": "550e8400-e29b-41d4-a716-446655440000"
}

ブロック更新

PUT /api/{tenantId}/{projectId}/block/{blockId}

既存のブロックのメタデータを更新します。実行履歴は保持し、指定されたフィールドのみを更新します。

リクエストボディ

{
  "blockTitle": "Updated Date Filter",
  "blockDescription": "Filters data for custom date range",
  "isDisabled": false
}

リクエストフィールド

フィールド 種類 必須 説明
blockTitle string なし 新しいブロックタイトル
blockDescription string なし 新しい説明文
isDisabled boolean なし ブロックの無効化設定

レスポンス (200 OK)

GETエンドポイントと同じ構造の更新されたブロックオブジェクトを返します。

エラー応答

Bad Request (400):

Failed to update block.

ブロック削除

DELETE /api/{tenantId}/{projectId}/block/{blockId}

ノートブックからブロックとそのすべての実行履歴を完全に削除します。この操作は元に戻せません。

レスポンスコード

  • 204 No Content - ブロックの削除に成功
  • 400 Bad Request - ブロック削除に失敗
  • 401 Unauthorized - 認証されていないかアクセス権なし
  • 404 Not Found - ブロックが存在しない

ブロック作成

ブロックの作成はBlock APIではなく、Notebook APIで行います。

POST /api/{tenantId}/{projectId}/notebook/{notebookId}/blocks

完全なブロック作成のドキュメントはNotebook APIを参照してください。

実装例

cURL

# 接続テスト(認証なし)
curl -X GET "https://your-mindzie-instance.com/api/12345678-1234-1234-1234-123456789012/87654321-4321-4321-4321-210987654321/block/unauthorized-ping"

# 接続テスト(認証あり)
curl -X GET "https://your-mindzie-instance.com/api/12345678-1234-1234-1234-123456789012/87654321-4321-4321-4321-210987654321/block/ping" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN"

# ブロック詳細取得
curl -X GET "https://your-mindzie-instance.com/api/12345678-1234-1234-1234-123456789012/87654321-4321-4321-4321-210987654321/block/550e8400-e29b-41d4-a716-446655440000" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN"

# ブロック更新
curl -X PUT "https://your-mindzie-instance.com/api/12345678-1234-1234-1234-123456789012/87654321-4321-4321-4321-210987654321/block/550e8400-e29b-41d4-a716-446655440000" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"blockTitle": "Updated Filter", "isDisabled": false}'

# ブロック削除
curl -X DELETE "https://your-mindzie-instance.com/api/12345678-1234-1234-1234-123456789012/87654321-4321-4321-4321-210987654321/block/550e8400-e29b-41d4-a716-446655440000" \
  -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';

class BlockManager {
  constructor(token) {
    this.token = token;
    this.headers = {
      'Authorization': `Bearer ${token}`,
      'Content-Type': 'application/json'
    };
  }

  async getBlock(blockId) {
    const url = `${BASE_URL}/api/${TENANT_ID}/${PROJECT_ID}/block/${blockId}`;
    const response = await fetch(url, { headers: this.headers });

    if (response.ok) {
      return await response.json();
    } else if (response.status === 404) {
      throw new Error('Block not found');
    } else {
      throw new Error(`Failed to get block: ${response.status}`);
    }
  }

  async updateBlock(blockId, updates) {
    const url = `${BASE_URL}/api/${TENANT_ID}/${PROJECT_ID}/block/${blockId}`;
    const response = await fetch(url, {
      method: 'PUT',
      headers: this.headers,
      body: JSON.stringify(updates)
    });

    if (response.ok) {
      return await response.json();
    } else {
      throw new Error(`Failed to update block: ${response.status}`);
    }
  }

  async deleteBlock(blockId) {
    const url = `${BASE_URL}/api/${TENANT_ID}/${PROJECT_ID}/block/${blockId}`;
    const response = await fetch(url, {
      method: 'DELETE',
      headers: this.headers
    });

    return response.status === 204;
  }
}

// 使用例
const manager = new BlockManager('your-auth-token');

// ブロック詳細取得
const block = await manager.getBlock('block-guid');
console.log(`Block: ${block.blockTitle} (${block.blockType})`);

// ブロック更新
const updated = await manager.updateBlock('block-guid', {
  blockTitle: 'Updated Title',
  isDisabled: false
});

// ブロック削除
const deleted = await manager.deleteBlock('block-guid');

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 BlockManager:
    def __init__(self, token):
        self.headers = {
            'Authorization': f'Bearer {token}',
            'Content-Type': 'application/json'
        }

    def get_block(self, block_id):
        """ブロック詳細取得"""
        url = f'{BASE_URL}/api/{TENANT_ID}/{PROJECT_ID}/block/{block_id}'
        response = requests.get(url, headers=self.headers)

        if response.ok:
            return response.json()
        elif response.status_code == 404:
            raise Exception('Block not found')
        else:
            raise Exception(f'Failed to get block: {response.status_code}')

    def update_block(self, block_id, title=None, description=None, disabled=None):
        """ブロックメタデータ更新"""
        url = f'{BASE_URL}/api/{TENANT_ID}/{PROJECT_ID}/block/{block_id}'
        payload = {}
        if title is not None:
            payload['blockTitle'] = title
        if description is not None:
            payload['blockDescription'] = description
        if disabled is not None:
            payload['isDisabled'] = disabled

        response = requests.put(url, json=payload, headers=self.headers)

        if response.ok:
            return response.json()
        else:
            raise Exception(f'Failed to update block: {response.status_code}')

    def delete_block(self, block_id):
        """ブロック削除"""
        url = f'{BASE_URL}/api/{TENANT_ID}/{PROJECT_ID}/block/{block_id}'
        response = requests.delete(url, headers=self.headers)
        return response.status_code == 204

# 使用例
manager = BlockManager('your-auth-token')

# ブロック取得
block = manager.get_block('block-guid')
print(f"Block: {block['blockTitle']} ({block['blockType']})")
print(f"Execution count: {block['executionCount']}")

# ブロック更新
updated = manager.update_block('block-guid', title='New Title', disabled=False)
print(f"Updated: {updated['blockTitle']}")

# ブロック削除
if manager.delete_block('block-guid'):
    print('Block deleted successfully')

C#

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

public class BlockReturn
{
    public Guid BlockId { get; set; }
    public Guid NotebookId { get; set; }
    public string BlockType { get; set; }
    public string BlockTitle { get; set; }
    public string BlockDescription { get; set; }
    public int BlockOrder { get; set; }
    public string Configuration { get; set; }
    public bool IsDisabled { get; set; }
    public DateTime DateCreated { get; set; }
    public DateTime DateModified { get; set; }
    public string CreatedBy { get; set; }
    public string ModifiedBy { get; set; }
    public DateTime? LastExecutionDate { get; set; }
    public string LastExecutionStatus { get; set; }
    public int ExecutionCount { get; set; }
}

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

    public BlockApiClient(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<BlockReturn> GetBlockAsync(Guid blockId)
    {
        var url = $"{_baseUrl}/api/{_tenantId}/{_projectId}/block/{blockId}";
        var response = await _httpClient.GetAsync(url);

        if (response.IsSuccessStatusCode)
        {
            var json = await response.Content.ReadAsStringAsync();
            return JsonSerializer.Deserialize<BlockReturn>(json,
                new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
        }

        throw new Exception($"Failed to get block: {response.StatusCode}");
    }

    public async Task<BlockReturn> UpdateBlockAsync(Guid blockId, string title, string description, bool? isDisabled)
    {
        var url = $"{_baseUrl}/api/{_tenantId}/{_projectId}/block/{blockId}";
        var payload = new
        {
            blockTitle = title,
            blockDescription = description,
            isDisabled = isDisabled
        };

        var content = new StringContent(
            JsonSerializer.Serialize(payload),
            Encoding.UTF8,
            "application/json");

        var response = await _httpClient.PutAsync(url, content);

        if (response.IsSuccessStatusCode)
        {
            var json = await response.Content.ReadAsStringAsync();
            return JsonSerializer.Deserialize<BlockReturn>(json,
                new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
        }

        throw new Exception($"Failed to update block: {response.StatusCode}");
    }

    public async Task<bool> DeleteBlockAsync(Guid blockId)
    {
        var url = $"{_baseUrl}/api/{_tenantId}/{_projectId}/block/{blockId}";
        var response = await _httpClient.DeleteAsync(url);
        return response.StatusCode == System.Net.HttpStatusCode.NoContent;
    }
}