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()
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.