Batch API dependency API


#1

I have one question in Batch API concept in asana. Any one use dependency in batch api calls. if any one use it or know it please explain how to use dependency in asana api


#2

I’d be happy to help but I am not sure what type of dependency you are talking about? Perhaps you could post some code so we can take a look at it.


#3

Hey @Palpandi_A,

check the work with dependencies at the API documentation.

You can use the relative path at the batch api to the following:

POST    /tasks/task-id/addDependencies

and set the field dependencies as an array with the task ids that are dependent to this task.

Hope I helped.


#4

HI @Vaidotas_Piekus,
Thanks for your response. Batch API concept is explain in https://asana.com/developers/documentation/getting-started/batch-api. In this concept, the example request contain many API calls rest in single call that is :
“data” : { … }.

Consider this single request,
{
“data”: {
“actions”: [
{
“method”: “get”,
“relative_path”: “/users/me”
}]
}

This give response of id, name, workspace, email, etc in the json format of { “data” : [ “body” : { “data” : { … } } ] }.
In this api call,
{
“method”: “get”,
“relative_path”: “/tasks”,
“data”: {
“assignee”: “me”,
“workspace”: 786257081329158
},
“options”: {
“limit”: 3,
“fields”: [
“name”
]
}
}

workspace is present in this call.

My doubt is,
{
“data”: {
“actions”: [
{
“method”: “get”,
“relative_path”: “/users/me”
},
{
“method”: “get”,
“relative_path”: “/tasks”,
“data”: {
“assignee”: “me”,
“workspace”: $.data.body.data[0].id
},
“options”: {
“limit”: 3,
“fields”: [
“name”
]
}
}]
}

I take first api call workspace output is input of second api call through JSON path concept. ie) second api call depend on first api call right.
I try this but it is not working. I think i explain my doubt clearly please help me.


#5

As far as I can see from the documentation is not possible to set a dynamic field at your request because you get the ‘created’ ids at the response.

But it’s a really interesting feature. Maybe @Joe_Trollo can give us an undocumented insight.


#6

@Palpandi_A, you can’t do what you’re trying to do using the Batch API, because among other things the order of requests is not guaranteed, as the Batch API executes them in parallel as the documentation states:

This happens in parallel, so all actions in the request will be processed simultaneously. There is no guarantee of the execution order for these actions, nor is there a way to use the output of one action as the input of another action


#7

@Phil_Seeman is correct: the batch API is parallel by design, and so cannot have one action depend on the output of another.


#8

@Phil_Seeman, @Joe_Trollo thank you for your response. It’s very helpful to me.