Forum Discussion

micha80's avatar
micha80
Expert
10 years ago

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,

     

2 Replies

  • PaoloT's avatar
    PaoloT
    Lithium Alumni (Retired)
    10 years ago

    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,

     

  • micha80's avatar
    micha80
    Expert
    10 years ago
    Hi Paolo,

    thanks, that helped a lot.

    Regards,
    Michael