Minds API Examples
Complete workflow examples for common use cases.
Create a Mind and Train It
This example creates a Mind, adds multiple knowledge sources, waits for processing, and publishes it.
JavaScript
const API_KEY = 'tr_live_your_api_key';
const BASE = 'https://trigglio.com/api/v1';
const headers = {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
};
// 1. Create the Mind
const mindRes = await fetch(`${BASE}/minds`, {
method: 'POST',
headers,
body: JSON.stringify({
name: 'Support Agent',
headline: 'AI-powered customer support',
systemPrompt: 'You are a friendly support agent. Help customers with their questions using the knowledge base.',
suggestedQuestions: [
'How do I get started?',
'What are the pricing plans?',
'How do I reset my password?'
]
})
});
const { mind } = await mindRes.json();
console.log(`Created Mind: ${mind.id}`);
// 2. Add knowledge sources
const sources = [
{ name: 'Help Center', type: 'url', url: 'https://help.example.com' },
{ name: 'FAQ Page', type: 'url', url: 'https://example.com/faq' },
{ name: 'Product Tour', type: 'youtube', youtubeUrl: 'https://youtube.com/watch?v=abc123' }
];
const sourceIds = [];
for (const source of sources) {
const res = await fetch(`${BASE}/minds/${mind.id}/knowledge`, {
method: 'POST',
headers,
body: JSON.stringify(source)
});
const { source: created } = await res.json();
sourceIds.push(created.id);
console.log(`Added source: ${created.name} (${created.id})`);
}
// 3. Wait for all sources to be ready
for (const sourceId of sourceIds) {
let status = 'pending';
while (status !== 'ready' && status !== 'failed') {
await new Promise(r => setTimeout(r, 5000));
const res = await fetch(`${BASE}/minds/${mind.id}/knowledge/${sourceId}`, { headers });
const data = await res.json();
status = data.source.status;
console.log(`Source ${sourceId}: ${status}`);
}
}
// 4. Publish the Mind
await fetch(`${BASE}/minds/${mind.id}/publish`, {
method: 'POST',
headers,
body: JSON.stringify({ isPublished: true })
});
console.log(`Mind published at: https://trigglio.com/m/${mind.slug}`);Upload a Document
JavaScript
// Upload the file
const formData = new FormData();
formData.append('file', fs.createReadStream('./product-guide.pdf'));
const uploadRes = await fetch(`${BASE}/minds/${mindId}/knowledge/upload`, {
method: 'POST',
headers: { 'Authorization': `Bearer ${API_KEY}` },
body: formData
});
const upload = await uploadRes.json();
// Create the knowledge source
const sourceRes = await fetch(`${BASE}/minds/${mindId}/knowledge`, {
method: 'POST',
headers,
body: JSON.stringify({
name: 'Product Guide',
type: 'document',
fileUrl: upload.fileUrl,
fileName: upload.fileName,
mimeType: upload.mimeType,
fileSize: upload.fileSize
})
});Webhook Callback Handler
Set up a server to receive processing notifications instead of polling.
Node.js (Express)
import express from 'express';
import { createHmac } from 'crypto';
const app = express();
app.use(express.json());
app.post('/webhooks/trigglio', (req, res) => {
// Verify signature
const signature = req.headers['x-trigglio-signature'];
const expected = createHmac('sha256', SIGNING_SECRET)
.update(JSON.stringify(req.body))
.digest('hex');
if (signature !== expected) {
return res.status(401).send('Invalid signature');
}
const { event, sourceId, mindId, status, chunkCount, error } = req.body;
if (event === 'knowledge.processed') {
console.log(`Source ${sourceId} ready with ${chunkCount} chunks`);
// Trigger your workflow — publish the Mind, notify users, etc.
} else if (event === 'knowledge.failed') {
console.error(`Source ${sourceId} failed: ${error}`);
// Alert your team or retry
}
res.sendStatus(200);
});Zapier / Make / n8n Integration
The Minds API works with any HTTP-capable automation tool.
Zapier Example
- Trigger: New row in Google Sheets
- Action: Webhooks by Zapier > Custom Request
- Method:
POST - URL:
https://trigglio.com/api/v1/minds/{mindId}/knowledge - Headers:
Authorization: Bearer tr_live_your_key - Body:
{"name": "{{Row Title}}", "type": "url", "url": "{{Row URL}}"}
- Method:
Make (Integromat) Example
- Add an HTTP > Make a request module
- Set URL to
https://trigglio.com/api/v1/minds/{mindId}/knowledge - Set method to
POST - Add header:
Authorization: Bearer tr_live_your_key - Set body to JSON with your source data
Error Handling
All v1 endpoints return errors in a consistent format:
{
"status": "error",
"message": "Human-readable error description",
"code": "machine_readable_code"
}Common Error Codes
| HTTP Status | Code | Description |
|---|---|---|
| 400 | validation_error | Missing or invalid fields |
| 400 | invalid_json | Request body is not valid JSON |
| 400 | duplicate_source | Source already exists |
| 401 | missing_token | No Authorization header |
| 401 | invalid_key | API key not found |
| 403 | insufficient_scope | API key lacks required scope |
| 403 | mind_limit_reached | Plan limit for Minds reached |
| 403 | source_limit_reached | Source limit per Mind reached |
| 404 | not_found | Resource not found or not owned |
| 429 | rate_limited | Too many requests |
| 500 | internal_error | Server error |
Rate Limits
All responses include rate limit headers:
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 98
X-RateLimit-Reset: 2024-06-15T10:31:00ZWhen rate limited (429), check the Retry-After header for when to retry.
Last updated on