Data Export API
Here's some sample code for a specific scenario using the Data Export API.
Grab all of the messages from yesterday
Continuously send GET requests until next_page_uri
is null.
import fetch from "node-fetch"
async function fetchMessages() {
const API_KEY = "<YOUR-API-KEY>"
const startOfYesterday = new Date(), endOfYesterday = new Date()
startOfYesterday.setDate(new Date().getDate() - 1)
startOfYesterday.setHours(0)
startOfYesterday.setMinutes(0)
startOfYesterday.setSeconds(0)
endOfYesterday.setDate(new Date().getDate() - 1)
endOfYesterday.setHours(23)
endOfYesterday.setMinutes(59)
endOfYesterday.setSeconds(59)
let endpoint = `data_api/v1/messages?created_since=${startOfYesterday.toISOString()}&created_to=${endOfYesterday.toISOString()}`
while (endpoint) {
const res = await fetch(`https://<YOUR-BOT-HANDLE>.ada.support/${endpoint}`,
{
headers: {
Authorization: `Bearer ${API_KEY}`
}
}
)
const json = await res.json()
saveToDatabase(json.data)
endpoint = json.next_page_uri
}
}
from datetime import timedelta, date
from requests import get
def fetch_messages():
API_KEY = "<YOUR-API-KEY>"
yesterday = date.today() - timedelta(days=1)
headers = {"Authorization": f"Bearer {API_KEY}"}
endpoint = f"data_api/v1/messages?created_since={yesterday}T00:00:00&created_to={yesterday}T23:59:59"
while endpoint:
res = get(f"https://<YOUR-BOT-HANDLE>.ada.support/{endpoint}", headers=headers)
json = res.json()
save_to_database(json["data"])
endpoint = json["next_page_uri"]
Replace
<YOUR-BOT-HANDLE>
with your own bot handle, and<YOUR-API-KEY>
with the key generated previously.