TurfAITurfAI Developers
Api_syncedGuides

API Testing Guide

Synced from the source repositories. Do not edit by hand.

Quick reference for testing all TurfAI workflow APIs.

Prerequisites

  1. Start DMS:
cd dms/
npm run develop  # or npm run start
  1. Get JWT Token:
JWT=$(curl -s -X POST http://localhost:1338/api/auth/local \
  -H "Content-Type: application/json" \
  -d '{"identifier":"turfai@openturf.in","password":"turf123@!"}' \
  | jq -r '.jwt')

echo "JWT: $JWT"

Workflow Builder APIs

1. Get Task Types

curl http://localhost:1338/api/workflows/task-types \
  -H "Authorization: Bearer $JWT" | jq '.'

Expected: List of 13 task types with schemas

2. Validate Workflow

curl -X POST http://localhost:1338/api/workflows/validate \
  -H "Authorization: Bearer $JWT" \
  -H "Content-Type: application/json" \
  -d '{
    "workflow_definition": {
      "nodes": [{"id":"1","type":"start","data":{"task_type":"custom_task","config":{}}}],
      "edges": []
    }
  }' | jq '.'

Expected: {"data":{"valid":true,"errors":[]}}


Workflow Analytics APIs

3. Metrics Overview

curl "http://localhost:1338/api/workflows/metrics/overview?period=last_7_days" \
  -H "Authorization: Bearer $JWT" | jq '.'

Expected: Dashboard metrics with executions, success rate, etc.

4. Workflow-Specific Analytics

# Replace 123 with actual activity ID
curl http://localhost:1338/api/workflows/123/analytics \
  -H "Authorization: Bearer $JWT" | jq '.'

Expected: Detailed analytics with step performance and failure analysis

5. Execution Timeline

# Replace 456 with actual execution ID
curl http://localhost:1338/api/workflow-executions/456/timeline \
  -H "Authorization: Bearer $JWT" | jq '.'

Expected: Step-by-step timeline with durations and results

6. Recent Errors

curl "http://localhost:1338/api/workflows/errors/recent?limit=10" \
  -H "Authorization: Bearer $JWT" | jq '.'

Expected: List of recent failures with error details


Workflow Execution APIs (Existing)

7. Create Activity

curl -X POST http://localhost:1338/api/activities \
  -H "Authorization: Bearer $JWT" \
  -H "Content-Type: application/json" \
  -d '{
    "data": {
      "name": "Test Workflow",
      "workflow_type": "document_processing",
      "workflow_definition": {
        "nodes": [
          {"id":"start","type":"start","data":{"task_type":"custom_task","config":{}}},
          {"id":"end","type":"end","data":{"task_type":"custom_task","config":{}}}
        ],
        "edges": [{"id":"e1","source":"start","target":"end"}]
      }
    }
  }' | jq '.'

8. List Activities

curl http://localhost:1338/api/activities \
  -H "Authorization: Bearer $JWT" | jq '.'

9. Create Execution

# Replace 123 with activity ID
curl -X POST http://localhost:1338/api/workflow-executions \
  -H "Authorization: Bearer $JWT" \
  -H "Content-Type: application/json" \
  -d '{
    "data": {
      "activity": 123,
      "workflow_definition": {...},
      "inputs": {"file_url": "gs://test/file.pdf"}
    }
  }' | jq '.'

10. Execute Workflow

# Replace 456 with execution ID
curl -X POST http://localhost:1338/api/workflow-executions/456/execute \
  -H "Authorization: Bearer $JWT" \
  -H "Content-Type: application/json" \
  -d '{"inputs": {"file_url": "gs://test/file.pdf"}}' | jq '.'

11. Get Execution Status

# Replace 456 with execution ID
curl http://localhost:1338/api/workflow-executions/456/status \
  -H "Authorization: Bearer $JWT" | jq '.'

Quick Test All Endpoints

#!/bin/bash
# Quick test script

# Get JWT
JWT=$(curl -s -X POST http://localhost:1338/api/auth/local \
  -H "Content-Type: application/json" \
  -d '{"identifier":"turfai@openturf.in","password":"turf123@!"}' \
  | jq -r '.jwt')

echo "Testing all endpoints..."

# 1. Task Types
echo "1. Task Types..."
curl -s http://localhost:1338/api/workflows/task-types \
  -H "Authorization: Bearer $JWT" | jq '.data.task_types | length'

# 2. Validate
echo "2. Validate..."
curl -s -X POST http://localhost:1338/api/workflows/validate \
  -H "Authorization: Bearer $JWT" \
  -H "Content-Type: application/json" \
  -d '{"workflow_definition":{"nodes":[{"id":"1","type":"start","data":{"task_type":"custom_task","config":{}}}],"edges":[]}}' \
  | jq '.data.valid'

# 3. Metrics Overview
echo "3. Metrics Overview..."
curl -s "http://localhost:1338/api/workflows/metrics/overview" \
  -H "Authorization: Bearer $JWT" | jq '.data.total_executions'

# 4. Recent Errors
echo "4. Recent Errors..."
curl -s "http://localhost:1338/api/workflows/errors/recent" \
  -H "Authorization: Bearer $JWT" | jq '.data.total'

echo "All tests complete!"

Expected Responses

Success Response Format

{
  "data": {
    // Response data here
  }
}

Error Response Format

{
  "error": {
    "status": 400,
    "name": "BadRequestError",
    "message": "Error message",
    "details": {
      "errors": ["Detail 1", "Detail 2"]
    }
  }
}

Troubleshooting

401 Unauthorized: JWT expired, get a new one 404 Not Found: Check endpoint path and IDs 400 Bad Request: Check request body format 500 Internal Server Error: Check DMS logs


Note: For complete integration examples, see /examples/ directory.

On this page