Please read this before posting
- Try out the AI technical support chatbot
by selecting the Ask AI button in our API documentation. It may help you quickly find relevant answers and resources related to your questions.
- If you’re seeking help with an API error, include the error from the JSON response (not the error your code raised) and describe the requests that triggered it.
- Do not share API credentials. Ensure your code doesn’t include real OAuth tokens or personal access tokens, and revoke any exposed credentials immediately via the developer console.
Hello I am getting the above error when adding a task to Asana, and also when then moving this task to a new section. I’ll also get this error when adding attachments to Asana through the API from time to time.
I’m using node.js v3.
See code below, can anyone explain what’s going on? These are not complex objects there are no circular references, just a few simple fields to make a task and update to a section
let tasksApiInstance = new asana2.TasksApi()
let task_id
let task_details = {
'name': ‘Some String’,
'projects': \[‘Some string’\]
}
await tasksApiInstance.createTask({'data': task_details})
.then((result) => {
task_id = result.data.gid
})
let body_request = {
‘data’ : {
‘ task’ : task_id
}
}
let sectionsApiInstance = new asana2.SectionsApi()
await sectionsApiInstance.addTaskForSection('1204322058065832', {'body': body_request})
The first thing would be to pin down in which part of the script this is happening. If you just do the createTask call and stop there, do you get the error? (I’m guessing not but let’s not guess.
)
And, does the task get created properly?
Yes, even if I isolate to just createTask I get this error
What exactly are you putting here?
'projects': \[‘Some string’\]
Sorry I didn’t intend for that to get marked up. Just initializing an array with a single string element, which is the ID of the project I’m adding the task to
‘projects’ = [‘1204321012349547’]
That looks right to me.
@dbrdak @Mikhail_Melikhov any ideas here?
I’ll also add, that when I create the task_details object through a function, then pass this to the ‘createTask’ method, it will work. If I declare the object as a literal, then I get this BSON error.
Hi there,
I’m a Developer Support Engineer at Asana and I’ve been investigating this for you.
I ran the exact logic you shared and the code worked perfectly on my end. The task was created and moved without any errors. You can see the working version of the code I used below:
import * as Asana from 'asana';
let client = new Asana.ApiClient();
let token = client.authentications['token'];
token.accessToken = '';
let tasksApiInstance = new Asana.TasksApi(client)
let task_id
let task_details = {
'name': 'Some String 5',
'projects': ['1234567890']
}
await tasksApiInstance.createTask({'data': task_details})
.then((result) => {
task_id = result.data.gid
})
let body_request = {
'data' : {
'task' : task_id
}
}
let sectionsApiInstance = new Asana.SectionsApi(client)
await sectionsApiInstance.addTaskForSection('0123456789', {'body': body_request})
Since I cannot replicate the crash, I have two main theories for what might be happening in your environment:
-
The “Smart Quotes” Issue
In your original post, your code uses “curly” or “smart” quotes (‘ and ’) rather than standard programming quotes ('). Ensure you are using standard straight quotes throughout.
-
Is the data coming from a BSON/MongoDB source?
Are the values you are putting into task_details (like the project GIDs or names) coming directly from a database like MongoDB?
1 Like