repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | --- |
| #2 | title: Webhooks |
| #3 | description: 'Configure and manage webhooks to receive real-time notifications about memory events' |
| #4 | --- |
| #5 | |
| #6 | ## Overview |
| #7 | |
| #8 | Webhooks enable real-time notifications for memory events in your Mem0 project. Webhooks are configured at the project level, meaning each webhook is tied to a specific project and receives events solely from that project. You can configure webhooks to send HTTP POST requests to your specified URLs whenever memories are created, updated, deleted, or categorized. |
| #9 | |
| #10 | ## Managing Webhooks |
| #11 | |
| #12 | ### Create Webhook |
| #13 | |
| #14 | Create a webhook for your project. It will receive events only from that project: |
| #15 | <CodeGroup> |
| #16 | |
| #17 | ```python Python |
| #18 | import os |
| #19 | from mem0 import MemoryClient |
| #20 | |
| #21 | os.environ["MEM0_API_KEY"] = "your-api-key" |
| #22 | |
| #23 | client = MemoryClient() |
| #24 | |
| #25 | # Create webhook in a specific project |
| #26 | webhook = client.create_webhook( |
| #27 | url="https://your-app.com/webhook", |
| #28 | name="Memory Logger", |
| #29 | project_id="proj_123", |
| #30 | event_types=["memory_add", "memory_categorize"] |
| #31 | ) |
| #32 | print(webhook) |
| #33 | ``` |
| #34 | |
| #35 | ```javascript JavaScript |
| #36 | const { MemoryClient } = require('mem0ai'); |
| #37 | const client = new MemoryClient({ apiKey: 'your-api-key'}); |
| #38 | |
| #39 | // Create webhook in a specific project |
| #40 | const webhook = await client.createWebhook({ |
| #41 | url: "https://your-app.com/webhook", |
| #42 | name: "Memory Logger", |
| #43 | projectId: "proj_123", |
| #44 | eventTypes: ["memory_add", "memory_categorize"] |
| #45 | }); |
| #46 | console.log(webhook); |
| #47 | ``` |
| #48 | |
| #49 | ```json Output |
| #50 | { |
| #51 | "webhook_id": "wh_123", |
| #52 | "name": "Memory Logger", |
| #53 | "url": "https://your-app.com/webhook", |
| #54 | "event_types": ["memory_add"], |
| #55 | "project": "default-project", |
| #56 | "is_active": true, |
| #57 | "created_at": "2025-02-18T22:59:56.804993-08:00", |
| #58 | "updated_at": "2025-02-18T23:06:41.479361-08:00" |
| #59 | } |
| #60 | ``` |
| #61 | |
| #62 | </CodeGroup> |
| #63 | |
| #64 | ### Get Webhooks |
| #65 | |
| #66 | Retrieve all webhooks for your project: |
| #67 | |
| #68 | <CodeGroup> |
| #69 | |
| #70 | ```python Python |
| #71 | # Get webhooks for a specific project |
| #72 | webhooks = client.get_webhooks(project_id="proj_123") |
| #73 | print(webhooks) |
| #74 | ``` |
| #75 | |
| #76 | ```javascript JavaScript |
| #77 | // Get webhooks for a specific project |
| #78 | const webhooks = await client.getWebhooks({projectId: "proj_123"}); |
| #79 | console.log(webhooks); |
| #80 | ``` |
| #81 | |
| #82 | ```json Output |
| #83 | [ |
| #84 | { |
| #85 | "webhook_id": "wh_123", |
| #86 | "url": "https://mem0.ai", |
| #87 | "name": "mem0", |
| #88 | "owner": "john", |
| #89 | "event_types": ["memory_add"], |
| #90 | "project": "default-project", |
| #91 | "is_active": true, |
| #92 | "created_at": "2025-02-18T22:59:56.804993-08:00", |
| #93 | "updated_at": "2025-02-18T23:06:41.479361-08:00" |
| #94 | } |
| #95 | ] |
| #96 | |
| #97 | ``` |
| #98 | |
| #99 | </CodeGroup> |
| #100 | |
| #101 | ### Update Webhook |
| #102 | |
| #103 | Update an existing webhook’s configuration by specifying its `webhook_id`: |
| #104 | |
| #105 | <CodeGroup> |
| #106 | |
| #107 | ```python Python |
| #108 | # Update webhook for a specific project |
| #109 | updated_webhook = client.update_webhook( |
| #110 | name="Updated Logger", |
| #111 | url="https://your-app.com/new-webhook", |
| #112 | event_types=["memory_update", "memory_add"], |
| #113 | webhook_id="wh_123" |
| #114 | ) |
| #115 | print(updated_webhook) |
| #116 | ``` |
| #117 | |
| #118 | ```javascript JavaScript |
| #119 | // Update webhook for a specific project |
| #120 | const updatedWebhook = await client.updateWebhook({ |
| #121 | name: "Updated Logger", |
| #122 | url: "https://your-app.com/new-webhook", |
| #123 | eventTypes: ["memory_update", "memory_add"], |
| #124 | webhookId: "wh_123" |
| #125 | }); |
| #126 | console.log(updatedWebhook); |
| #127 | ``` |
| #128 | |
| #129 | ```json Output |
| #130 | { |
| #131 | "message": "Webhook updated successfully" |
| #132 | } |
| #133 | ``` |
| #134 | |
| #135 | </CodeGroup> |
| #136 | |
| #137 | ### Delete Webhook |
| #138 | |
| #139 | Delete a webhook by providing its `webhook_id`: |
| #140 | |
| #141 | <CodeGroup> |
| #142 | |
| #143 | ```python Python |
| #144 | # Delete webhook from a specific project |
| #145 | response = client.delete_webhook(webhook_id="wh_123") |
| #146 | print(response) |
| #147 | ``` |
| #148 | |
| #149 | ```javascript JavaScript |
| #150 | // Delete webhook from a specific project |
| #151 | const response = await client.deleteWebhook({webhookId: "wh_123"}); |
| #152 | console.log(response); |
| #153 | ``` |
| #154 | |
| #155 | ```json Output |
| #156 | { |
| #157 | "message": "Webhook deleted successfully" |
| #158 | } |
| #159 | ``` |
| #160 | |
| #161 | </CodeGroup> |
| #162 | |
| #163 | ## Event Types |
| #164 | |
| #165 | Mem0 supports the following event types for webhooks: |
| #166 | |
| #167 | - `memory_add`: Triggered when a memory is added. |
| #168 | - `memory_update`: Triggered when an existing memory is updated. |
| #169 | - `memory_delete`: Triggered when a memory is deleted. |
| #170 | - `memory_categorize`: Triggered when a memory is categorized. |
| #171 | |
| #172 | ## Webhook Payload |
| #173 | |
| #174 | When a memory event occurs, Mem0 sends an HTTP POST request to your webhook URL with the following payload: |
| #175 | |
| #176 | **Memory add/update/delete payload:** |
| #177 | ```json |
| #178 | { |
| #179 | "event_details": { |
| #180 | "id": "a1b2c3d4-e5f6-4g7h-8i9j-k0l1m2n3o4p5", |
| #181 | "data": { |
| #182 | "memory": "Name is Alex" |
| #183 | }, |
| #184 | "event": "ADD" |
| #185 | } |
| #186 | } |
| #187 | ``` |
| #188 | |
| #189 | **Memory categorize payload:** |
| #190 | ```json |
| #191 | { |
| #192 | "event_details": { |
| #193 | "event": "CATEGORIZE", |
| #194 | "memory_id": "a1b2c3d4-e5f6-4g7h-8i9j-k0l1m2n3o4p5", |
| #195 | "categories": ["hobbies", "travel"] |
| #196 | } |
| #197 | } |
| #198 | ``` |
| #199 | |
| #200 | ## Best Practices |
| #201 | |
| #202 | 1. **Implement Retry Logic**: Ensure your webhook endpoint can handle temporary failures. |
| #203 | 2. **Verify Webhook Source**: Implement security measures to verify that webhook requests originate from Mem0. |
| #204 | 3. **Process Events Asynchronously**: Process webhook events asynchronously to avoid timeouts and ensure reliable handling. |
| #205 | 4. **Monitor Webhook Health**: Regularly review your webhook logs to ensure functionality and promptly address delivery failures. |
| #206 | |
| #207 | If you have any questions, please feel free to reach out to us using one of the following methods: |
| #208 | |
| #209 | <Snippet file="get-help.mdx" /> |