The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

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

How to use Slack connection resource in REST Endpoint? (Scriptrunner)

Viktoria
May 12, 2025

Please help me understand how to use the Scriptrunner's resource in the REST endpoint. Right now, my script does not work without a token in it, but I want to hide it with the Resource.

I use it to send a POST http request with ${slackToken}:

def http = new HTTPBuilder("https://slack.com/api/chat.postMessage")
http.request(Method.POST) {
headers.'Authorization' = "Bearer ${slackToken}"
headers.'Content-Type' = 'application/json; charset=utf-8'

def payload = [
channel: channel,
text: previewText,
attachments: [[
color : color,
blocks: blocks
]]
]

send(ContentType.JSON, JsonOutput.toJson(payload))

response.success = { resp, reader ->
def parsed = reader
slackResponse.append(parsed)
slackStatus = 200
}
response.failure = { HttpResponseDecorator resp ->
slackResponse.append("Slack error: ${resp.status}")
slackStatus = resp.status
}
}

return Response.status(slackStatus).entity(slackResponse.toString()).build()

 

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

1 vote
Vronik
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
May 12, 2025