Good afternoon, I don’t quite understand why I can’t add a task using the NodeJS asana library.
I reread the documentation several times, but still didn’t understand:(
Here is my code:
require('dotenv').config();
const asana = require('asana');
const client = asana.Client.create().useAccessToken(process.env.PERSONAL_ACCESS_TOKEN);
client.users.me()
.then(async (user) => {
const userId = user.gid;
const workspaceId = user.workspaces[0].gid;
const tableInfo = await client.tasks.findAll({
assignee: userId,
workspace: workspaceId,
})
return [tableInfo , userId];
})
.then(gid => client.tasks.createTask({
assignee: gid[1],
assignee_section: gid[0].data[0].gid,
name: "test",
}).then((result) => {
console.log(result);
})
)
My console outputs:
REQUEST {
method: 'GET',
url: 'https://app.asana.com/api/1.0/users/me',
json: true,
headers: {
Authorization: 'Bearer 1/1201953775449875:42e97f469fb33522b377bf4cea619843',
'X-Asana-Client-Lib': 'version=0.18.6&language=NodeJS&language_version=v16.13.1&os=win32'
},
callback: [Function (anonymous)]
}
REQUEST make request https://app.asana.com/api/1.0/users/me
REQUEST onRequestResponse https://app.asana.com/api/1.0/users/me 200 {
date: 'Fri, 11 Mar 2022 13:19:48 GMT',
'content-type': 'application/json; charset=UTF-8',
'content-length': '208',
connection: 'close',
server: 'nginx',
'x-frame-options': 'DENY',
'x-xss-protection': '1; mode=block',
'x-content-type-options': 'nosniff',
'content-security-policy': "report-uri https://app.asana.com/-/csp_report?report_only=false;default-src 'none';frame-src 'none';frame-ancestors 'none'",
'x-asana-api-version': '1.1',
'asana-change': 'name=new_user_task_lists;info=https://forum.asana.com/t/update-on-our-planned-api-changes-to-user-task-lists-a-k-a-my-tasks/103828',
'x-robots-tag': 'none',
'strict-transport-security': 'max-age=31536000; includeSubDomains',
'datacenter-time-end': '1647004788.025',
'x-loadbalancer': 'prod-lb007.ec2'
}
REQUEST reading response's body
REQUEST finish init function https://app.asana.com/api/1.0/users/me
REQUEST response end https://app.asana.com/api/1.0/users/me 200 {
date: 'Fri, 11 Mar 2022 13:19:48 GMT',
'content-type': 'application/json; charset=UTF-8',
'content-length': '208',
connection: 'close',
server: 'nginx',
'x-frame-options': 'DENY',
'x-xss-protection': '1; mode=block',
'x-content-type-options': 'nosniff',
'content-security-policy': "report-uri https://app.asana.com/-/csp_report?report_only=false;default-src 'none';frame-src 'none';frame-ancestors 'none'",
'x-asana-api-version': '1.1',
'asana-change': 'name=new_user_task_lists;info=https://forum.asana.com/t/update-on-our-planned-api-changes-to-user-task-lists-a-k-a-my-tasks/103828',
'x-robots-tag': 'none',
'strict-transport-security': 'max-age=31536000; includeSubDomains',
'datacenter-time-end': '1647004788.025',
'x-loadbalancer': 'prod-lb007.ec2'
}
REQUEST end event https://app.asana.com/api/1.0/users/me
REQUEST has body https://app.asana.com/api/1.0/users/me 208
REQUEST emitting complete https://app.asana.com/api/1.0/users/me
REQUEST {
method: 'GET',
url: 'https://app.asana.com/api/1.0/tasks',
json: true,
qs: {
assignee: '1201953775449875',
workspace: '1201953859870712',
limit: 50
},
headers: {
Authorization: 'Bearer 1/1201953775449875:42e97f469fb33522b377bf4cea619843',
'X-Asana-Client-Lib': 'version=0.18.6&language=NodeJS&language_version=v16.13.1&os=win32'
},
callback: [Function (anonymous)]
}
REQUEST make request https://app.asana.com/api/1.0/tasks?assignee=1201953775449875&workspace=1201953859870712&limit=50
REQUEST onRequestResponse https://app.asana.com/api/1.0/tasks?assignee=1201953775449875&workspace=1201953859870712&limit=50 200 {
date: 'Fri, 11 Mar 2022 13:19:49 GMT',
'content-type': 'application/json; charset=UTF-8',
'content-length': '92',
connection: 'close',
server: 'nginx',
'x-frame-options': 'DENY',
'x-xss-protection': '1; mode=block',
'x-content-type-options': 'nosniff',
'content-security-policy': "report-uri https://app.asana.com/-/csp_report?report_only=false;default-src 'none';frame-src 'none';frame-ancestors 'none'",
'x-asana-api-version': '1.1',
'asana-change': 'name=new_user_task_lists;info=https://forum.asana.com/t/update-on-our-planned-api-changes-to-user-task-lists-a-k-a-my-tasks/103828',
'x-robots-tag': 'none',
'strict-transport-security': 'max-age=31536000; includeSubDomains',
'datacenter-time-end': '1647004789.118',
'x-loadbalancer': 'prod-lb002.ec2'
}
REQUEST reading response's body
REQUEST finish init function https://app.asana.com/api/1.0/tasks?assignee=1201953775449875&workspace=1201953859870712&limit=50
REQUEST response end https://app.asana.com/api/1.0/tasks?assignee=1201953775449875&workspace=1201953859870712&limit=50 200 {
date: 'Fri, 11 Mar 2022 13:19:49 GMT',
'content-type': 'application/json; charset=UTF-8',
'content-length': '92',
connection: 'close',
server: 'nginx',
'x-frame-options': 'DENY',
'x-xss-protection': '1; mode=block',
'x-content-type-options': 'nosniff',
'content-security-policy': "report-uri https://app.asana.com/-/csp_report?report_only=false;default-src 'none';frame-src 'none';frame-ancestors 'none'",
'x-asana-api-version': '1.1',
'asana-change': 'name=new_user_task_lists;info=https://forum.asana.com/t/update-on-our-planned-api-changes-to-user-task-lists-a-k-a-my-tasks/103828',
'x-robots-tag': 'none',
'strict-transport-security': 'max-age=31536000; includeSubDomains',
'datacenter-time-end': '1647004789.118',
'x-loadbalancer': 'prod-lb002.ec2'
}
REQUEST end event https://app.asana.com/api/1.0/tasks?assignee=1201953775449875&workspace=1201953859870712&limit=50
REQUEST has body https://app.asana.com/api/1.0/tasks?assignee=1201953775449875&workspace=1201953859870712&limit=50 92
REQUEST emitting complete https://app.asana.com/api/1.0/tasks?assignee=1201953775449875&workspace=1201953859870712&limit=50
REQUEST {
method: 'POST',
url: 'https://app.asana.com/api/1.0/tasks',
json: {
data: {
assignee: '1201953775449875',
assignee_section: '1201954197211652',
name: 'test'
}
},
qs: {},
headers: {
Authorization: 'Bearer 1/1201953775449875:42e97f469fb33522b377bf4cea619843',
'X-Asana-Client-Lib': 'version=0.18.6&language=NodeJS&language_version=v16.13.1&os=win32'
},
callback: [Function (anonymous)]
}
REQUEST make request https://app.asana.com/api/1.0/tasks
REQUEST onRequestResponse https://app.asana.com/api/1.0/tasks 400 {
date: 'Fri, 11 Mar 2022 13:19:49 GMT',
'content-type': 'application/json; charset=UTF-8',
'content-length': '245',
connection: 'close',
server: 'nginx',
'x-frame-options': 'DENY',
'x-xss-protection': '1; mode=block',
'x-content-type-options': 'nosniff',
'content-security-policy': "report-uri https://app.asana.com/-/csp_report?report_only=false;default-src 'none';frame-src 'none';frame-ancestors 'none'",
'x-asana-api-version': '1.0',
'asana-change': 'name=new_user_task_lists;info=https://forum.asana.com/t/update-on-our-planned-api-changes-to-user-task-lists-a-k-a-my-tasks/103828',
'x-robots-tag': 'none'
}
REQUEST reading response's body
REQUEST finish init function https://app.asana.com/api/1.0/tasks
REQUEST response end https://app.asana.com/api/1.0/tasks 400 {
date: 'Fri, 11 Mar 2022 13:19:49 GMT',
'content-type': 'application/json; charset=UTF-8',
'content-length': '245',
connection: 'close',
server: 'nginx',
'x-frame-options': 'DENY',
'x-xss-protection': '1; mode=block',
'x-content-type-options': 'nosniff',
'content-security-policy': "report-uri https://app.asana.com/-/csp_report?report_only=false;default-src 'none';frame-src 'none';frame-ancestors 'none'",
'x-asana-api-version': '1.0',
'asana-change': 'name=new_user_task_lists;info=https://forum.asana.com/t/update-on-our-planned-api-changes-to-user-task-lists-a-k-a-my-tasks/103828',
'x-robots-tag': 'none'
}
REQUEST end event https://app.asana.com/api/1.0/tasks
REQUEST has body https://app.asana.com/api/1.0/tasks 245
REQUEST emitting complete https://app.asana.com/api/1.0/tasks
Unhandled rejection Error: Invalid Request
at InvalidRequest.AsanaError (C:\Users\grema\Desktop\code\node_modules\asana\lib\errors\error.js:4:11)
at new InvalidRequest (C:\Users\grema\Desktop\code\node_modules\asana\lib\errors\invalid_request.js:5:14)
at Request._callback (C:\Users\grema\Desktop\code\node_modules\asana\lib\dispatcher.js:263:23)
at Request.self.callback (C:\Users\grema\Desktop\code\node_modules\request\request.js:185:22)
at Request.emit (node:events:390:28)
at Request.<anonymous> (C:\Users\grema\Desktop\code\node_modules\request\request.js:1154:10)
at Request.emit (node:events:390:28)
at IncomingMessage.<anonymous> (C:\Users\grema\Desktop\code\node_modules\request\request.js:1076:12)
at Object.onceWrapper (node:events:509:28)
at IncomingMessage.emit (node:events:402:35)
at endReadableNT (node:internal/streams/readable:1343:12)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
Please help me.