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

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,506,715
Community Members
 
Community Events
180
Community Groups

Hi I'm working on a project which involves API calls. I was able to perform the Post api successfully but I'm getting 400 error for the GET request. I have tried so many times but still i'm getting the same error. Any solutions?

 

My Code

String targetURL = 'https://graph.microsoft.com/v1.0/users/pradeep@avaMigration.onmicrosoft.com'
try {
URL restServiceURL = new URL(targetURL);
HttpURLConnection httpConnection = (HttpURLConnection) restServiceURL.openConnection();
httpConnection.setRequestMethod("GET");
//httpConnection.setRequestProperty("Accept", "application/json");
httpConnection.setRequestProperty("Authorization", "Bearer " + "the token);

if (httpConnection.getResponseCode() != 200) {
throw new RuntimeException("HTTP GET Request Failed with Error code : "
+ httpConnection.getResponseCode());
}

BufferedReader responseBuffer = new BufferedReader(new InputStreamReader(
(httpConnection.getInputStream())));

String output;
log.debug("Output: \n");

while ((output = responseBuffer.readLine()) != null) {
return output;
}

httpConnection.disconnect();

} catch (MalformedURLException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

 

2 answers

0 votes

This line is plain wrong:

httpConnection.setRequestProperty("Authorization", "Bearer " + "the token);

Do you have the token as the variable "token"? If so, then it should be something like:

httpConnection.setRequestProperty("Authorization", "Bearer " + token);

Hi that's just to show you that I'm passing the bearer token there I'm not an idiot to pass an variable like that

Thanks

Hi @Pradeep A

From the code you have shared, I noticed an error, i.e.:-

httpConnection.setRequestProperty("Authorization", "Bearer " + "the token);

You have missed out on a closed quotation for your String parameter. It should be:-

httpConnection.setRequestProperty("Authorization", "Bearer " + "the token"); 

I hope this helps to solve your question. :)


Thank you and Kind Regards,

Ram 

Hi that's just an example to show you where the token gets inserted I know that I have missed the quotes there

 

Thanks

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events