Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

ScriptRunner. Rest Endpoint feature to fetch Slack payload.

Edited

Hey Folks!

I'm trying to set up my own integration between Jira and Slack using the endpoint scriptrunner feature.

 

In Jira I made a listener spritrunner for the approval process. When the assignee changed I send several requests:

 

  1. to slack: to receive the assigne channel based on mail.
  2. to slack: to send a message with buttons and information from the task.

 

Both jsons are working fine.

 

The problem occurs when the button is clicked and the request goes to the spritrunner endpoint and I cannot read the contents of the payload inside the endpoint. the body comes empty. I tried sending requests from the postman, and the body arrived correctly.

 
Custom endpoint is simple, it looks like:

import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript
import org.codehaus.jackson.map.ObjectMapper
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
import groovyx.net.http.ContentType
import javax.servlet.http.HttpServletRequest
import groovy.json.JsonSlurper
import groovy.json.JsonOutput

@BaseScript CustomEndpointDelegate delegate


doSomething(httpMethod: "POST"){ MultivaluedMap queryParams, String body ->
JsonOutput.toJson([data: body])


log.info("Success! ${body}")

return Response.ok(new JsonBuilder([abc: 42]).toString()).build();
}

 

Perhaps is required to specify a special content type format application/x-www-form-urlencoded  in the endpoint to read information from slack, but I don’t know how to do it correctly.

 

Hope yoг help.

2 answers

0 votes
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Nov 16, 2023

The issue might be on the Slack side of this. It may not be sending a payload with the post. 

From postman, set the body type to raw>JSON or Content-Type header to application/json.

You should be able to read the body content that way.

2023-11-16 14_06_25-REST Endpoints.png2023-11-16 14_02_53-{{baseUrl}}_rest_scriptrunner_latest_custom_doSomething - My Workspace.png2023-11-16 14_01_39-REST Endpoints.png

As for how to handle that body, I'd recommend parsing with new JsonSlurper().parseText(body)

@Peter-Dave Sheehan hey! I've added new row as you recommended. But Slack action button returns 500 error, also in ScriptRunner error appear.

scriptrunner endpoint config.jpgslack action error.jpgscriptrunner endpoint log2.jpg

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Nov 16, 2023

Hi @Serj Shcherbakov

After going through your description, I have a doubt to clarify i.e. are you receiving any error messages when request goes to the ScriptRunner Endpoint?

If yes, could you please share the error message you are receiving?

Thank you and Kind regards,

Ram

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events