This IntegrationIntegration - An integration is the place the you write your code to get things done! Written in NodeJS, an integration runs in Fusebit's secure and scalable environment to translate between the needs of your backend application and the remote service or services you're connecting to. allows full access to the Asana API for cloud-hosted instances from your application. Fusebit's multi-tenant approach makes it easy for you to manage multiple Asana connections on behalf of your app's users. Our Node.js-based programming model and lightweight deployment story make it easy to customize the Integration with any necessary business logic.

Getting Started

  1. Use the Fusebit Management PortalFusebit Management Portal - The Fusebit Management Portal enables you to easily setup and manage all your integrations in one place. Link: https://manage.fusebit.io to create an account and log in.
  2. Create a new Integration using one of our Asana templates
  1. You will then be able to run the Integration, download it's code, modify it, and deploy your changes. Detailed instructions on how to get started with an Integration are available here.

Invoking the Asana API

The Integration template comes pre-configured with some example calls that invoke Asana's API, for example:

const asanaClient = await integration.tenant.getSdkByTenant(ctx, connectorName, ctx.params.tenantId);

const me = await asanaClient.users.me();
const workspace = me.workspaces[0].gid;
const assignee = me.gid;
const tasks = await asanaClient.tasks.getTasks({ workspace, assignee });

ctx.body = {
  message: `Found ${tasks.data.length} tasks in the Asana Workspace ${me.workspaces[0].name}`
};

The asanaClient object provided by Fusebit is an instance of the asana npm client. The full reference documentation for the package is available here.

Fusebit ensures the above SDK object is already bootstrapped with the Asana credentials of the user invoking the integration. You do not need to worry about obtaining an access token or refresh token -- Fusebit does that for you automatically.

Creating your own Asana App

Out of the box, Fusebit's Asana Integration uses our own demonstration application. This is to make it easier to get started, however you will likely need to register your own Asana app for use in production.

To create your own Asana App:

  1. In the Fusebit Management Portal, find the Integration you would like to connect to the new Asana App you just created. Select the ConnectorConnector - A connector is the package from Fusebit that manages the relationship between one or more integrations and a specific service. One of the most common types of connector is an OAuth connector, which takes care of the OAuth negotiation between your customers and the service you're integrating, so that you don't have to! tied to that integration

πŸ“˜

If more than one Integration is linked to that same Connector, they will all use the new Asana App you are about to configure.

  1. Select Enable Production Credentials in the Connector Configuration and note the OAuth Redirect URL under the 'Service Configuration' section. You will need this information to successfully create your app in Asana.

🚧

When switching a Connector to a different Asana App, all IdentityIdentity - An identity is a unique relationship one of your customers has with a service. An identity can be used by multiple integrations to act on that service on behalf of your customer. objects associated with that Connector will be deleted. Your users will need to re-authenticate against Asana after you make the change.

  1. In your Asana Workspace, navigate to Settings > Apps > Manage Developer Apps and select '+ New App'. Alternatively, you can click on this link to go there directly.
  1. Once you have filled out all the fields and selected 'Create App', Asana will display the Client ID and Client Secret, you will need these to configure the connector in the Fusebit Management Portal.

    Additionally, You will need to paste the OAuth Redirect URL retrieved from from the Fusebit Management Portal into the Redirect URLs field.

  1. Back in the portal, under 'Fusebit Connector Configuration', paste in the Client ID and Client Secret you obtained earlier from the Asana App you created.

Additionally, If the method(s) you want to invoke against the Asana API require certain permissions see here, add them under 'Space separated scopes to request from the OAuth server'. You can also this field blank and Fusebit will automatically ask for the default scopes.

πŸ‘

Good Job!

Any time a new user installs your Integration, you should now see your Asana App information displayed during the authorization step.

Also, now that you've configured your own app, you can also leverage our Webhooks SDK to receive events from Asana!

Receiving events from Asana

With this Asana App configuration, your Fusebit Integration will be able to sync any updates directly with/from
Asana. But you will likely also want to have your application respond to events from Asana (on behalf of your users) without having to poll for changes. We can achieve that by leveraging Asana's Webhooks API.

To set this up, you will need do to the following in your Integration:

  1. To register a webhook with Asana, you need to decide what resources you want to monitor for changes. You may choose to allow your user to select what they are interested in, or monitor all available resources. The below endpoint demonstrates how you could monitor a project by a specific name. The kinds of resources in Asana you can register webhooks agains are listed in the Resources and Actions section of this document.
router.post('/api/tenant/:tenantId/webhooks', integration.middleware.authorizeUser('install:get'), async (ctx) => {
  const asanaClient = await integration.tenant.getSdkByTenant(ctx, connectorName, ctx.params.tenantId);
  const me = await asanaClient.users.me();
  const workspace = me.workspaces[0].gid;
  const projects = await asanaClient.projects.getProjects({ workspace });
  
  // Pick resource to receive events for
  const selectedProject = projects.data.filter(d => d.name === "Product launch");

  if(selectedProject.length){
    try {
      const asanaWebhookClient = await integration.webhook.getSdkByTenant(ctx, connectorName, ctx.params.tenantId);

      // Specify filters as documented here https://developers.asana.com/docs/webhook-filter
      const webhook = await asanaWebhookClient.create(selectedProject[0].gid, {
        "filters": [{ 
          "action": "changed",
          "fields": [ "name" ],
          "resource_type" : "project"
        }]
      });
      ctx.body = webhook;

    } catch (e) {
      ctx.throw(e);
    }
  }
});
  1. Set up a listener in your integration.
integration.event.on('/:componentName/webhook/:eventtype', async (ctx) => {

  console.log ('There is a new update to your Asana Project!')
  
  // Insert your code here and invoke your backend to perform an action using
  // the event information provided in `ctx.req.body`
           
});

Did this page help you?