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"}]}
私を助けてください!