setParent for task with Javascript library


#1

I read through the Javascript library documentation and did not seem to find the setParent functionality.

in that case, can anyone help with how to assign an existing task with a parent task?
The asana JS library helps out a lot and I am kind of new with coding, so I haven’t gotten into actually using the JS http curl request yet


#2

In the doc it says “The parent of this task, or null if this is not a subtask. This property cannot be modified using a PUT request but you can change it with the setParent endpoint. You can create subtasks by using the subtasks endpoint.”
Did you try to call this endpoint?


#3

only familiar with using the JS library

client.tasks.update( {task to set as subtask}, {parent task gid} )

but above is using a PUT request, and seems like it cannot be done

I did find a create subtask function with the lib using

Tasks.prototype.addSubtask = function(
task,
data,
dispatchOptions
)

but cannot find one where I can set an existing task with a parent task

and as mentioned, not too sure how to do the curl request without using the node.js library

is it something like this? or can someone point me in the right direction?

var requesst = require(‘request’)
var headers = {
‘authorization’: 'Bearer ’
};
var parent_id = {parent task gid}
var options = {
‘url’: ‘https://app.asana.com/api/1.0/tasks/{task gid}/setParent’,
‘method’:‘POST’,
‘headers’ : headers
‘data’: {“parent”: parentgid}
};

request(options).then(response => {console.log(response)}


#4

Thanks for pointing out the endpoint, think I figured it out using the node request module

needed to use the json option instead of using body

var request = require( ‘request’)
var personalAccessToken = { personal access token }
var parenttaskid = { parent task gid }
var subtaskid = { existing task gid to set as subtask }
var headers = {
‘Authorization’: 'Bearer ’ + personalAccessToken
};
var jsondata = {“data”: {‘parent’ : parenttaskid}}

var options = {
url: ‘https://app.asana.com/api/1.0/tasks/’+ subtaskid +’/setParent/’,
headers: headers,
method: ‘POST’,
json: jsondata
};

function callback(error, response, body) {

console.log(body)

}

request(options, callback);