Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client.attachments.createAttachmentForTask is not a function #220

Open
shi-yan opened this issue Dec 4, 2020 · 4 comments
Open

client.attachments.createAttachmentForTask is not a function #220

shi-yan opened this issue Dec 4, 2020 · 4 comments

Comments

@shi-yan
Copy link

shi-yan commented Dec 4, 2020

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)
@rossgrambo-zz
Copy link
Contributor

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 #4 )

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

@GioSensation
Copy link

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

@Naeem775
Copy link

@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

@DaveMadden
Copy link

DaveMadden commented Apr 26, 2022

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

5 participants