Forum Discussion

CCornerstone's avatar
8 years ago

REST-API: Sorting TKB Articles by number of views via API

Hi everyone,

 

I am not a developer so not really sure how to use the rest-api. I would like to retrieve a full list of tkb articles sorted by the number of views from our online financial dictionary containing more than 1.300 definitions.

See: https://wissen.consorsbank.de/t5/Geldlexikon/tkb-p/Boersenlexikon for the full dictionary or https://wissen.consorsbank.de/t5/Geldlexikon/Abandon/ta-p/6065 for a single article.

As an output I would just need the number of views and the title of the article.

 

 

Is anyone familiar with this topic? Thank you very much for your help!

 

All the best, Clemens

 

6 Replies

  • CCornerstone - 

    Below is the query which will return you TKB subject by views sorting.

    SELECT subject FROM messages WHERE conversation.style='tkb' ORDER BY metrics.views DESC

     Here is the documentation https://community.lithium.com/t5/Developer-Documentation/bd-p/dev-doc-portal?section=commv2&collection=messages#constraints-conversation.style

    If you just want to get all the tkbs from Boersenlexikon board. You don't need to add conversation.style either. 

     

    SELECT subject FROM messages WHERE board.id='Boersenlexikon' ORDER BY metrics.views DESC

     

  • CCornerstone's avatar
    CCornerstone
    Ace
    8 years ago
    thank you for the quick reply!
    would you perhaps also know the rest-api call? (not lithium query language?)
  • TariqHussain's avatar
    TariqHussain
    Boss
    8 years ago

    CCornerstone - Can you elaborate more? do you want to use this query inside lithium using Freemarker or you want to access from the third server? 

     

     

  • CCornerstone's avatar
    CCornerstone
    Ace
    8 years ago

    of course, sorry for the unspecific question. the data must be accessed from third parties

  • luk's avatar
    luk
    Boss
    8 years ago

    TariqHussain CCornerstone nope, you don't need the OAuth stuff =)...

     

    Paste the code below in an endpoint in Studio > Endpoints and set the endpoint's "View Content Type" to "application/json" in the dropdown below the content field. Then click "View <endpoint.name> Endpoint" to get the link to the endpoint, you will see a gibberish output, that is JSON =)...the developers implementing the data on the third party site will know what to do with it, just send them the link to the endpoint.

     

    <#-- fetch all tkb articles sorted by views, adjust the WHERE conditions as needed, in your case one should be enough as Tariq already stated -->
    <#assign query = "SELECT subject,view_href,metrics FROM messages WHERE board.id = 'Boersenlexikon' AND conversation.style = 'tkb' ORDER BY metrics.views DESC LIMIT 1000"?url />
    <#assign response = restd("2.0", "/search?q=" + query) />
    
    ${response}