I want to create a task inside a section of a project.
Therefore I need a few things:
A way to get the id of the section
I can’t find it on the UI (projectIds and taskIds for example can be seen in the URL)
There is an endpoint to get sections of a project and the java lib example seems to support this see Get sections in a project
Unfortunately my com.asana.Client doesn’t seem to have a sections member see [1] (using the latest java release 10.1)
A way to assign a task to a section
Creating a task in a section as described here developers.asana.com/docs/add-task-to-section has the same problem for me - I don’t seem to have the sections member in the Client …
The client libraries don’t get nearly as much love as they deserve. I’m surprised this is the first I’ve heard that sections are missing, and I now see an issue back in March on the github that I must have missed as well.
That being said, I went ahead and added it to the Java client. It’ll be on the next deploy which should go out either later today or tomorrow (depends how fast maven is).
If you need a fix before then, you could create a new instance of the resources.Sections class and go from there, or manually send a request.
Point 1:
I updated to the lates java client 10.3 and can now see the methods to create and fetch sections over the api → this solves that part
Point 2:
I don’t see a way to create a task in a section directly with the java library in contrast to some forum posts showing how to do this with the the rest interface see here or here.
Strangely enough I could not find this in the REST documentation for the task creation here.
So I only see the 2 step option to create the task in a project and then in a second step assign it to a project see here.
Is there a better way or do I have to make these 2 calls?
Hey @Ross_Grambo
My second point is purely about the java client support for doing it - not REST only
Even though it seems the REST interface lacks the documentation for what you just wrote.
The pure REST call works for me when doing it with a tool/CURL.
After a bit of trying I also got your java example to work but is a bit of a hack (modifications see [2])
Regarding your comment to make it less hacky - I would not know how to use the Membership class to full full the REST interface with the current java-client-lib - do you have an example for this aswell ^^
I tried:
A nearly empty Membership entity (just gid of project and section set)
Constructing a full Membership entity (failed as I don’t know how to create a Task with the section data see [1]
[1]
public static class Membership {
public Project project;
public Task section;
}
[2]
The memArray should be a list as the expected JSON is that memberships is a list of object
HashMap<String, String> memberships = new HashMap<String, String>();
memberships.put("project", "1234");
memberships.put("section", "12345");
List<Object> memArray = new ArrayList<>()
memArray.add(memberships)
Task t = client.tasks.createTask()
.data("name", "java test")
.data("projects", "1234")
.data("memberships", memArray)
.execute();