Add delete users method (#1683)
This commit is contained in:
@@ -639,6 +639,28 @@ curl -X DELETE "https://api.mem0.ai/v1/memories/?user_id=alex" \
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
Delete all users:
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```python Python
|
||||
client.delete_users()
|
||||
```
|
||||
|
||||
```javascript JavaScript
|
||||
client.delete_users()
|
||||
.then(users => console.log(users))
|
||||
.catch(error => console.error(error));
|
||||
```
|
||||
|
||||
```json Output
|
||||
{'message': 'All users, agents, and sessions deleted.'}
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
|
||||
|
||||
Fun fact: You can also delete the memory using the `add()` method by passing a natural language command:
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
@@ -245,6 +245,17 @@ class MemoryClient:
|
||||
capture_client_event("client.users", self)
|
||||
return response.json()
|
||||
|
||||
@api_error_handler
|
||||
def delete_users(self) -> Dict[str, Any]:
|
||||
"""Delete all users, agents, or sessions."""
|
||||
entities = self.users()
|
||||
for entity in entities["results"]:
|
||||
response = self.client.delete(f"/entities/{entity['type']}/{entity['id']}/")
|
||||
response.raise_for_status()
|
||||
|
||||
capture_client_event("client.delete_users", self)
|
||||
return {"message": "All users, agents, and sessions deleted."}
|
||||
|
||||
def reset(self):
|
||||
"""Reset the client. (Not implemented)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user