Skip to Content
Minds API Examples

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.

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

// 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.

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

  1. Trigger: New row in Google Sheets
  2. 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}}"}

Make (Integromat) Example

  1. Add an HTTP > Make a request module
  2. Set URL to https://trigglio.com/api/v1/minds/{mindId}/knowledge
  3. Set method to POST
  4. Add header: Authorization: Bearer tr_live_your_key
  5. 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 StatusCodeDescription
400validation_errorMissing or invalid fields
400invalid_jsonRequest body is not valid JSON
400duplicate_sourceSource already exists
401missing_tokenNo Authorization header
401invalid_keyAPI key not found
403insufficient_scopeAPI key lacks required scope
403mind_limit_reachedPlan limit for Minds reached
403source_limit_reachedSource limit per Mind reached
404not_foundResource not found or not owned
429rate_limitedToo many requests
500internal_errorServer error

Rate Limits

All responses include rate limit headers:

X-RateLimit-Limit: 100 X-RateLimit-Remaining: 98 X-RateLimit-Reset: 2024-06-15T10:31:00Z

When rate limited (429), check the Retry-After header for when to retry.

Last updated on