Forums

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

How to send not-ok response from Script Runner Rest End Point

Nallusamy Narayanaswamy
Contributor
March 23, 2021

Hi

I have created Script Runner Rest End point. 

For the success  case, I am sending ok response with JSON as shown below

return Response.ok(new JsonBuilder([success: success]).toString()).build();

 

For the failure case, I want to send not.ok response. May be 404 status code with JSON error message. 

 

Can anyone please tell how to do it? Is there any method for that? 

1 answer

1 accepted

4 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
March 23, 2021

Hi Nallusamy,

 

To return a failed response, you could try someting like:

return Response.status(404).entity("NOT-OK").type(acceptType).build()

Please note, this sample is not 100% exact to your environment. Hence you will need to make the required changes.

 

Hope this helps to solve your question :)

 

Kind Regards,

Ram

Nallusamy Narayanaswamy
Contributor
March 24, 2021

Thanks @Ram Kumar Aravindakshan _Adaptavist_ 

return Response.status(404).entity("${sourceIssueKey} - Source JIRA Key does not exist.").build();

 

It just returns string given in  entity.  What should I do to get status code as well?

 

Curl command:

curl -X POST -H "Content-type: text/json" -u nnallusamy: --data "@linkIssueInput.json" https://devjira.athenahealth.com/rest/scriptrunner/latest/custom/linkJiraIssue

 

Result:

"ACRK-86888 - Source JIRA Key does not exist."

Nallusamy Narayanaswamy
Contributor
March 24, 2021

Thanks @Ram Kumar Aravindakshan _Adaptavist_ 

return Response.status(404).entity("${sourceIssueKey} - Source JIRA Key does not exist.").build();

 

What should i do to get the status code along with entity message?

 

curl -X POST -H "Content-type: text/json" -u nallu @123 --data "@linkIssueInput.json" https://devjira.athenahealth.com/rest/scriptrunner/latest/custom/linkJiraIssue

"ACRK-86888 - Source JIRA Key does not exist."

Ram Kumar Aravindakshan _Adaptavist_
Community Champion
March 24, 2021

Hi Nallusamy,

From your requirement, you could include the status code in the message itself, for example:-

return Response.status(404).entity("404 - ${sourceIssueKey} - Source JIRA Key does not exist.").build()

 

Kind Regards,

Ram

Suggest an answer

Log in or Sign up to answer