Forum Discussion

duannguyen's avatar
13 years ago

How to consume multiple XML from multiple Rest API calls and transform data with XSLT

Hi, I need to pull in data from the Lithium blog to display on a webpage the following info: 1 - Blog posts (teaser headline, date, user, etc) 2 - PermaLink 3 - User's Avatar   In order to get a...
  • xorrkaz's avatar
    13 years ago

    Not sure if you have the feature enabled in your community, but we use endpoints for this.  Within the endpoint, we make all of the REST calls then produce a consolidated XML output with only the data we care about.  For example, here is the code we use in a search-before-post endpoint to give us a consolidated list of matches along with their kudos and a custom metadata count of cases linked.

     

    <#assign subject = http.request.parameters.name.get("subject", "") />
    <#assign size = http.request.parameters.name.get("size", "") />
    <#assign messages = restadmin("/search/messages?one_or_more=" + subject?replace(" ", "+") + "&page_size=" + size + "&restapi.response_style=view").messages />
    <response status="success">
    <messages>
    <#list messages.message as message>
      <message type="message" href="${message.@href}" view_href="${message.@view_href}">
      <subject type="string">${message.subject}</subject>
      <kudos>
      <count type="int">${message.kudos.count}</count>
      </kudos>
      <#assign cases_linked = 0 />
      <#assign tags = restadmin("/messages/id/" + message.id + "/tagging/tags/all").tags />
      <#list tags.tag as tag>
        <#if tag.text?starts_with("tz:km:")>
          <#assign cases_linked = cases_linked + 1 />
        </#if>
      </#list>
      <cases_linked>
      <count type="int">${cases_linked}</count>
      </cases_linked>
      </message>
    </#list>
    </messages>
    </response>

     

    The result looks like:

     

    <response status="success">
      <messages>
        <message type="message" href="/messages/id/59" view_href="https://foo.example.com/t5/boards/id/bar/This-is-a-test">   
          <subject type="string">CASE: 12345: This is a test</subject>    
          <kudos>
            <count type="int">10</count>
          </kudos>
          <cases_linked>
            <count type="int">3</count>
          </cases_linked>
        </message>
      </messages>
    </response>