Your solution doesn’t work for me…it is asking to open a link in the browser and enter a code in the command line. The link is broken and I can’t figure out what code it wants as input.
In your code I can’t see how you authenticate a specific user with his oauth-token.
I use following code to send the request that is failing:
In our Authentication Basics docs we say “Native or command line applications should use the special redirect URL urn:ietf:wg:oauth:2.0:oob”, which is what my script is doing. If you want it to work, go to your Developer Console in Asana and add urn:ietf:wg:oauth:2.0:oob as a redirect_url.
It appears you’re loading your refresh_token from an env_variable, which is only appropriate if your app runs for a single user. If it’s only ever going to be run for a single user, you should be using a PAT.
If this app is meant to be used for multiple people, then you should load a refresh token for each person on their first authentication.
Are you building a script that a local computer will run, a website, or a server?
I only isolated the attachment code to be sure it is not a problem of my application. In the end it should run on a nodeJS server for multiple users.
Using the client.authorize() method it always ask me for the credentials. Even i I pass them to the useOauth method. So I think your approach is not suited for my production application.
I am glad I finally have a working example with the pure request method that I can use. I just find it very confusing that I can’t make it work using your asana npm package. In the end it was causing more problems then it helped me.
I hope you and me can find the issue and your team can fix it so other people don’t have to waste hours and hours to find the problem.
it does not work with the asana-client and its dispatch method. Using an OAuth-Token the request will fail. If I’m using a personal-access-token, the asana-client will successfully upload my file.
I managed to make it work using the http service from Angular, after looking at a what a formData postman request looks like. It appears that the Asana dispatcher does not know how to handle form data request, cc @Ross_Grambo
Same problem with attachments. Is there any way to add an attachment with OAuth at all? To be honest, this problem is really confusing. And even official doc for node.js is wrong as it pointing to method createAttachmentForTask which simply does not exists.
@Bastien_Siebman I was able to get it working via axios and the REST api. Still using the node-asana client for a few endpoints, just not the file upload.