Retrieve all projects in express


#1

I am trying to retrieve all projects in express, and this is my code.
var Asana = require(‘asana’);
var client = Asana.Client.create({
clientId: ,
clientSecret:
,
redirectUri: ‘http://localhost:8000
}).useAccessToken(’*****’);
console.log(client.projects);

When I print client.projects, it only shows
Projects {
dispatcher:
Dispatcher {
authenticator: OauthAuthenticator { credentials: [Object], flow: null, app: undefined },
asanaBaseUrl: ‘https://app.asana.com/’,
retryOnRateLimit: false,
handleUnauthorized: [Function],
_cachedVersionInfo: null,
requestTimeout: null } }

So how can i retrieve all the projects? Thanks.
If possible, please show me any related information, thanks a lot!


#2

Your authentication process went smoothly and Asana sent the user back to your app with a token?


#3

Hi Bastien, thanks for your reply. Do you mean this?
when i try this code:
client.users.me().then(function (user) {
console.log(user);
})
I can get the user id, email, name, photo, and workspaces after print the “user”.
And I need to retrieve all the projects from this workspace. What kinds of syntax I can use? And where can I check those syntax from documentation? I have read the github code(https://github.com/Asana/node-asana) but I didn’t see it.
Thanks.


#4

Hey @Jiahao_Yu,

Thanks for reaching out. To get all projects you use the function findAll(), which requires at least one param (e.g. workplace, team, archived).

Here’s an example of getting all projects in a workspace using the Node client library:

client.projects.findAll({"workspace":123456789})
	.then(function(response) {
 		console.log(response);
 	})

You can find the code to get all projects on line 160 of projects.js in the Asana Node client library.

Cheers!
Jeff


#5

@Jeff_Schneider Thank you very much! That’s what I need!


#6

@Jeff_Schneider Hi Jeff, I have one more question about this.
I am trying to retrieve one specific project, after read the documentation, I try this code:
client.projects.findById({ “project”: 12345678}).then(function (response) {
console.log(response);
})
but it doesn’t work.
In the documentation,
Projects.prototype.findById = function(
project,
params,
dispatchOptions
) {
var path = util.format(’/projects/%s’, project);

return this.dispatchGet(path, params, dispatchOptions);
};
How can i make the correct format of the params? Thanks a lot.


#7

Hey @Jiahao_Yu,

You just need to pass the project_id as a param:

client.projects.findById(123456789)
	.then(function(response) {
		console.log(response);
	})