【发布时间】:2021-05-16 12:33:08
【问题描述】:
使用Asana Task API,我们可以查看任务所属的项目列表,以及这些项目的 GID 和注释(描述文本)。
期望的结果
这里的整个目标是获取在其 Notes 值中包含 #websiteprojecttemplate 的项目的 GID。我们需要找到该项目的 GID,然后将其输出,以便稍后在 Zapier 操作中使用该 GID。
体式任务 API
使用这个 API URL,我们可以看到返回项目数据的 API 输出(包括 GID 和 Notes)。我相信这是 JSON。 https://app.asana.com/api/1.0/tasks/{id}?opt_fields=projects.notes
例如:
https://app.asana.com/api/1.0/tasks/1799885428032109?opt_fields=projects.notes 显示为:
当前代码
理想情况下,Node.js Javascript 代码将能够迭代/搜索/找到带有#websiteprojecttemplate 的代码,然后输出匹配的 GID。在这种情况下,它将是:1199916857565229
这是我目前的 JS 代码:
const res = await fetch('https://app.asana.com/api/1.0/tasks/' + inputData.uniqueID + '?opt_fields=projects.notes', {
headers: {
'Authorization': 'Bearer 0/899removedforsecurity24564s'
}
});
const body = await res.json();
const projects = body.data;
output = { id: projects };
输出类似:
"id" : {
"gid" : "1199885428032109",
"projects" : [ {
"gid" : "810573962916457",
"notes" : "CRM project to create custom fields for the CRM task"
}, {
"gid" : "881219806802782",
"notes" : "Helps keep PMs aware of what stage of progress the website projects are at; as well as how many projects each PM has (via saved Asana searches)."
}, {
"gid" : "1129624391492919",
"notes" : "Tracks the stage and progress of converting a lead to a client."
}, {
"gid" : "1140671985497468",
"notes" : "Additional CRM project to create more custom fields for the CRM task"
}, {
"gid" : "1199916857565229",
"notes" : "Created from the #websiteprojecttemplate."
} ]
}
但我需要它输出的不是整个身体的数据,而是仅输出 gid 值中的 #websiteprojecttemplate 的 notes 值。
TL;DR
我们如何更新当前代码,以便它可以遍历gid,并在notes 中找到具有#websiteprojecttemplate 的代码,并输出它的gid 编号?
【问题讨论】:
标签: javascript node.js json asana asana-api