繁体   English   中英

使用获取发布Asana任务

[英]Posting an Asana task using fetch

我在学习React和Redux时尝试使用Asana API。 到目前为止,我已经可以使用fetch()从Asana API中获取数据,但是我在发布任务时遇到了麻烦。

这是我正在使用的代码:

 const options = (type, data) => { const defaultHeaders = { 'Authorization': `Bearer ${apiKey}`, 'Asana-Fast-Api': 'true', } switch(type) { case 'get': return { headers: defaultHeaders, } case 'post': const body = JSON.stringify(data) console.log(body); return { method: 'POST', headers: defaultHeaders, contentType: 'application/json', body: body, } default: return { headers: defaultHeaders, } } }; const asanaUrl = (props) => { const numOfProps = props.length; switch (numOfProps) { case 3: return `https://app.asana.com/api/1.0/${props[0]}/${props[1]}?${props[2]}` case 2: return `https://app.asana.com/api/1.0/${props[0]}?${props[1]}` case 1: return `https://app.asana.com/api/1.0/${props[0]}` default: return console.log(props) } } export const asanaPost = (props, data) => { return fetch(asanaUrl(props), options('post', data)) .then(response => response.json() ) } 

在控制台中,我看到console.log的返回信息,其中显示了我要发送到我的主体密钥中的JSON:

{"assignee":22800770039251,"name":"test","notes":"test"}

和以下错误

Failed to load resource: the server responded with a status of 400 (Bad Request)

网址似乎正确: https//app.asana.com/api/1.0/tasks?workspace = 31542879721131

错误消息是:

"Must specify exactly one of project, tag, or assignee + workspace"

我在主体中包括哪些字段(包括一个项目导致相同的错误)似乎并不重要,这使我怀疑还有其他事情在发生,并且Asana API不能控制主体或不起作用。无法用我的设置方式来解释它。

感谢您帮我解决这个问题!

我使用的api网址是https://app.asana.com/api/1.0/tasks?opt_fields=html_notes

我还将projects作为键和正文中的字符串值传递。

我在标题中不使用'Asana-Fast-Api': 'true'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM