2017-06-02 85 views
0

我正在尝试使用Asana API,因为我学习了React和Redux。我已经能够使用fetch()从Asana API获取数据了,但我无法发布任务。使用提取发布Asana任务

这里是我使用的代码:

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

在控制台中,我看到这说明我送进入我的身体的JSON的执行console.log回报关键:

{"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

的错误信息是:

​​

它似乎并不无论什么领域包括我的身体(包括一个项目导致了相同的错误),这让我怀疑还有其他事情正在进行中,Asana API没有掌握正确的身体,或者无法解释它如何设置。

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

回答

1

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

我也通过projects作为重点,并在身体的字符串值。

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