I'm trying to build a JSON file by making successive HTTP requests with Axios:
JSON file out of the modified projects arrayCode:
let getProjects = function() {
try {
return axios.get('https://app.asana.com/api/1.0/projects/')
} catch (error) {
console.error(error)
}
}
let getTasks = function(project) {
try {
return axios.get('https://app.asana.com/api/1.0/projects/'+project+'/tasks')
} catch (error) {
console.error(error)
}
}
let getAttachments = function(task) {
try {
return axios.get('https://app.asana.com/api/1.0/tasks/'+task+'/attachments')
} catch (error) {
console.error(error)
}
}
async function getAsanaData() {
let projects = await getProjects()
return Promise.all(projects.data.data.map(async (project) => {
project.attachments = []
let tasks = await getTasks(project.gid)
return Promise.all(tasks.data.data.map(async (task) => {
let attachments = await getAttachments(task.gid)
project.attachments = !!attachments ? project.attachments.concat(attachments.data.data) : project.attachments
return project
}))
}))
}
getAsanaData()
.then((projects) => {
var asanaData = safeJsonStringify(projects);
fs.writeFile("thing.json", asanaData);
})
.catch(err=>console.log(err))
But I'm running into this error:
status: 429,
statusText: 'Too Many Requests
I haven't found anything helpful yet for figuring out how to resolve it. What can I do?
You're getting throttled by Asana for sending too many requests and reaching the maximum rate.
When it happens, you need to check for the Retry-After response header and wait for the specified amount of time before sending another request.
https://asana.com/developers/documentation/getting-started/rate-limits
You can also learn more in the RFC 6585 about HTTP 429
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With