Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

MS Team webhook works for some users, doesn't work for others

Guy Incognito
Contributor
November 23, 2023

Hi all,

I use Scriptrunner to send MS Teams (and Slack) notifications when some issues are transitioned. The problem is, that MS Teams notifications only work for certain Jira(/Microsoft) users (e.g. mine), and not for others.

When the notification fails, I get a 400 error.

Here's my Scriptrunner groovy code:

def notificationChannel = "https://XXXXXXXXXX.webhook.office.com/webhookb2/XXXXXXXX/IncomingWebhook/YYYYYYYYYYY/ZZZZZZZZZZZZZZ"
try {
def post = new URL(notificationChannel).openConnection() as HttpURLConnection
def teamsMessage = "{'text':'"+notificationMessage+"'}"
post.setRequestMethod("POST")
post.setDoOutput(true)
post.setRequestProperty("Accept", 'application/json')
post.setRequestProperty("Content-Type", "application/json")
post.getOutputStream().write(teamsMessage.getBytes("UTF-8"))
def postRC = post.getResponseCode()
if (!postRC.equals(200)) {
throw post.getInputStream().getText()
}
} catch (err) {
SlackUtil.message("slack_connector",
Constants.ERROR_NOTIFICATION_CHANNEL,
"<!channel>\n"+err.getMessage()
)
}

When it fails, the returned error is:

Server returned HTTP response code: 400 for URL: https://XXXXXXXXXX.webhook.office.com/webhookb2/XXXXXXXX/IncomingWebhook/YYYYYYYYYYY/ZZZZZZZZZZZZZZ

 If I open the same issue with my Jira users, and execute the same transition, the notification goes fine.

Any hints?

Thanks in advance!

1 answer

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
January 2, 2024

Hi @Guy Incognito

Just to check, have you confirmed whether all the users receiving the MS Team notification have the required permission or exist in your instance?

I am asking this because if you look through the Slack API, the HTTP 400 error message is returned only when there is an invalid payload or the user is not found.

Also, I suggest taking a look at this Adaptavist Library example of how a Custom Notification is sent to Slack.

I am looking forward to your feedback and clarification.

Thank you and Kind regards,

Ram

Suggest an answer

Log in or Sign up to answer