Getting started

The following example demonstrates how to use the Data Export API to retrieve messages from a specific time range. In this case, the code fetches all messages from the previous day, handling pagination until all data is retrieved.

The sample code is provided in both JavaScript and Python to help you get started quickly.

Replace placeholders like <YOUR-BOT-HANDLE> and <YOUR-API-KEY> with your own credentials to begin fetching data.

Fetch All Messages from the Previous Day

1import fetch from "node-fetch"
2
3async function fetchMessages() {
4 const API_KEY = "<YOUR-API-KEY>"
5
6 const startOfYesterday = new Date(), endOfYesterday = new Date()
7
8 startOfYesterday.setDate(new Date().getDate() - 1)
9 startOfYesterday.setHours(0)
10 startOfYesterday.setMinutes(0)
11 startOfYesterday.setSeconds(0)
12
13 endOfYesterday.setDate(new Date().getDate() - 1)
14 endOfYesterday.setHours(23)
15 endOfYesterday.setMinutes(59)
16 endOfYesterday.setSeconds(59)
17
18
19 let endpoint = `data_api/v1/messages?created_since=${startOfYesterday.toISOString()}&created_to=${endOfYesterday.toISOString()}`
20
21 while (endpoint) {
22 const res = await fetch(`https://<YOUR-BOT-HANDLE>.ada.support/${endpoint}`,
23 {
24 headers: {
25 Authorization: `Bearer ${API_KEY}`
26 }
27 }
28 )
29
30 const json = await res.json()
31 saveToDatabase(json.data)
32 endpoint = json.next_page_uri
33 }
34}