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

API suddenly doesn't work

Hi,

My API work fine the last week but today i can't call API JIRA (all API doesn't work).

I reset my passord, and create a new API token but no success.

 

My API : 

public HttpResponse<JsonNode> getAllUsers(String startAt, String maxResult) throws UnirestException {

String UrlRest3 = JiraUrl+ "rest/api/3/users/search";

String UrlRestComplet = UrlRest3+"?startAt="+startAt+"&maxResults="+maxResult;

HttpResponse<JsonNode> response = Unirest.get(UrlRestComplet)
.basicAuth(JiraUserMail, JiraToken)
.header("Accept", "application/json")
.asJson();

return response;

}

 

 

I have this error  : 

Exception in thread "main" com.mashape.unirest.http.exceptions.UnirestException: java.lang.RuntimeException: java.lang.RuntimeException: org.json.JSONException: A JSONArray text must start with '[' at 1 [character 2 line 1]
at com.mashape.unirest.http.HttpClientHelper.request(HttpClientHelper.java:143)
at com.mashape.unirest.request.BaseRequest.asJson(BaseRequest.java:68)
at com.ag2rlm.jira.api.JiraAPI.getAllUsers(JiraAPI.java:72)
at TestJiraAPI_GetAllUsers.main(TestJiraAPI_GetAllUsers.java:24)
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: org.json.JSONException: A JSONArray text must start with '[' at 1 [character 2 line 1]

 

Thanks,

2 answers

0 votes
Footleg
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
Sep 14, 2023

I ran into this same problem, and debugging into the library I learned that it was because the API was not returning JSON, in my case because authentication was denied with the reason 'CAPTCHA required'. It was difficult to determine this from the error output by this Unirest call. However if you first attempt to call the API with a String response:

 

HttpResponse<String> response1 = Unirest.get(jiraServerURL + "/rest/api/2/search")
                    .basicAuth(jiraUsername, jiraPassword)
                    .header("Accept", "application/json")
                    .queryString("jql", "type = Bug AND project = ABC")
                    .asString();
then you don't get the runtime exception and can now look at the response header to learn what was actually returned by the API.
0 votes
Deleted user Dec 21, 2022

Hi 

 

Even I am getting the same exception

Suggest an answer

Log in or Sign up to answer