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~
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
}
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")
hi Stefan
1. I can get the response data via browser:2. 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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Welcome to the community
Are you sure that the username in the variable addLicenceUsers is correct ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.