Integrating Kobo Toolbox with Asana - use HTTP adaptor?

“Does OpenFn support integration between Kobo Toolbox and Asana?”

@Mamadou this question came up on a call with a partner today. I know we can easily leverage the OpenFn HTTP adaptor to connect with any REST API, including the Asana API (see docs… but how would authentication work if the app uses OAuth 2.0? Can you explain and maybe share an example job snippet? :slight_smile:

1 Like

@aleksa-krolls this might be similar to connecting to Azure endpoint (since we need to first create an application on Asana).

A first step would be to request for a code that the app can exchange for a token at this endpoint https://app.asana.com/-/oauth_authorize.

After that something like this can do the job:

alterState(state => {
  const {...getAllConfigVariables } = state.configuration;

  const data = {
    code,
    client_id,
    grant_type,
    code_verifier,
    client_secret,
  };
  return post(
    `https://app.asana.com/-/oauth_token`,
    {
      headers: {
        "Content-Type": "application/json",
      },
      body: data,
    },
    state => {
      console.log("Authentication successful");
      const access_token = state.access_token;
    }
  )(state);
});

The result of that request would look like this if successful:

{
  "access_token": "f6ds7fdsa69ags7ag9sd5a...",
  "expires_in": 3600,
  "token_type": "bearer",
  "refresh_token": "hjkl325hjkl4325hj4kl32fjds...",
  "data": {
    "id": "4673218951",
    "name": "[NAME]",
    "email": "[EMAIL]"
  }
}
1 Like