Forums

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

Need Help in sending REST API calls from Scriptrunner

Elina September 1, 2025

I have used below code in Scriptrunner to call jira data center api, it always error message as below. I can confirm the base url and endpoint is right. Anyone can give some advise? Many thanks~

 

 Script console script failed: 
groovyx.net.http.HttpResponseException: status code: 404, reason phrase: Not Found
at groovyx.net.http.RESTClient.defaultFailureHandler(RESTClient.java:263) ~[plugin_3515051478453807647_groovyrunner-9.18.0.jar:9.18.0]
at groovyx.net.http.HTTPBuilder$1.handleResponse(HTTPBuilder.java:503) ~[plugin_3515051478453807647_groovyrunner-9.18.0.jar:9.18.0]
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:223) ~[plugin_3515051478453807647_groovyrunner-9.18.0.jar:?]
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:165) ~[plugin_3515051478453807647_groovyrunner-9.18.0.jar:?]
at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:515) ~[plugin_3515051478453807647_groovyrunner-9.18.0.jar:9.18.0]
at groovyx.net.http.RESTClient.get(RESTClient.java:119) ~[plugin_3515051478453807647_groovyrunner-9.18.0.jar:9.18.0]
at groovyx.net.http.RESTClient$get$0.call(Unknown Source) ~[?:?]
at Script284.get(Script284.groovy:115) ~[?:?]
at Script284.run(Script284.groovy:78) ~[?:?]
-----------------------------------------------------------------------------------------------------

String authTokenJira = "xxxx"
def responseJiraGet = get("/rest/api/2/user", "username="+addLicenseUsers, "https://xxx/jira", authTokenJira)
log.warn(responseJiraGet)

 

public Object get(String endpoint, String query, String base_url, String authToken) {
RESTClient client = new RESTClient(base_url)
if (endpoint.contains("&") || endpoint.contains("?")) {
throw new Exception("The parameters of the endpoint must be included in the query variable")
}
client.setHeaders([
"Accept" : ContentType.JSON,
"Authorization": "Bearer ${authToken}"
])

def getResponse = client.get(
path: endpoint,
queryString: query,
contentType: ContentType.JSON
)

return getResponse
}

2 answers

0 votes
Stefan Stadler
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 1, 2025

Hi @Elina 

did you try to run this in the browser directly? 
For example, I was able to run this in the same browser session as I was logged into Jira:
https://url-to-jira/rest/api/2/user?username=my.mail@address.de

In our case, the mail address is the user name, but not in all cases. Sometimes, there are also JIRAUSER12345 usernames given. If the questionable query works in the browser, then there is something about the RESTClient library you are using. 

If the call is not working in the browser, you will see that the error message is more clearly visible to your, but the request still fails with HTTP404, which is the same error as you already got. 

As you already try using ScriptRunner: Could you check if the following gives you some output?

com.atlassian.jira.component.ComponentAccessor.getUserManager().getUserByName("sameUserNameAsFromAbove")
Elina September 1, 2025

hi Stefan

 

1. I can get the response data via browser:get browser.png2. I have used same get function to call confluence api and it can give the response. Please see the section marked with yellow color. The value of com.atlassian.jira.component.ComponentAccessor.getUserManager().getUserByName("sameUserNameAsFromAbove" marked with red cycle.Users.PNG

 

 

Stefan Stadler
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 1, 2025

This is a really strange behavior. Unfortunately I have no idea how to debug RESTClient, but maybe there is a way to obtain the message to get more details on what is missing?

404 could be thrown when the endpoint itself is not found or when the user is not found. A missing user could be because of (somehow) incorrect data - even if I have seen that the browser request is working fine. 

And a missing endpoint could be because of some faulty configuration of the RESTClient. Maybe the message would help here.

0 votes
Mohamed Benziane
Community Champion
September 1, 2025

Hi,

Welcome to the community

Are you sure that the username in the variable addLicenceUsers is correct ?

Elina September 1, 2025

yes, i'm sure. I can find the user in Jira application.

Elina September 1, 2025

it' very weird. I have try another api : https://developer.atlassian.com/server/jira/platform/rest/v10007/api-group-group/#api-api-2-group-user-post. it's always display same error.

Suggest an answer

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

Atlassian Community Events