API ブロック YAML スキーマ
API ブロックの YAML 設定リファレンス
スキーマ定義
type: object
required:
- type
- name
- inputs
properties:
type:
type: string
enum: [api]
description: Block type identifier
name:
type: string
description: Display name for this API block
inputs:
type: object
required:
- url
- method
properties:
url:
type: string
description: The endpoint URL to send the request to
method:
type: string
enum: [GET, POST, PUT, DELETE, PATCH]
description: HTTP method for the request
default: GET
params:
type: array
description: Query parameters as table entries
items:
type: object
required:
- id
- cells
properties:
id:
type: string
description: Unique identifier for the parameter entry
cells:
type: object
required:
- Key
- Value
properties:
Key:
type: string
description: Parameter name
Value:
type: string
description: Parameter value
headers:
type: array
description: HTTP headers as table entries
items:
type: object
required:
- id
- cells
properties:
id:
type: string
description: Unique identifier for the header entry
cells:
type: object
required:
- Key
- Value
properties:
Key:
type: string
description: Header name
Value:
type: string
description: Header value
body:
type: string
description: Request body for POST/PUT/PATCH methods
timeout:
type: number
description: Request timeout in milliseconds
default: 30000
minimum: 1000
maximum: 300000
connections:
type: object
properties:
success:
type: string
description: Target block ID for successful requests
error:
type: string
description: Target block ID for error handling
接続設定
接続はリクエスト結果に基づいてワークフローの進行先を定義します:
connections:
success: <string> # Target block ID for successful requests
error: <string> # Target block ID for error handling (optional)
例
シンプルな GET リクエスト
user-api:
type: api
name: "Fetch User Data"
inputs:
url: "https://api.example.com/users/123"
method: GET
headers:
- id: header-1-uuid-here
cells:
Key: "Authorization"
Value: "Bearer {{API_TOKEN}}"
- id: header-2-uuid-here
cells:
Key: "Content-Type"
Value: "application/json"
connections:
success: process-user-data
error: handle-api-error
ボディを含む POST リクエスト
create-ticket:
type: api
name: "Create Support Ticket"
inputs:
url: "https://api.support.com/tickets"
method: POST
headers:
- id: auth-header-uuid
cells:
Key: "Authorization"
Value: "Bearer {{SUPPORT_API_KEY}}"
- id: content-type-uuid
cells:
Key: "Content-Type"
Value: "application/json"
body: |
{
"title": "<agent.title>",
"description": "<agent.description>",
"priority": "high"
}
connections:
success: ticket-created
error: ticket-error
動的 URL とクエリパラメータ
search-api:
type: api
name: "Search Products"
inputs:
url: "https://api.store.com/products"
method: GET
params:
- id: search-param-uuid
cells:
Key: "q"
Value: <start.searchTerm>
- id: limit-param-uuid
cells:
Key: "limit"
Value: "10"
- id: category-param-uuid
cells:
Key: "category"
Value: <filter.category>
headers:
- id: auth-header-uuid
cells:
Key: "Authorization"
Value: "Bearer {{STORE_API_KEY}}"
connections:
success: display-results
パラメータ形式
ヘッダーとパラメータ(クエリパラメータ)は以下の構造のテーブル形式を使用します:
headers:
- id: unique-identifier-here
cells:
Key: "Content-Type"
Value: "application/json"
- id: another-unique-identifier
cells:
Key: "Authorization"
Value: "Bearer {{API_TOKEN}}"
params:
- id: param-identifier-here
cells:
Key: "limit"
Value: "10"
構造の詳細:
id
: テーブル行を追跡するための一意の識別子cells.Key
: パラメータ/ヘッダー名cells.Value
: パラメータ/ヘッダーの値- この形式により、適切なテーブル管理とUI状態の保持が可能になります
出力参照
API ブロックが実行された後、後続のブロックでその出力を参照できます。API ブロックは主に3つの出力を提供します:
利用可能な出力
出力 | 型 | 説明 |
---|---|---|
data | any | API からのレスポンスボディ/ペイロード |
status | number | HTTP ステータスコード(200、404、500など) |
headers | object | サーバーから返されたレスポンスヘッダー |
使用例
# Reference API response data
process-data:
type: function
name: "Process API Data"
inputs:
code: |
const responseData = <fetchuserdata.data>;
const statusCode = <fetchuserdata.status>;
const responseHeaders = <fetchuserdata.headers>;
if (statusCode === 200) {
return {
success: true,
user: responseData,
contentType: responseHeaders['content-type']
};
} else {
return {
success: false,
error: `API call failed with status ${statusCode}`
};
}
# Use API data in an agent block
analyze-response:
type: agent
name: "Analyze Response"
inputs:
userPrompt: |
Analyze this API response:
Status: <fetchuserdata.status>
Data: <fetchuserdata.data>
Provide insights about the response.
# Conditional logic based on status
check-status:
type: condition
name: "Check API Status"
inputs:
condition: <fetchuserdata.status> === 200
connections:
true: success-handler
false: error-handler
実用的な例
user-api:
type: api
name: "Fetch User Data"
inputs:
url: "https://api.example.com/users/123"
method: GET
connections:
success: process-response
process-response:
type: function
name: "Process Response"
inputs:
code: |
const user = <fetchuserdata.data>;
const status = <fetchuserdata.status>;
console.log(`API returned status: ${status}`);
console.log(`User data:`, user);
return {
userId: user.id,
email: user.email,
isActive: status === 200
};
エラー処理
api-with-error-handling:
type: api
name: "API Call"
inputs:
url: "https://api.example.com/data"
method: GET
connections:
success: check-response
error: handle-error
check-response:
type: condition
name: "Check Response Status"
inputs:
condition: <apicall.status> >= 200 && <apicall.status> < 300
connections:
true: process-success
false: handle-api-error
process-success:
type: function
name: "Process Success"
inputs:
code: |
return {
success: true,
data: <apicall.data>,
message: "API call successful"
};
handle-api-error:
type: function
name: "Handle API Error"
inputs:
code: |
return {
success: false,
status: <apicall.status>,
error: "API call failed",
data: <apicall.data>
};
YAMLの文字列エスケープ
YAMLを記述する際、適切に解析されるために引用符で囲む必要がある文字列があります:
引用符で囲む必要がある文字列
# URLs with hyphens, colons, special characters
url: "https://api.example.com/users/123"
url: "https://my-api.example.com/data"
# Header values with hyphens or special characters
headers:
- id: header-uuid
cells:
Key: "User-Agent"
Value: "My-Application/1.0"
- id: auth-uuid
cells:
Key: "Authorization"
Value: "Bearer my-token-123"
# Parameter values with hyphens
params:
- id: param-uuid
cells:
Key: "sort-by"
Value: "created-at"
引用符を使用するタイミング
- ✅ 常に引用符で囲む: URL、トークン、ハイフン、コロン、特殊文字を含む値
- ✅ 常に引用符で囲む: 文字列として扱うべき数字で始まる値
- ✅ 常に引用符で囲む: 文字列として維持すべきブール値のように見える文字列
- ❌ 引用符で囲まない: 特殊文字を含まない単純な英数字の文字列
例
# ✅ Correct
url: "https://api.stripe.com/v1/charges"
headers:
- id: auth-header
cells:
Key: "Authorization"
Value: "Bearer sk-test-123456789"
# ❌ Incorrect (may cause parsing errors)
url: https://api.stripe.com/v1/charges
headers:
- id: auth-header
cells:
Key: Authorization
Value: Bearer sk-test-123456789
ベストプラクティス
- APIキーには環境変数を使用する:
{{API_KEY_NAME}}
- エラー接続でエラー処理を含める
- ユースケースに適したタイムアウトを設定する
- 後続のブロックでレスポンスステータスコードを検証する
- 参照しやすいように意味のあるブロック名を使用する
- 特殊文字、URL、トークンを含む文字列は常に引用符で囲む