I have a scenario for sending notification into a chat window from my microsoft teams custom tab. So, I am trying to call Microsoft Graph API for sending message into a specific chatId: Post https://graph.microsoft.com/beta/chats/${chatId}/messages I can get access_token successfully , but while calling post request for sending notification into a chatId , I get "401 UnAuthorized" error . what is wrong with my code?
var message = {
"body": {
"content": "Hello World"
}
};
fetch(`https://graph.microsoft.com/beta/${context.userObjectId}/chats/${chatId}/messages`, {
method: "POST",
mode: "cors",
cache: "no-cache",
headers: {
'Content-Type': "application/json;charset=utf-8",
'Authorization': `Bearer ${fetched_accessToken}`
},
body: JSON.stringify(message)
}).then((response) => {
alert(response.statusText);
}).catch((err) => {
alert(err);
});
}
what is wrong with this code?