API Request Code Snippets
Ready-to-use code examples for interacting with MetaPilot API.
1. User Login (cURL)
bash
curl -X POST http://localhost:8000/api/auth/login/ \
-H "Content-Type: application/json" \
-d '{
"email": "admin@metapilot.in",
"password": "AdminSecret123"
}'
2. Create Tenant (Python Requests)
python
import requests
url = "http://localhost:8000/api/clients/"
headers = {
"Authorization": "Bearer <access_token>",
"Content-Type": "application/json"
}
data = {
"name": "Acme Retail Org",
"slug": "acme-retail",
"agency": "405b16e0-3215-40fc-bac6-c3fb9b2649c4",
"wa_access_token": "EAAG..."
}
response = requests.post(url, json=data, headers=headers)
print(response.status_code, response.json())
3. WebSocket Realtime Inbox (JavaScript)
javascript
const ws = new WebSocket("ws://localhost:8000/ws/inbox/96598ec0-9ee5-4e10-9948-85894cbc9fcf/");
ws.onopen = () => console.log("Connected to Realtime Inbox WS");
ws.onmessage = (event) => {
const payload = JSON.parse(event.data);
if (payload.type === "new_message") {
console.log("New inbound message:", payload.data.content);
}
};