Forum Discussion

omygoodness's avatar
8 years ago

How to display all community messages?

Is there a way to display all messages for whole community using rest API?

 

  • PaoloT's avatar
    PaoloT
    8 years ago

    omygoodness wrote:

    Thank you.

    I have another question. If you use:

    SELECT * FROM messages limit 1000

     or

    posts/messages?filter=&page_size=1000

    you will get all messages across whole community but how to filter out messages from hidden categories or that messages which are not public?


     

    Hi

    Just make sure that your call is made using the rest freemarker method (if you are writing a component), so that it will be made using the  permissions of the user who is viewing the component (or the anonymous user if none is logged). If you are calling the API programmatically, make sure you are using the appropriate session key / authentication for the relevant user. This will ensure only the messages that user can view are returned.

     

    If you call using restadmin (in freemarker), or with Administrator privileges, then you will see all messages.

     

    Hope it helps,

  • omygoodness - The rest() call will work the same way in the endpoint as well, so you will only get the public messages.

5 Replies

  • omygoodness's avatar
    omygoodness
    Mentor
    8 years ago

    Thank you.

    I have another question. If you use:

    SELECT * FROM messages limit 1000

     or

    posts/messages?filter=&page_size=1000

    you will get all messages across whole community but how to filter out messages from hidden categories or that messages which are not public?

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

    omygoodness wrote:

    Thank you.

    I have another question. If you use:

    SELECT * FROM messages limit 1000

     or

    posts/messages?filter=&page_size=1000

    you will get all messages across whole community but how to filter out messages from hidden categories or that messages which are not public?


     

    Hi

    Just make sure that your call is made using the rest freemarker method (if you are writing a component), so that it will be made using the  permissions of the user who is viewing the component (or the anonymous user if none is logged). If you are calling the API programmatically, make sure you are using the appropriate session key / authentication for the relevant user. This will ensure only the messages that user can view are returned.

     

    If you call using restadmin (in freemarker), or with Administrator privileges, then you will see all messages.

     

    Hope it helps,

  • omygoodness's avatar
    omygoodness
    Mentor
    8 years ago

    PaoloT What I am trying to do is setup an XML endpoint which looks like this:

     

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <#assign postQuery = "posts/messages?filter=&page_size=1000" />
    <#assign ordinary_posts = rest(postQuery + "&restapi.format_detail=full_list_element").messages.message />

    <searchContent>

    <#list ordinary_posts as main_message>

    <post>
    <url>${main_message.@view_href}</url>
    <title>${main_message.subject}</title>

    <#assign short_description = main_message.body?replace("<[^>]*>", "", "r")?replace("&nbsp;", " ", "r") />
    <#if short_description?length <= 255>
    <shortDescription>${short_description}</shortDescription>
    <#else>
    <shortDescription>${short_description?substring(0, 255)}</shortDescription>
    </#if>

    <#assign content = main_message.body?replace("<[^>]*>", "", "r")?replace("&nbsp;", " ", "r") />
    <content>${content}</content>
    </post>

    </#list>
    </searchContent>

     I get XML with required fields but now I need to filter not public messages. What is best solution for endpoints? Session key? Where I can find information about it?

  • VarunGrazitti's avatar
    VarunGrazitti
    Boss
    8 years ago
    omygoodness - The rest() call will work the same way in the endpoint as well, so you will only get the public messages.