I tried the syntax listed here - Asana API (Java) - Fetching the tasks's due date - Stack Overflow
And the syntax listed here - Taks fields come as null + Java SDK
But nothing I’ve tried has allowed me to retrieve the “due_on” and “due_at” from client.tasks.getTasksForProject
Any other suggestion?
Thanks
opt_fields are definitely the way to go, do you want to share some code snippets?
I’ve tried
CollectionRequest<Task> request = client.tasks.getTasksForProject(myProject.gid, null)
.option("fields", "notes, due_on, due_at, memberships")
.option("pretty", true);
All additional fields are null.
CollectionRequest<Task> request = client.tasks.getTasksForProject(myProject.gid, null)
..option("fields", Arrays.asList("notes", "due_on", "due_at", "memberships"))
.option("pretty", true);
All additional fields are null.
I can get the information if I use curl, so I know it can work. Just can’t get it to work in Java. Here is the curl command that does work for me:
curl -X GET https://app.asana.com/api/1.0/projects/<project.gid>/tasks?
opt_fields=notes,due_on,due_at,memberships \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <token>'
I’m not sure if I’m calling it wrong from Java and it isn’t requesting the info correctly or if there’s a problem with the Java client parsing the response so it isn’t getting populated.
@Aaron_Armstrong,
I don’t know Java - I’m a C# guy - but looking at the source for the Java client, it looks like maybe the fields list should be supplied as a parameter in the method call itself?
public CollectionRequest<Task> getTasksForProject(String projectGid, String completedSince, String offset, Integer limit, List<String> optFields, Boolean optPretty) throws IOException {
String path = "/projects/{project_gid}/tasks".replace("{project_gid}", projectGid);
CollectionRequest<Task> req = new CollectionRequest<Task>(this, Task.class, path, "GET")
.query("completed_since", completedSince)
.query("opt_pretty", optPretty)
.query("opt_fields", optFields)
.query("limit", limit)
.query("offset", offset);
return req;
}
Specifically the part I bolded:
public CollectionRequest getTasksForProject(String projectGid, String completedSince, String offset, Integer limit, List<String> optFields, Boolean optPretty)
Thanks for the suggestion, but it didn’t help.
For the Java client the syntax is .data instead of .query so I tried
CollectionRequest<Task> request = client.tasks.getTasksForProject(myProject.gid, null)
.data("opt_fields", "name,notes,due_on,due_at,memberships")
And got the same null result as with the .option(“fields”,… code I pasted before.