Forum Discussion

hurebelo's avatar
hurebelo
Contributor
10 years ago

Rest APIs: retrieve information in a single call

Using the Lithium rest api, is there a way to retrieve in a single “search/messages” call all of the following information?

  • Total number of messages/discussions fitting the search criteria (without needing to do a “search/messages/count” call).
  • Board title (without needing to do a “boards/id/board_id” call)
  • Excerpt/blurb of the body where the search term was found

 

Or do I really need to do a call to find out the number of results, other to get the actual results and another one for each of the messages to find out the board name through its board_id?

  • Hi hurebelo ,

     

    You could use the following REST V2 call to get all the details in a single call.

     

    <#assign query="SELECT board.title,body FROM messages WHERE subject MATCHES 'test' OR body MATCHES 'test' LIMIT 1000" />
    <#assign x= restadmin("2.0","/search?q=" + query?url) />

     

    Response would be as follows:

    {
    "status" : "success",
    "message" : "",
    "http_code" : 200,
    "data" : {
    "type" : "messages",
    "list_item_type" : "message",
    "size" : 3,
    "items" : [ {
    "type" : "message",
    "body" : "<P><SPAN>body123 test</SPAN></P>",
    "board" : {
    "type" : "board",
    "title" : "boardTitle1"
    }
    },
    {
    "type" : "message",
    "body" : "<P>test body</P>",
    "board" : {
    "type" : "board",
    "title" : "boardTitle2"
    }
    },
    {
    "type" : "message",
    "body" : "<P><SPAN>body123 test test</SPAN></P>",
    "board" : {
    "type" : "board",
    "title" : "boardTitle1"
    }
    } ]
    },
    "metadata" : { }
    }

     

     Now, you can get count and board title as follows:

     

    <#assign count = x.data.size />

     

    <#list x.data.items as message >
     <#-- you can access board title here as message.board.title -->
    </#list>

     

     

    Let me know if this gives any error, I tried and its working fine.

     

    Regards,

    Madhu