Missed Team ’24? Catch up on announcements here.

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

Iterating over elements of "Send web request"

Jochen Betz April 18, 2024

I'm trying to iterate over the elements of a web request to the rest api v3.

The result I get from the request contains all the information I need. In fact I can even print the result to audit log. With {{webResponse.body}} it results in:


{self=htps://xxxxxx.atlassian.net/rest/api/3/version/10321, id=10321, name=9.4.2, archived=false, released=false, startDate=2024-01-24, releaseDate=2024-04-26, overdue=false, userStartDate=24/Jan/24, userReleaseDate=26/Apr/24, projectId=10096},
{self=htps://xxxxxx.atlassian.net/rest/api/3/version/10325, id=10325, name=8.6.1, archived=false, released=false, startDate=2024-04-01, releaseDate=2024-08-16, overdue=false, userStartDate=01/Apr/24, userReleaseDate=16/Aug/24, projectId=10096},
{self=htps://xxxxxx.atlassian.net/rest/api/3/version/10326, id=10326, name=9.4.3, archived=false, released=false, startDate=2024-08-16, releaseDate=2024-12-31, overdue=false, userStartDate=16/Aug/24, userReleaseDate=31/Dec/24, projectId=10096},
{self=htps://xxxxxx.atlassian.net/rest/api/3/version/10327, id=10327, name=9.4.1.1, archived=false, released=true, startDate=2024-01-01, releaseDate=2024-03-20, userStartDate=01/Jan/24, userReleaseDate=20/Mar/24, projectId=10096},
{self=htps://xxxxxx.atlassian.net/rest/api/3/version/10328, id=10328, name=8.6.0.4, archived=false, released=true, startDate=2024-01-01, releaseDate=2024-02-17, userStartDate=01/Jan/24, userReleaseDate=17/Feb/24, projectId=10096},
{self=htps://xxxxxx.atlassian.net/rest/api/3/version/10332, id=10332, name=8.6.0.5, archived=false, released=true, startDate=2024-02-25, releaseDate=2024-03-01, userStartDate=25/Feb/24, userReleaseDate=01/Mar/24, projectId=10096},
{self=htps://xxxxxx.atlassian.net/rest/api/3/version/10333, id=10333, name=9.5.0, archived=false, released=false, startDate=2024-12-30, releaseDate=2025-12-31, overdue=false, userStartDate=30/Dec/24, userReleaseDate=31/Dec/25, projectId=10096},
{self=htps://xxxxxx.atlassian.net/rest/api/3/version/10335, id=10335, description=Auftrag von Curdin wegen AP7532, name=9.4.1.2, archived=false, released=true, startDate=2024-03-28, releaseDate=2024-04-10, userStartDate=28/Mar/24, userReleaseDate=10/Apr/24, projectId=10096}

 

It's a request to get https://xxxxx.atlassian.net/rest/api/3/project/PRJ/versions. But I don't know how to correct iterate over the result.

As the iteration did not work, after several different attempts I tried to access a single (aka first item) with something mentioned in other community questions:

  • Attempting to print {{webResponse.body.values(0)}} prints nothing
  • The same empty response is happening when printing {{webResponse.body.values.get(0)}}
  • And also empty print for {{response.results}}

What I'm surprised is, that there is no element/list/dict containing all this elements. I suppose the smart value {{webResponse.body}} is supposed to be this.

For completeness, here the "Send web request" which also shows state 200 up on validation:

2024-04-19_07-56-13.png

 

I would be thankful for more hints about what to try or pointing out errors/problems in my attempts.

 

2 answers

0 votes
Jochen Betz April 18, 2024

What is also strange/funny: the fields are ordered differently for my than on all the screenshots and videos I found online.
2024-04-19_08-30-37.png

0 votes
Jochen Betz April 18, 2024

After several more attempts I found out that the result is not (correctly) stored in my new created variable.
I found a similar issue where there is the hint to print the number of elements of the response.

This correctly prints 9 in case of {{webResponse.body.size|0}} but prints 0 in case of {{response.size|0}}

Thus trying to iterate directly over {{webResponse.body}} instead the new variable works.
But this makes me wonder:

  1. Why do/should we store the result in a variable first?
  2. What's wrong with either storing the data in the variable or accessing it?

 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events