Forum Discussion

neel_psl's avatar
8 years ago

API to get list of all available Ranks in community?

Is there any API through which i can get list of all available Ranks present in the community?

As i need to show where a specific user is standing among all the Ranks present in the community (like a progress bar).

Also need API to fetch only the Ranks which a user can win in community, without being assigned it manually by some other super users (like Administrator is assigned manually)?

 

Thanks 

9 Replies

  • neel_psl : 

     

    Please find the API Call to get all the list of ranks in the community  "/restapi/vc/ranks/list".

     

    Please refer following Document for more details.

     

    If my post is helpful and answers your question, please give "Kudos" and "Accept it as a Solution."

    Thanks & Regards,
    Abhishek Illindra

  • neel_psl's avatar
    neel_psl
    Ace
    8 years ago
    Thanks, I also tried same API but unable to use it, every time i am using it i am getting an error message, can you please give me an example of how to use this api?
  • VikasB's avatar
    VikasB
    Boss
    8 years ago

    Hi neel_psl  You have to raise a ticket to Lithium support team so they can configure it on your instance. 

  • Really?? I'm speechless... so to actually get a list of all existing ranks we have to contact support even though there is an official API call for it in v1 and v2 and neither of them works properly...

     

    The v1 call to ranks/list asks for a specific user login or id (via URL parameter) which completely defeats it's purpose, I don't want a USER's rank, I want ALL ranks in the community (this time for translation purposes).

     

    <response status="error">
    <error code="306">
    <message>
    A required feature is not configured: user-node-rank.
    </message>
    </error>
    </response>

     

    The v2 call documented here https://community.lithium.com/t5/Developer-Documentation/bd-p/dev-doc-portal?section=commv2&collection=ranks#fields-id just returns an error on a 17.12 (17.12-release r1803051017) community...

     

    {
      "status" : "error",
      "message" : "undefined collection: ranks",
      "data" : {
        "type" : "error_data",
        "code" : 602,
        "developer_message" : "",
        "more_info" : ""
      },
      "metadata" : { }
    }

    SuzieH do you know why this is documented but then throws an error like that? It says nowhere that this has to be custom enabled by support?? I'm simply trying

    SELECT * FROM ranks

    If that's really something that needs to be first enabled by support, please add it to the docs so any confusion and waste of time is avoided in the future.

  • SuzieH's avatar
    SuzieH
    Khoros Alumni (Retired)
    7 years ago

    Hi GlowingBlue_sc,

    We don't provide a v2 API to get a list of all ranks in the Community. I apologize for the confusion in the Ranks collection documentation, The sentence about the Fields table that says "Fields in this table are supported in the SELECT statement of a LiQL query." Is auto-generated, and is a mistake. With v2, you only retrieve ranks for a specific user or a set of users. 

     

    In addition, I spoke with of our Community engineers. The ranks/list endpoint is actually used to retrieve a list of Category Expert Ranks (which is called UserNodeRanks in our code), not User Ranks. I'll be clarifying that in the documentation as well. We have a TKB describing the differences between these features here

  • lilim's avatar
    lilim
    Boss
    7 years ago

    I came across this topic when researching possibilities to export user ranks. I did end up opening a support ticket to ask if it is possible, but unfortunately it is not.

    Please consider voting on my product idea here: Allow user ranks to be exported to CSV

  • luk's avatar
    luk
    Boss
    7 years ago

    Thanks for the idea lilim, upvoted!

     

    Meanwhile I wrote a dirty export script, just execute it within the inspector console on the ranks page in Admin, it will inject a download link called "Export Ranks" which when clicked will give you a text file to download (just rename the .properties file to .csv or .txt or whatever you need, doesn't really matter, its just text):

     

    jQuery('<div id="ranks" />').hide().appendTo('body'); // create fake container for .load() 
    // The ranks are embedded with an iFrame in Admin, and
    // therefore not accessible directly via JS, that means we first have to fetch
    // the content of the iFrame, inject it into the DOM and then work from there...
    jQuery('#ranks').load(jQuery('.lia-component-admin-widget-user-rankings').prop('src') + ' .admin_cell:last', function() {
    
    	var ranks = []; // initialize variable
    	
    	jQuery('#ranks a[href*="edit&ranking.id"]').each(function() {
    		var $item = jQuery(this);
    		
    		var title = $item.parents('td:first').next().text().trim();
    		var id = $item.prop('href').split('=').pop();
    		
    		var output = `rank.${id}.title = ${title}`;
    		
    		ranks.push(output);
    		//console.log(output);
    	});
    	
    	//console.log(ranks.join("\n"));
    	
    	var file = null;
    	var buffer = new Blob([ranks.join("\n")], {type: 'text/plain'});
    	var $link = jQuery('<a href="#" download="ranks.properties">Export Ranks</a>').insertBefore('.lia-component-admin-widget-user-rankings');
    
    	// If we are replacing a previously generated file we need to
    	// manually revoke the object URL to avoid memory leaks.
    	if (file !== null) {
    		window.URL.revokeObjectURL(file);
    	}
    	file = window.URL.createObjectURL(buffer);
    	
    	$link.attr('href', file);
    });

    of course you would need to tailor the output to your needs, I needed it for rank translation, therefore it is generating the proper text keys to overwrite rank names...

     

  • Hi neel_psl finally khoros released a v2 API in its 19.5 version for getting a list of ranks. Simply use the following query: 

    SELECT id FROM ranks WHERE rank_status='active'

    for more details please refer to this  Developer Documentation

    If my post is helpful and answers your question, please give "Kudos" and "Accept it as a Solution."