2017-06-02 89 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'