I'm wondering if there's a way to get all attachment view_urls for an Asana workspace. The company I work for is looking to do a sweep of their Asana attachments to make sure everything that should be living in a proper file store (i.e. Google Drive) isn't lost in a completed Asana task.
I've been referencing the Asana API docs, but it doesn't seem like this is something that is particularly common - and I'm hoping it's not impossible (or, prohibitively time-consuming).
I've been hitting the API via cURL, which has been good for simple calls, but I'm finding it to be a bit limiting for detailed requests.
The node wrapper has made certain calls easier (retrieving all tasks based on assignee, for instance); but has pretty significant limitations when it comes to attachments.
I've been trying to get a proof-of-concept working, but haven't had much luck.
Currently the node implementation looks like this:
let asana = require("asana")
let client =
asana.Client.create().useAccessToken('0/##########################(this
is properly populated, normally))
client.users.me()
.then(user => {
const userId = user.id;
const workspaceId = user.workspaces[0].id;
//this part works fine
return client.tasks.findAll({
workspace: workspaceId,
assignee: userId,
opt_fields: 'id,name'
});
})
.then(response => {
//this is working as expected
console.log(response.data)
//this is working as expected too...
let taskArray = response.data
taskArray.forEach(task => {
console.log(task.id)
})
return taskArray.id
}
).catch(e => {
console.log(e.value.errors)
})
That feeds back an array of taskIds that I've been then running through this:
tasks.forEach(task => {
client.attachments.findByTask(task.id)
.then(response => {
console.log(response.data)
return client.attachments.findById(response.data.id, {
// I can't seem to retrieve the urls...
opt_fields: 'view_url,download_url'
})
}).then(response => {
console.log(response.data)
})
})
Figured it out - was doing a lot of things that I didn't need to be doing in the iteration posted above. Ultimately, there was still a bit of work that had to be done manually - but nothing particularly time-consuming. Here's what worked:
client.users.me()
.then(user => {
const userId = user.id;
const workspaceId = user.workspaces[0].id;
//this part works fine
return client.tasks.findByProject(support, {
opt_fields: 'id,name'
});
})
.then(collection => {
//this is working as expected too...
let taskArray = collection.stream().on('data', task => {
console.log(task.id)
client.attachments.findByTask(task.id, {
opt_fields: 'id, view_url, download_url, permanent_url'
}).then(attachment => {
console.log(attachment.data)
return attachment.data
})
})
return taskArray.json()
}
).then(tasks => {
console.log(tasks.permanent_url)
}
).catch(e => {
console.log(e.value)
})