【问题标题】:Asana API - GET all Attachments in a Workspace (+ the view_url param)Asana API - 获取工作区中的所有附件(+ view_url 参数)
【发布时间】:2019-02-28 12:06:55
【问题描述】:

我想知道是否有办法获取 Asana 工作区的所有附件 view_url。我工作的公司正在检查他们的 Asana 附件,以确保应该保存在正确文件存储(即 Google Drive)中的所有内容都不会在完成的 Asana 任务中丢失。

我一直在参考 Asana API 文档,但这似乎不是特别常见的东西 - 我希望这不是不可能的(或者,非常耗时)。

我一直通过 cURL 访问 API,这对于简单的调用很有用,但我发现它对于详细的请求有点限制。

节点包装器使某些调用更容易(例如,根据受让人检索所有任务);但在附件方面有相当大的限制。

我一直在尝试进行概念验证,但运气不佳。

目前节点实现如下:

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)
})

这会反馈我一直在运行的一组 taskId:

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)
    }) 
})

【问题讨论】:

    标签: node.js asana asana-api


    【解决方案1】:

    想通了 - 做了很多我在上面发布的迭代中不需要做的事情。最终,仍然需要手动完成一些工作——但没有什么特别耗时的。这是有效的:

    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)
    })
    

    【讨论】:

      猜你喜欢
      • 2023-03-30
      • 2023-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-15
      • 1970-01-01
      • 2012-05-06
      • 2016-10-04
      相关资源
      最近更新 更多