Forum Discussion

omygoodness's avatar
8 years ago

Absolute URL from view_href

Is it possible to get absolute URL from such query?
SELECT * FROM messages WHERE kudos.sum(weight) > 0 AND author.id='3' ORDER BY kudos.sum(weight) DESC

 

I know it is possible with API v 1 and can be achieved like this:

&restapi.response_style=view

 

but in this case I need to use API v 2 and I have no idea what to do.

6 Replies

  • omygoodness - Yes, check this out here

     

    You need to use this -

     

    <#assign labels = rest(apiVersion, "/search?q=" + labelsQuery?url + "&restapi.response_style=view").data.items![] />

    I hope this helps. 

  • omygoodness's avatar
    omygoodness
    Mentor
    8 years ago

    VarunGrazitti

    Unfortunately it is not working for me.

     

    I did something like this:

     

    <#assign apiVersion = "2.0"/>
    <#assign topKudosQuery = "SELECT * FROM messages WHERE kudos.sum(weight) > 0 AND author.id='3' ORDER BY kudos.sum(weight) DESC" />
    <#assign topKudos = rest(apiVersion, "/search?q=" + topKudosQuery?url + "&restapi.response_style=view").data.items![] />
    
    <#list topKudos as x>
        <div>
            data: ${x.post_time?datetime?string('dd-MM-yyyy HH:mm')}<br>
            tytuł: ${x.subject}<br>
            adres: ${x.view_href}<br>
            ilość wyświetleń: ${x.metrics.views}<br>
            treść: ${x.body?replace("<[^>]*>", "", "r")?replace("&nbsp;", " ", "r")}<br>
            lajki: ${x.kudos.sum.weight}
        </div><br><br>
    
    </#list>

    When I am trying to use: ${x.view_href} I get url like this: /t5/BlaBla/BlaBla/m-p/1896#M1 and when I am trying to use code ${x.@view_href} I get error:

     

    The following has evaluated to null or missing:
    ==> x.@view_href  [in template "latest-kudos-test.ftl" at line 13, column 18]

     

  • omygoodness's avatar
    omygoodness
    Mentor
    8 years ago

    VarunGrazitti This is exactly what I am trying to do but when I use "x.view_href" I get link like this:

     

     /t5/O-spolecznosci/Bialy-czy-Czarny/m-p/1896#M1

    My query looks like this:

     

    <#assign apiVersion = "2.0"/>
    <#assign topKudosQuery = "SELECT * FROM messages WHERE kudos.sum(weight) > 0 AND author.id='3' ORDER BY kudos.sum(weight) DESC" />
    <#assign topKudos = rest(apiVersion, "/search?q=" + topKudosQuery?url + "&restapi.response_style=view").data.items![] />

    Any ideas? 

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

    omygoodness what's the problem with having the relative url? If you're doing the call from inside the community I think it's expected...

  • omygoodness's avatar
    omygoodness
    Mentor
    8 years ago

    ChiaraS Yes it is expected... You are right. I am just testing code as custom endpoints and that is why I have problems with absolute urls...

     

    Thank you :)