1

我可以使用 Asana API (JAVA) 在 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\": \"ykhonskiy@gmail.com\"" +
                    "   }," +
                    "    \"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\"" +
            "  }}";

我得到 Return code: 404 {"errors":[{"message":"No matching route for request"}]}

请帮我!

4

1 回答 1

0

Asana API 不支持创建新工作区。目前它只支持更新“特定的、现有的工作空间”,甚至这仅限于更新工作空间的名称。

根据 Asana API 文档:https ://asana.com/developers/api-reference/workspaces

PS 我从帖子中编辑了您的 API 密钥,以防万一它实际上是您真正的 API 密钥!

于 2013-02-28T14:07:59.860 回答