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

0 votes
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 Leaders.
May 12, 2025

Suggest an answer

Log in or Sign up to answer