node-asana icon indicating copy to clipboard operation
node-asana copied to clipboard

client.attachments.createAttachmentForTask is not a function

Open shi-yan opened this issue 4 years ago • 4 comments

followed

https://developers.asana.com/docs/upload-an-attachment

      client.attachments.createAttachmentForTask(gid, {file: '/home/shiy/Downloads/test.png'})
      .then((result) => {
        console.log(result);
      });

got


Unhandled rejection TypeError: client.attachments.createAttachmentForTask is not a function
    at client.tasks.createTask.then (/home/shiy/autocatlabeller/inbase/inject.js:70:26)
    at tryCatcher (/home/shiy/autocatlabeller/inbase/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/home/shiy/autocatlabeller/inbase/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (/home/shiy/autocatlabeller/inbase/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromise0 (/home/shiy/autocatlabeller/inbase/node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (/home/shiy/autocatlabeller/inbase/node_modules/bluebird/js/release/promise.js:729:18)
    at _drainQueueStep (/home/shiy/autocatlabeller/inbase/node_modules/bluebird/js/release/async.js:93:12)
    at _drainQueue (/home/shiy/autocatlabeller/inbase/node_modules/bluebird/js/release/async.js:86:9)
    at Async._drainQueues (/home/shiy/autocatlabeller/inbase/node_modules/bluebird/js/release/async.js:102:5)
    at Immediate.Async.drainQueues [as _onImmediate] (/home/shiy/autocatlabeller/inbase/node_modules/bluebird/js/release/async.js:15:14)
    at runCallback (timers.js:705:18)
    at tryOnImmediate (timers.js:676:5)
    at processImmediate (timers.js:658:5)
    at process.topLevelDomainCallback (domain.js:126:23)

shi-yan avatar Dec 04 '20 20:12 shi-yan

Hello @shi-yan !

I'm the person to blame for that. Basically, we generate those samples from our OpenAPI spec, but the auto-generation for creating attachments is not correct (as it has to be a special case for each client library).

You'll likely want to use something like:

var params = {
    method: 'POST',
    url: "https://app.asana.com/api/1.0/tasks/1234567890/attachments",
    formData: {
        file: fs.createReadStream('test.png')
    },
    headers: {
        "Content-Type": "multipart/form-data"
    },
};
client.dispatcher.dispatch(params, {});

( Stolen from https://github.com/Asana/node-asana/issues/4 )

Let me know if you still have any issues, and I'll take note that I need to update the docs!

rossgrambo-zz avatar Dec 04 '20 21:12 rossgrambo-zz

Thanks, the suggested workaround did it. The docs still suggest client.attachments.createAttachmentForTask, isn't there an official API for this?

GioSensation avatar Oct 15 '21 10:10 GioSensation

@rossgrambo-zz hi, is there a way i can attach two files? i only can one and if i try to attach two files it only attach one and ignore the other one, i would appreciate any help, thank you

Naeem775 avatar Feb 14 '22 15:02 Naeem775

@rossgrambo-zz FYI the docs STILL say this.

It also seems that there is no dispatcher.dispatch on the asana client.

It also appears that Asana's published Postman workspace has the wrong form for this to work

DaveMadden avatar Apr 26 '22 23:04 DaveMadden