> For the complete documentation index, see [llms.txt](https://tilepmoney.gitbook.io/tilepmoney-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tilepmoney.gitbook.io/tilepmoney-docs/technical/api-reference.md).

# API Reference

TilepMoney provides RESTful API endpoints for workflow management, execution monitoring, and blockchain interactions.

### Base URL

```
Development: http://localhost:3000/api
Production: https://your-domain.com/api
```

### Authentication

All API endpoints require authentication via Privy session tokens.

```typescript
headers: {
  'Authorization': `Bearer ${userSessionToken}`
}
```

### Workflow Management

#### List Workflows

Get all workflows for the authenticated user.

**Endpoint:** `GET /api/workflows`

**Response:**

```json
{
  "workflows": [
    {
      "_id": "65b...",
      "name": "Treasury Automation",
      "description": "Auto-allocate monthly revenue",
      "status": "draft",
      "nodes": [...],
      "edges": [...],
      "createdAt": "2025-01-01T00:00:00Z"
    }
  ]
}
```

#### Create Workflow

Create a new workflow graph.

**Endpoint:** `POST /api/workflows`

**Request Body:**

```json
{
  "name": "New Workflow",
  "description": "Optional description",
  "nodes": [], // React Flow Node objects
  "edges": [] // React Flow Edge objects
}
```

#### Update Workflow

**Endpoint:** `PUT /api/workflows/[id]`

**Request Body:**

```json
{
  "name": "Updated Name",
  "nodes": [...],
  "edges": [...]
}
```

#### Delete Workflow

**Endpoint:** `DELETE /api/workflows/[id]`

### Workflow Execution

#### Execute (Server-Side Trigger)

Initiate execution logic from the server (for automation/scheduling). Note: Most user-initiated executions happen directly on-chain via the frontend interaction with MainController.

**Endpoint:** `POST /api/workflows/[id]/execute`

#### Simulate Workflow

Run a dry-run to estimate gas and validate logic.

**Endpoint:** `POST /api/workflows/[id]/simulate`

**Response:**

```json
{
  "estimatedGas": "0.05",
  "estimatedTime": 120,
  "simulationResult": "success",
  "outputChanges": {
    "balance_USDT": "+500"
  }
}
```

#### Get Execution Status

**Endpoint:** `GET /api/workflows/[id]/status`

**Response:**

```json
{
  "executionId": "exec_123...",
  "status": "running",
  "currentNodeId": "node_swap_1",
  "logs": [{ "timestamp": "...", "message": "Bridge completed: 0x123..." }]
}
```

### Blockchain Operations

These endpoints serve as proxies or helpers for blockchain interactions, often used for setting up test environments (minting dummy tokens) or getting data.

#### Mint Tokens (Testnet)

**Endpoint:** `POST /api/blockchain/mint`

```json
{
  "token": "IDR",
  "amount": "1000000",
  "recipient": "0x..."
}
```

#### Execute Swap (Quote/Proxy)

**Endpoint:** `POST /api/blockchain/swap`

```json
{
  "tokenIn": "IDRX",
  "tokenOut": "USDT",
  "amount": "50000"
}
```

#### Bridge Tokens

**Endpoint:** `POST /api/blockchain/bridge`

```json
{
  "token": "USDT",
  "destinationChainId": 5000, // Mantle
  "amount": "100"
}
```

#### Get Balance

**Endpoint:** `GET /api/blockchain/balance?address=0x...`

**Response:**

```json
{
  "address": "0x...",
  "balances": {
    "ETH": "1.5",
    "mUSDT": "500.00"
  }
}
```

***

### Error Codes

* `401 Unauthorized` - Missing or invalid Privy token.
* `404 Not Found` - Workflow ID or User not found.
* `422 Unprocessable Entity` - Invalid Node/Edge configuration.
* `500 Internal Server Error` - Blockchain RPC failure or DB error.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tilepmoney.gitbook.io/tilepmoney-docs/technical/api-reference.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
