Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to parse a json array response in script Runner

Dear all,

From script runner script we are using MS Graph APi to get information from particular user mentionned in an issue.

For that we call an API endpoint using HttpBuilder and from the response json we get the follwing output :

{
 @odata.context=https://graph.microsoft.com/v1.0/$metadata#users, 
 value=[{         businessPhones=[], 
         displayName=Serge Cal GMAIL, 
         givenName=null, 
         jobTitle=null, 
         mail=user1.tom@gmail.com, 
         mobilePhone=null, 
         officeLocation=null, 
         preferredLanguage=null, 
         surname=null,         userPrincipalName=user1.tom_gmail.com#EXT#@SCALDERARA.onmicrosoft.com,          id=253bca1d-6c03-441f-92e4-e206c7d180f7
       }]
}

The method sample I use is as below :

def http = new HTTPBuilder('https://graph.microsoft.com/v1.0/users?')
http.request(GET) {

requestContentType = ContentType.JSON
uri.query = [ $filter:"mail eq '$userEmail'".toString() ]

headers.'Authorization' = "Bearer " + AuthToken

response.success = { resp, json ->
_userId=json["value"]["id"]  <<<= Do not work !!!!!

}

How can I access the value of value[0].Id member from the response delegate ?

Thanks for help

regards

 

 

1 answer

1 accepted

0 votes
Answer accepted

I was able to find what seems to be the reference for that API

https://docs.microsoft.com/en-us/graph/api/resources/user?view=graph-rest-1.0#json-representation

So I think either of the following 2 notations will work:

_userId = json.id 
_userId = json['id']

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

Happy New Year and Welcome New Marketplace Partner Program Partners!

Happy New Year! We hope you all had a safe and restful holiday season. 2020 was a unique year full of unforeseen events; however, as we enter the new year of 2021, we’re optimistic for the light at t...

536 views 7 20
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you