micha80
10 years agoExpert
How to iterate through rest api result
Hi all,
I have tried a lot and now I am stuck. I loaded the user data from the following V1 Rest API Call:
rest(/users/id/XXX?restapi.response_style=view").response.user
Then I want to access the field "title" from the profile properties. And I can get it. I tried the following:
${user1.profiles.title}
OR
${user1.profiles.profile.title}
OR
<#list user1.profiles.profile as profile>
- ${profile}<br />
</#list>
OR
<#list user1.profiles as profile>
- ${profile}<br />
</#list>
Can anyone tell me how to access the profile property?
Regards,
Michael
Hi micha80
have a look at the below sample code:
<#assign test = rest("/users/self?restapi.response_style=view").user /> <ul> <#list test.profiles.profile as prf> <li>Profile '${prf.@name}' : ${prf}</li> </#list> </ul>
It will generate a list of all the key/value pairs for the currently logged in user (REST v1)
Hope it helps,