我可以使用 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"}]}
请帮我!