我可以使用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\"" +
" }}";
我明白了 返回码:404 {“errors”:[{“message”:“没有匹配的请求路线”}}}
拜托,帮助我!
答案 0 :(得分:0)
Asana API不支持创建新工作区。 目前它只支持更新“特定的,现有的工作区”,甚至这仅限于更新工作区的名称。
根据Asana API文档:https://asana.com/developers/api-reference/workspaces
PS我从帖子中编辑了你的API密钥,以防它实际上是你真正的API密钥!