Search code examples
microsoft-teamsazure-bot-serviceteams-toolkit

401 when calling Teams Bot deployed in Azure


I've created a Notification Bot in VS Code using the Teams Toolkit template (Teams Toolkit v4.1.2).

The Bot runs fine locally and I'm able to trigger it by sending a HTTP Post request from Postman.

It deploys fine to Azure, but when I call it from Postman (using the url from the Azure App Service), I get a 401 Unauthorized response.

I've followed the Troubleshooting Bot Framework authentication guide to generate an access token from my bot's App Id & App Password using the following command:

curl -k -X POST https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token -d "grant_type=client_credentials&client_id=APP_ID&client_secret=APP_PASSWORD&scope=https%3A%2F%2Fapi.botframework.com%2F.default"

This generates an access token, but when I add that to the header of my Postman request I get a 403 Forbidden response.

How do I trigger my bot in Azure from an HTTP Post request?


Solution

  • There are several APIs for a Notification Bot, and please make sure you are sending POST to '/api/notification', e.g.,

    POST to https://{your-azure-host}.azurewebsites.net/api/notification

    In addition, the 401 Unauthorized may be returned by another API /api/messages which is used for Bot Framework Connection. If you are manually calling /api/messages, you may need to go through the access token flow with Bot ID and Password.