JavaScript

Installation

For use in the Node server-side JavaScript runtime, you can install with npm:

npm install asana
npm install [email protected]

Consider migrating to Node v3 if you're currently using v1 of the SDK.

Browser

You may also use our library directly in the browser (i.e., rather than in a Node environment). Visit the Releases page to download the latest full or minified JS bundle, then include the following script in your web page:

<script src="asana-min.js"></script>

Hello world

In this brief tutorial, we'll build a GET request to /users/me using the Node client library.

To get started, be sure that you have installed the library (npm install asana). You may also follow the detailed installation instructions on the GitHub page for the Node client library. Then, once the library is installed:

  1. Copy the example code below:
// Import the library
const Asana = require('asana');

// Configure client with personal access token
let client = Asana.ApiClient.instance;
let token = client.authentications['token'];
token.accessToken =  '0/123456789....';

// Construct resource API Instance
let usersApiInstance = new Asana.UsersApi();
let user_gid = "me";
let opts = {};

// Get your user info
usersApiInstance.getUser(user_gid, opts).then((result) => {
    console.log('Hello world! ' + 'My name is ' + result.data.name + '!');
}, (error) => {
    console.error(error.response.body);
});

// This sample code utilizes node-asana v1.0.5 -> npm install [email protected]

// Import the library
var asana = require('asana');

// Note: Replace this value with your own personal access token
var personalAccessToken = '0/123456789....';

// Construct an Asana client
var client = asana.Client.create().useAccessToken(personalAccessToken);

// Get your user info
client.users.getUser("me")
  .then(function(me) {
    // Print out your information
    console.log('Hello world! ' + 'My name is ' + me.name + '!');
});
  1. Open a text editor and save this code in a file (i.e., a descriptive file name such as hello_world.js).

  2. Run this script in your console by passing it as an argument to the Node interpreter: node hello_world.js. You must execute this command in the same directory as the file.

  3. You should see the response outputted to the console.

You can see a variant of this script, and other useful Asana API scripts, in our open-source devrel-examples.


GitHub

You can access the library's source code on GitHub.

All of the built-in functions can be found in the /gen folder of the client library.

OAuth

See this page for examples of using OAuth with the Node SDK.


Asana Home
Asana helps you manage projects, focus on what's important, and organize work in one place for seamless collaboration.
© 2023 Asana, Inc.