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()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.