Unable to Get Local Issuer Cert in Node API call to Asana

So, admittedly I don’t know much about SSL certs, which I’m assuming is my issue. I’m trying to call the TasksApi.createTask method in my NodeJS Azure Function to create a task in our Asana environment. I’m running this in development; through VS Code on localhost, calling the API from Postman. The error I’m getting from the createTask method is “Unable to get local issuer certificate.” I can see this error in the terminal in VSCode. Note, the “error” object isn’t in the form of a JSON object or anything, it’s simply the “error” text that’s being returned and triggering the log entry below:

const Asana = require('asana');

let client = Asana.ApiClient.instance;
let token = client.authentications['token'];
token.accessToken = '-- redacted for security --';

let tasksApiInstance = new Asana.TasksApi();
let body = {"data":{"workspace":"-- my workspace id --"}}; // Object | The task to create.
        
let opts = { 
     'opt_fields': "-- redacted for brevity --"
};
if (body) {
          tasksApiInstance.createTask(body, opts).then((result) => {
          context.log('>>> API Returned data: ' + JSON.stringify(result.data, null, 2));
     }, (error) => {
          context.log("!!!!!!!!!!!!!!!! Error: " + error);
     });
}

Does anyone know what steps I can take to mitigate this? I’ve searched this forum and elsewhere and couldn’t find a great resolution to a similar use case.
Thanks!

Hi @Christine_Hill2,

I don’t know too much about SSL certs and Azure Functions but I tried your sample code out on my local computer and was able to create a task:

const Asana = require('asana');

let client = Asana.ApiClient.instance;
let token = client.authentications['token'];
token.accessToken = "<YOUR_PERSONAL_ACCESS_TOKEN>";

let tasksApiInstance = new Asana.TasksApi();
let body = {"data":{"workspace":"<YOUR_WORKSPACE_GID>"}}; // Object | The task to create.
let opts = {};

if (body) {
     tasksApiInstance.createTask(body, opts).then((result) => {
          console.log('>>> API Returned data: ' + JSON.stringify(result.data, null, 2));
     }, (error) => {
          console.log("!!!!!!!!!!!!!!!! Error: " + error);
     });
}

To confirm that this isn’t an issue with the node-asana client library and more on how SSL certs work with Azure could you try the following request with the node axios library (assuming Azure Functions has this library installed and accessible)

const axios = require('axios');

const url = 'https://app.asana.com/api/1.0/tasks';
const data = {
  data: {
    workspace: '<YOUR_WORKSPACE_GID>',
  },
};

const headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Bearer <YOUR_PERSONAL_ACCESS_TOKEN>',
};

axios.post(url, data, { headers })
  .then(response => {
    console.log('Response:', response.data);
  })
  .catch(error => {
    console.error('Error:', error.response ? error.response.data : error.message);
  });

1 Like

Hello, I was unable to get this specific code snippet to return anything (either through ‘then’ or ‘catch’). However, I was able to use the JavaScript example (using axios) on Asana’s API Documentation page, and got an error with the code “UNABLE_TO_GET_ISSUER_CERT_LOCALLY,” which is presumably the same error. So, I’m not sure what to do about this. If I deploy the API to Azure and run it from our development server, it does work. It creates the task and returns the taskID for logging. So, it seems there’s some sort of certificate magic that needs to happen on my local machine in order to test the API from localhost. I’d really like to avoid having to deploy the API every single time we make a small change, and lose the ability to debug using the console.

Any help would be greatly appreciated. Thanks!!

I see. Thank you for confirming @Christine_Hill2. Based off of what you have told me this doesn’t look to be an issue with our node client library or API. It is likely an issue with node on your machine or VPN or proxy.

From a quick Google search I found some of the following:

I would check with your IT admin to see if they are blocking any requests or check your node configuration. If you ask ChatGPT “how to fix node UNABLE_TO_GET_ISSUER_CERT_LOCALLY” it should also give you a list of ways to troubleshoot

I suspected it wasn’t an issue with the Asana client library. I’ve tried a myriad of solutions (including the ones mentioned in the links above) and none have worked. I feel like developing calls to Asana APIs through a Node application is a pretty niche use-case, which is why I’ve turned to an Asana forum. I don’t know if there’s a trick to getting a cert that will play nice with Asana’s APIs or a special configuration that someone has come across for this specific use-case. In all the searching and Googling I’ve done on this issue, I haven’t come across anyone who is trying to call an Asana endpoint.

For anyone coming across this in the future, I got around this issue by adding/setting the NODE_TLS_REJECT_UNAUTHORIZED key to a value of 0 in your local settings file. You can do this by opening local.settings.json in (the root of) your project, and adding the following:

"NODE_TLS_REJECT_UNAUTHORIZED": "0"

The way I understand it, this issue comes when calling an Asana endpoint from a Node application that does not have a certificate set up correctly or being blocked by company policy. Your application is trying to call an Asana endpoint, but because Node doesn’t trust Asana without a CA, Node blocks the request. Setting the above key will tell Node to ignore that mistrust and call it anyway. You’re setting it on the local file, which means it should not affect the application in production.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.