Custom API Call

#1

Hey there,
I am having troubles calling a custom api. For dev-purpose I am running botpress as well as my custom API on localhost. When calling my API (https://localhost:5000/api/values) I am facing the following error message: “Error, unable to verify the first certificate”.
I know this is more a nodejs error regarding missing some root certificate. I found the following thread --> https://stackoverflow.com/questions/31673587/error-unable-to-verify-the-first-certificate-in-nodejs
Unfortunately I have no clue, where and how I can install and/or require the npm package.

Does anyone had the same problem and could give me some advise?

Thanks in advance!

#2

@waretec Are you calling the custom API from a hook? Also, is your API working from a REST Client i.e. Postman?

#3

I am calling the API like in the tutorial: https://botpress.io/docs/tutorials/skill-call-api/
The api itself is working and I tested it already via Postman.
The Call API functionality is also working if I use some API on some server which is not localhost. like https://jsonplaceholder.typicode.com/

#4

I also tried the following approach: creating a custom action:

"use strict";
const axios = require("axios");

/**
 * Make HTTP(S) call to any given API
 * @title Make HTTP(S) call to any given API
 * @category Custom
 * @author MyName
 * @param {string} baseApiUrl - The base api url
 * @param {string} httpAction - GET/POST/...
 * @param {string} actionUrl - The detailed action url
 * @param {string} output - the result of the action call
 */

async function callCustomAction(baseApiUrl, httpAction, actionUrl, output) {
  const fullUrl = `${baseApiUrl}/${actionUrl}`;
  console.log("calling: " + fullUrl);
  if (httpAction.toUpperCase() === "GET") {
    const { data } = await axios.get(fullUrl);
    temp[output] = data;
    temp[displayMessage] = true;
  } else if (httpAction.toUpperCase() === "POST") {
  }
}

return callCustomAction(
  args.baseApiUrl,
  args.httpAction,
  args.actionUrl,
  args.output
);

and I still get the same error:

An error occurred while executing the action "customApiCall [Error, unable to verify the first certificate]

Is it possible to disable the verification of the certificate?

#5

Custom Action should have worked as i haven’t tried API skill. Are you hosting the botpress on SSL?

Its something to do with your API hosting server which is not able to verify certificate. Try setting rejectUnAuthorized to false in your axios call and see if that works.(search google for more info)