Forum Discussion

Nath's avatar
Nath
Guide
7 years ago

Sort labels from restapi

Hi,

i config 4 labels in admin with this order : test1, test2, test3, test4

and i use restapi for return my labels : /restapi/vc/boards/id/blog/labels

but the order of result in XML is  : test1, test4, test3, test2

is it possible to find the same order as in the admin ?

 

thanks,

  • Nath

    API returns the sorted results as per their usage count instead of the order in the admin section.  You can check the labels usage count(how many times a label added with any message). You will get test1 > test 4 > test 3> test 2. That's why you are getting the label 'test 2' in last. 

    Actually, API gets the labels from board's messages, not from the admin section. Even label is added in admin section but API does not return the label until it is not added to any message. 

     

    But you can sort it using Freemarker function 

    <#assign getLabels = rest("/boards/id/Learning_Quick_Answers/labels/").labels.label?sort_by("text") />
    <#list getLabels as label>
    ${label.text}
    </#list>

    It will print the labels in expected order

    test 1, test 2, test 3, test 4

     

     

  • Nath

    API returns the sorted results as per their usage count instead of the order in the admin section.  You can check the labels usage count(how many times a label added with any message). You will get test1 > test 4 > test 3> test 2. That's why you are getting the label 'test 2' in last. 

    Actually, API gets the labels from board's messages, not from the admin section. Even label is added in admin section but API does not return the label until it is not added to any message. 

     

    But you can sort it using Freemarker function 

    <#assign getLabels = rest("/boards/id/Learning_Quick_Answers/labels/").labels.label?sort_by("text") />
    <#list getLabels as label>
    ${label.text}
    </#list>

    It will print the labels in expected order

    test 1, test 2, test 3, test 4

     

     

    • Nath's avatar
      Nath
      Guide

      Ok,

      so, how do I get all the labels of a board with LiQL ?

      i can return labels text by board.id ?

       

      • Payal's avatar
        Payal
        Director

        Nath - Please try the below code:

        <#assign getLabels = rest("/boards/id/${board.id}/labels/").labels />
        <#list getLabels.label?reverse as label>
        ${label.text}
        </#list>

         

        Thanks,
        Payal