const credentials = {
email: process.env.AMDITAL_EMAIL,
password: process.env.AMDITAL_PASSWORD,
}
const login = await fetch('https://api.amdital.com/v1/auth-next/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(credentials),
})
if (!login.ok) throw new Error(`Login failed: ${login.status}`)
const { accessToken } = await login.json()
const res = await fetch('https://api.amdital.com/api/v1/leads?limit=20', {
headers: { Authorization: `Bearer ${accessToken}` },
})
if (!res.ok) throw new Error(`Request failed: ${res.status}`)
const { docs, totalDocs } = await res.json()
console.log(totalDocs, docs.length)