Forums

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

How to use Slack resource in the REST Endpoint?

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
Viktoriia Boiko
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 12, 2025

pls delete this question, I chose wrong deployment type, it should be Data Center and I already created duplicated question

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
ENTERPRISE
TAGS
AUG Leaders

Atlassian Community Events