2013-02-26 64 views
1

我可以使用Asana API(JAVA)在Asana中創建任務。如何在Asana中創建新的工作區?

import org.apache.commons.httpclient.HttpClient; 
    import org.apache.commons.httpclient.UsernamePasswordCredentials; 
    import org.apache.commons.httpclient.auth.AuthScope; 
    import org.apache.commons.httpclient.methods.PostMethod; 
    import org.apache.commons.httpclient.methods.PutMethod; 

    import java.io.BufferedReader; 
    import java.io.InputStreamReader; 

    class Main { 
     public static void main(String[] args) { 
      String data = "{" + 
        " \"data\": {" + 
        "  \"workspace\": 4210637464884," + 
        "  \"name\": \"Task 2 this is it\"," + 
        "  \"notes\": \"NOTES_ABOUT_TASK_GO_HERE\"," + 
        "  \"assignee\": \"[email protected]\"" + 
        " }," + 
        " \"options\": {" + 
        "  \"fields\": \"name\"" + 
        " }" + 
        "}"; 

      HttpClient client = new HttpClient(); 
      client.getParams().setAuthenticationPreemptive(true); 
      client.getParams().setParameter("http.useragent", "Test Client"); 
      client.getState().setCredentials(
        new AuthScope("app.asana.com", 443, "realm"), 
        new UsernamePasswordCredentials("<APIKEY>", "") 
      ); 

      BufferedReader br = null; 
      PostMethod method = new PostMethod("https://app.asana.com/api/1.0/tasks"); 
      method.setDoAuthentication(true); 

      try { 
       method.setRequestBody(data); 
       int returnCode = client.executeMethod(method); 
       System.out.println("Return code: " + returnCode); 
       br = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream())); 
       String readLine; 
       while (((readLine = br.readLine()) != null)) { 
        System.out.println(readLine); 
       } 
      } catch (Exception e) { 
       System.out.println(e.getMessage()); 
      } finally { 
       method.releaseConnection(); 
       if (br != null) try { 
        br.close(); 
       } catch (Exception fe) { 
        System.err.println(fe); 
       } 
      } 
      createNewWorkSpace(); 

     } 
    } 

它工作正常。 現在我想創建一個工作區。怎麼樣? 我試圖用

PutMethod method = new PutMethod("https://app.asana.com/api/1.0/workspaces"); 
String data = "{" + 
      " \"data\": {" + 
      " \"id\": 1234," + 
      " \"name\": \"Everyone's Favorite Workspace\"" + 
      " }}"; 

我也得到 返回代碼:404 { 「錯誤」:[{ 「消息」: 「對於要求不匹配路由」}]}

請幫幫我!

回答

0

Asana API不支持創建新的工作區。 目前它只支持「特定的,現有的工作空間」的更新,甚至這僅限於更新工作空間的名稱。

按照體位API文檔:https://asana.com/developers/api-reference/workspaces

PS我編輯從崗位以防萬一它實際上是你真正的API密鑰您的API密鑰!

+0

Upvote(歸零!),因爲這仍然是真實的 – 2016-06-06 15:29:10

相關問題