RestError - Authorization has been denied for this request - Bot framework Azure bot service

Baig, Farhan Ahmed 25 Reputation points
2025-12-01T08:20:49.1433333+00:00

Azure App service code -

const restify = require('restify');

const { BotFrameworkAdapter } = require('botbuilder');

// Create HTTP server

const server = restify.createServer();

server.listen(3978, () => {

console.log('Bot listening on http://localhost:3978/api/messages');

});

// Create adapter

const adapter = new BotFrameworkAdapter({

appId: process.env.MICROSOFT_APP_ID || '',

appPassword: process.env.MICROSOFT_APP_PASSWORD || ''

});

// Error handling

adapter.onTurnError = async (context, error) => {

console.error('Unhandled error:', error);

await context.sendActivity('Oops! Something went wrong.');

};

// Listen for incoming requests at /api/messages

server.post('/api/messages', async (req, res) => {

adapter.processActivity(req, res, async (context) => {

    // Respond directly using context.sendActivity()

    const userMessage = context.activity.text || '<empty>';

    await context.sendActivity(`You sent: "${userMessage}"`);

});

});

Error -

{

"statusCode": 401,

"details": {},

"name": "RestError",

"request": {

 "url": "https://webchat.botframework.com/v3/conversations/16VXUFHtu2s7p0wxBKLEvz-in/activities/16VXUFHtu2s7p0wxBKLEvz-in%7C0000003",

 "method": "POST",

 "headers": {

   "content-type": "application/json; charset=utf-8",

   "x-ms-conversation-id": "REDACTED",

   "accept-encoding": "gzip,deflate",

   "user-agent": "botframework-connector/4.0.0 Microsoft-BotFramework/3.1 BotBuilder/4.23.3 (Node.js,Version=v22.20.0; Linux 6.6.104.2-1.azl3; x64)  core-rest-pipeline/1.22.2 Node/22.20.0 (Linux 6.6.104.2-1.azl3; x64)",

   "x-ms-client-request-id": "649cae8f-f8ee-4a3c-b4eb-bd30aefba3d0",

   "accept": "*/*",

   "authorization": "REDACTED",

   "content-length": "504"

 },

 "timeout": 0,

 "withCredentials": false,

 "streamResponseStatusCodes": {},

 "enableBrowserStreams": false,

 "disableKeepAlive": false,

 "requestId": "649cae8f-f8ee-4a3c-b4eb-bd30aefba3d0",

 "allowInsecureConnection": false

}

}

Note -

The bot is working correctly in Bot framework Emulator, and able to receive messages on /api/messages, however when calling sendActivity() method it gives the error. The bot gives the error when ran in MS teams or test in web chat. The credentials and messaging endpoint are correct.

Webchat log - There was an error sending this message to your bot: HTTP status code InternalServerError

Azure AI Bot Service
Azure AI Bot Service
An Azure service that provides an integrated environment for bot development.
{count} votes

Answer accepted by question author
  1. Manas Mohanty 13,340 Reputation points Moderator
    2025-12-04T04:27:25.37+00:00

    Hi Baig, Farhan Ahmed,

    Attached case summary for reference

    1. Ensure MicrosoftAppId and ClientSecret match the Azure Bot’s registration.
    2. Set MicrosoftAppType and MicrosoftAppTenantId correctly (especially if SingleTenant).
    3. Verify your messaging endpoint is reachable and HTTPS.
    4. Retest in Teams and Test in Web Chat.
    5. Suggested Switching to Agent-Teams Deployment

    Reference- https://learn.microsoft.com/en-us/azure/bot-service/bot-service-quickstart-create-bot?view=azure-bot-service-4.0&tabs=python%2Cvs

    Status - Customer resolved the issue by changing to single tenant from multi-tenants.

    Thank you for using Azure Services.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

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