Forum Discussion

tmarshall's avatar
tmarshall
Advisor
9 years ago

FreeMarker Novice - Making two rest calls in custom component

I'm new to developing and using FreeMarker. I'm learning and reading the various samples and figured out how to reference items in an API call. I'm getting stuck trying to reference a rest call to a different API from the initial rest set. I'm trying to make something similar to "Latest Solution" panel which lists the subject and board as a custom comonent. Below is my attempt, but would appreciate an expert who could guide me on how to reference the second rest information to pull the 'board name'. 

 

Thanks,

Tim

 

Here is my white boarding of what I want to accomplish.

Make API call to get solutions
https://community.foo.com/restapi/vc/boards/id/foobar/solutions/recent?restapi.response_style=view&page_size=30&format_detail=full_list_element
Loop thru each thread in solution list
For each thread read the following feilds (title, URL, board the solution is posted, URL for the board)
Print those values
End Loop

 

 

<ul>
  <#list rest("/boards/id/foo/solutions/recent?page_size=10&response_style=view").threads.thread as thread>
  <#assign rest("/boards/nested").boards.board.title as title>
	<li> 
	<a href="${thread.solutions.solution.@view_href}">${thread.messages.topic.subject}</a><br>
	<a href="${thread.board.@view_href}">${title}</a><br><br>
</li>
</#list>
</ul>

 

  • tmarshall's avatar
    tmarshall
    9 years ago

    Thanks, but that is a bit overwhelming for a novice. I went over my question with my boss and came up with the following below. Since the title didn't exist in the API call I was making I needed to reference another AP call. This was my original question. You can see that we can reference another rest call and concatenate the title to get the board title.

     

    <#list rest("/boards/id/[foo]/solutions/recent?page_size=10&response_style=view").threads.thread as thread>			<li> 
    				<a href="${thread.solutions.solution?first.@view_href}">${thread.messages.topic.subject}</a> <br /> 
    				<a href="${thread.board.@view_href}"> ${rest(thread.board.@href + "/title").value} </a> <br /><br />
    			</li>
    		</#list>
  • Hi tmarshall,

     

    Here is the code which gives number of details of recent soultion. Suppress those details which you don't want.

    <#assign solution_recent =rest("boards/id/<Board_ID>/solutions/recent?restapi.response_style=view").threads/>
    
    <#assign solution_details =[] />
    
    <#list solution_recent.thread as each_topic>
        
        <#assign Thread_title = each_topic.messages.topic.subject />
        <#assign Thread_author = each_topic.messages.topic.author.login />
        <#assign Thread_creation_date = each_topic.messages.topic.post_time.@view_date />
        <#assign Thread_views = each_topic.messages.topic.views.count?number />
        <#assign Thread_URL = each_topic.@view_href />
        <#assign Solution_author = each_topic.solutions.solution[0].author.login />
        <#assign author_rank =rest("users/login/${each_topic.solutions.solution[0].author.login}/ranking").ranking.name/>
        <#assign Solution_author_rank = author_rank />
        <#assign Solution_URL = each_topic.solutions.solution[0].@view_href />
    
        <#assign solution_details = solution_details + [{"Hash_Thread_title":Thread_title,"Hash_Thread_author":Thread_author,"Hash_Thread_creation_date":Thread_creation_date,"Hash_Thread_views":Thread_views,"Hash_Thread_URL":Thread_URL,"Hash_Solution_author":Solution_author,"Hash_Solution_author_rank":Solution_author_rank,"Hash_Solution_URL":Solution_URL}] />
    
    </#list>
    
    <#assign solution_details= solution_details?sort_by("Hash_Thread_views")?reverse> 
    
    <#list solution_details as solutions_details_loop>
      <table>
      <tr><td>Thread_title</td><td>${solutions_details_loop.Hash_Thread_title}</td>        
      <tr><td>Thread_author</td><td>${solutions_details_loop.Hash_Thread_author}</td> 
      <tr><td>Thread_creation_date</td><td>${solutions_details_loop.Hash_Thread_creation_date}</td> 
      <tr><td>Thread_views</td><td>${solutions_details_loop.Hash_Thread_views}</td> 
      <tr><td>Thread_URL</td><td>${solutions_details_loop.Hash_Thread_URL}</td> 
      <tr><td>Solution_author</td><td>${solutions_details_loop.Hash_Solution_author}</td> 
      <tr><td>Solution_author_rank</td><td>${solutions_details_loop.Hash_Solution_author_rank}</td> 
      <tr><td>Solution_URL</td><td>${solutions_details_loop.Hash_Solution_URL}</td> 
      <tr>---------------------------------------------------------------------------------</tr>
      </table>
    </#list>

    Please let me know if you face any problem.

     

    Thanks,

    Vishwajeet

     

    Give a Kudo and Accept as solution, if my post helps you.:smileyhappy:

    • tmarshall's avatar
      tmarshall
      Advisor

      Thanks, but that is a bit overwhelming for a novice. I went over my question with my boss and came up with the following below. Since the title didn't exist in the API call I was making I needed to reference another AP call. This was my original question. You can see that we can reference another rest call and concatenate the title to get the board title.

       

      <#list rest("/boards/id/[foo]/solutions/recent?page_size=10&response_style=view").threads.thread as thread>			<li> 
      				<a href="${thread.solutions.solution?first.@view_href}">${thread.messages.topic.subject}</a> <br /> 
      				<a href="${thread.board.@view_href}"> ${rest(thread.board.@href + "/title").value} </a> <br /><br />
      			</li>
      		</#list>