API Reference
Webhooks
Receive webhooks from external services and send webhooks from Magneteco
Receive Webhooks
Receive webhooks from external services.
POST /webhooks/:sourceSupported Sources
| Source | Description |
|---|---|
stripe | Stripe payment events |
github | GitHub repository events |
netsuite | NetSuite record events |
salesforce | Salesforce CRM events |
slack | Slack messaging events |
custom | Generic webhook handler |
Example: Stripe Webhook
curl -X POST https://api.magneteco.io/v1/webhooks/stripe \
-H "Content-Type: application/json" \
-H "Stripe-Signature: $STRIPE_SIGNATURE" \
-d '{
"type": "invoice.paid",
"data": {
"object": {
"customer": "cus_123",
"amount_paid": 9900,
"currency": "usd"
}
}
}'Response
{
"status": "processed" | "ignored",
"eventId"?: "evt-456" // Only if processed
}Custom Webhook Handler
For sources not natively supported:
curl -X POST https://api.magneteco.io/v1/webhooks/custom \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"appId": "my-app",
"userId": "user-123",
"eventType": "custom_event",
"data": {
"key": "value"
}
}'Send Webhooks from Magneteco
Magneteco can send webhooks to your app for certain events.
Configuring Outbound Webhooks
curl -X POST https://api.magneteco.io/v1/config/webhooks \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"appId": "tanda",
"url": "https://your-app.com/magneteco-webhook",
"events": ["memory.processed", "entity.created", "conflict.detected"],
"secret": "your-webhook-secret"
}'Webhook Events
| Event | Description |
|---|---|
memory.processed | Content has been processed and memorized |
entity.created | New entity discovered |
entity.updated | Entity properties updated |
relationship.created | New relationship discovered |
conflict.detected | Conflicting information detected |
maintenance.completed | Maintenance job completed |
Webhook Payload
{
"event": "memory.processed",
"timestamp": "2024-01-15T14:30:00Z",
"appId": "tanda",
"userId": "user-123",
"data": {
"resourceId": "res-789",
"itemsCreated": 3,
"entitiesCreated": 2,
"categoriesUpdated": ["client_preferences"]
}
}Verify Webhook Signature
const crypto = require('crypto');
function verifyWebhook(
payload: string,
signature: string,
secret: string
): boolean {
const expected = crypto
.createHmac('sha256', secret)
.update(payload)
.digest('hex');
return crypto.timingSafeEqual(
Buffer.from(signature),
Buffer.from(`sha256=${expected}`)
);
}Webhook Retry Policy
Failed webhooks are retried with exponential backoff:
| Attempt | Delay |
|---|---|
| 1 | Immediate |
| 2 | 1 minute |
| 3 | 5 minutes |
| 4 | 30 minutes |
| 5 | 2 hours |
After 5 failed attempts, the webhook is marked as failed and requires manual intervention.