How to connect to an external web API from a local Azure Function?

Shane Davis 0 Reputation points
2025-06-17T21:06:00.8166667+00:00

I am trying to develop an Azure Function that makes calls to a web service on our Azure tenant. I can connect to the web service from Postman. However, when I try to run my Azure function in VSCode that attempts to connect to the same web service, I get a "TypeError: fetch failed" message with the cause "Error: unable to verify the first certificate". The error code is "UNABLE_TO_VERIFY_LEAF_SIGNATURE". For my local server, it is using https://localhost, and I start the function by using func start --useHttps --cert LocalCert.pfx --password ????????.

I have tried using several different modules, but I now I am trying to use the wretch APT, but still getting the same issue. Has anyone experienced this issue before?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,909 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Praveen Kumar Gudipudi 1,805 Reputation points Microsoft External Staff Moderator
    2025-06-18T04:44:55.8766667+00:00

    Hello Shane Davis,

    To resolve this issue, you can bypass Node.js certificate validation by adding an environment variable when starting the application. Specifically, you can add NODE_TLS_REJECT_UNAUTHORIZED=0

    Please configure above environment variable app setting and let us know with an update.

    If this answer was helpful, please click "Accept the answer" and mark Yes, as this can help other community members.

    User's image

    If you have any other questions or are still experiencing issues, feel free to ask in the "comments" section, and I'd be happy to help.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.