Forum Discussion

skylinegtr's avatar
10 years ago

Help with API code

Hello! For some reason the following API only display posts from the tkb. It's supposed to show posting from tkb and forum. Has anyone run into this problem before?  Any help will be appreciated. Thanks!

 

<#attempt>
<#assign messages = rest("2.0","/search?q=" + "SELECT subject, view_href, post_time_friendly, board.id, teaser, author FROM messages WHERE board.id IN('forum','tkb') ORDER BY post_time DESC LIMIT 5"?url) />
<#recover>
</#attempt>

<#if messages.message?size gt 0>
<div class="custom-recent-articles-container">
<div class="custom-recent-articles-heading-bar"><span class="custom-recent-articles-heading-bar-title">${text.format("")}</span></div>

<#list messages.data.items as message >
<#assign posted_by_userid = message.author.login?string />
<#assign posted_by_label = text.format("Posted By:") />

<div class="custom-recent-article-wrapper">
<div class="custom-article-header">
<div class="custom-article-subject"><a href="${message.view_href}">${message.subject}</a></div>
<div class="custom-article-posted-by">
<span class="author">${posted_by_label} <#if ((posted_by_userid != "") && (posted_by_userid != "Anonymous"))><@component id="common.widget.user-name" user="conv:${message.author.login}" /></#if></span>
</div>
</div>
<div class="custom-article-teaser">
<#if message.teaser?length gt 0>
${message.teaser} <span class="custom-read-more"><a href="${message.@view_href}">${text.format("")}</a></span>
</#if>
</div>
</div>
</#list>
</#if>

  • OlivierS's avatar
    OlivierS
    10 years ago

    skylinegtr I think it's probably best to run 2 querries then:

     

    <#assign messages_forum = rest("2.0","/search?q=" + "SELECT subject, view_href, post_time_friendly, board.id, teaser, author FROM messages WHERE board.id='forum' ORDER BY post_time DESC LIMIT 3"?url) />

    and

     

    <#assign messages_tkb = rest("2.0","/search?q=" + "SELECT subject, view_href, post_time_friendly, board.id, teaser, author FROM messages WHERE board.id ='tkb' ORDER BY post_time DESC LIMIT 2"?url) />
  • OlivierS's avatar
    OlivierS
    Lithium Alumni (Retired)

    skylinegtr are you sure your board forum is called 'forum' ?

    Try something like: SELECT board.id FROM messages LIMIT 100 in Studio / API browser and see what's returned.

    Also, maybe the last 5 messages are from the tkb and not the forum (unlikely). Have you tried to display more (LIMIT DESC 50)

    • skylinegtr's avatar
      skylinegtr
      Mentor

      OlivierS- When I changed the Limit 100 it display more content but it seems that the KB content display first and then the Forum content. I also got the following message. I only want 5 post to display, maybe 3 from KB and 2 the forum or mix content. 

       

      The following has evaluated to null or missing:
      ==> message.@view_href  [in template "preview" at line 23, column 77]
      
      Tip: If the failing expression is known to be legally null/missing, either specify a default value with myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthessis: (myOptionVar.foo)!myDefault, (myOptionVar.foo)??
      
      The failing instruction (FTL stack trace):
      ----------
      ==> ${message.@view_href}  [in template "preview" at line 23, column 75]
          #list messages.data.items as message  [in template "preview" at line 10, column 9]
      ----------

        

      • OlivierS's avatar
        OlivierS
        Lithium Alumni (Retired)

        skylinegtr I think it's probably best to run 2 querries then:

         

        <#assign messages_forum = rest("2.0","/search?q=" + "SELECT subject, view_href, post_time_friendly, board.id, teaser, author FROM messages WHERE board.id='forum' ORDER BY post_time DESC LIMIT 3"?url) />

        and

         

        <#assign messages_tkb = rest("2.0","/search?q=" + "SELECT subject, view_href, post_time_friendly, board.id, teaser, author FROM messages WHERE board.id ='tkb' ORDER BY post_time DESC LIMIT 2"?url) />