Forum Discussion

Natkinson's avatar
Natkinson
Genius
3 years ago

Set User Rank via API

We recently updated our ranking system and use some custom ranking formulas for our new ranks. However, we have some longtime users who didn't meet all of our new criteria so they were "demoted" to a lower rank. We're hoping to grandfather these users into their old rank, but it seems like there's not any way to do that. There's no way I've found in the settings or rank settings and I've tried with a few users via the API with no luck. Does anyone know of a way to do this for a list of users that we want to manually change their rank even if they don't meet all the formula requirements? Or will the formula requirements keep us from changing their rank manually?

Here's the code I'm using to try to change the rank manually. I get a success message when I run this, but the rank doesn't change:

const options = {
  method: 'PUT',
  headers: {Accept: 'application/json', 'Content-Type': 'application/json'},
  body: JSON.stringify({
    data: {
      type: 'user',
      rank: {id: '9'}
    }
  })
};

fetch('https://community.url.com/api/2.0/users/user-id', options)
  .then(response => response.json())
  .then(response => console.log(response))
  .catch(err => console.error(err));

 (I've changed our url and user-id for privacy, but I'm using the correct values in the code I'm running) 

  • AdamN's avatar
    AdamN
    3 years ago

    I think Stan has the right idea. As Stan pointed out, you can't directly set ranks via the API or otherwise; it's all managed through the rank structure itself, so the rank structure would need to be built to account for this.

    How easy or hard this is will likely depend on how your rank formulas are constructed:

    • If your formula is essentially a series of AND evaluations (e.g. posts > 10 && net_kudos_events_received > 5 && tagging_tag_count > 3 && ...) then you'll probably need some kind of special case added in as an OR logic, or as Stan suggested have separate parallel ranks for the legacy users based on role or some other criteria unique to these users.
    • If your formula is doing some kind of math calculation to total some kind of "points" system (e.g. posts*1.4 + net_kudos_events_received*3 +tagging_tag_count*0.7 > 24), then one option would be to use the Bonus Points ("arbitrary_points" in your rank formula) to give these legacy users a boost to meet some minimum ranking threshold.
  • I don't think there is any way to turn off ranking per se.  You would have to probably do some time intensive workarounds such as duplicating your entire rank structure, the duplicates of each rank using a 'requires role X' for each.  Then all the legacy users you want a specific rank for, put them into the appropriate roles to make it all work.

    edit: Words (and edit for words again)

    • AdamN's avatar
      AdamN
      Khoros Oracle

      I think Stan has the right idea. As Stan pointed out, you can't directly set ranks via the API or otherwise; it's all managed through the rank structure itself, so the rank structure would need to be built to account for this.

      How easy or hard this is will likely depend on how your rank formulas are constructed:

      • If your formula is essentially a series of AND evaluations (e.g. posts > 10 && net_kudos_events_received > 5 && tagging_tag_count > 3 && ...) then you'll probably need some kind of special case added in as an OR logic, or as Stan suggested have separate parallel ranks for the legacy users based on role or some other criteria unique to these users.
      • If your formula is doing some kind of math calculation to total some kind of "points" system (e.g. posts*1.4 + net_kudos_events_received*3 +tagging_tag_count*0.7 > 24), then one option would be to use the Bonus Points ("arbitrary_points" in your rank formula) to give these legacy users a boost to meet some minimum ranking threshold.
      • Natkinson's avatar
        Natkinson
        Genius

        Thanks StanGromer and AdamN for your responses! The API docs for updating a user made it seem like we could update, but looks like that's not the case.

        We did end up using bonus points as a big OR part of the formula (all this formula stuff OR X number of bonus points) since we don't use bonus points for anything else.

  • Keep in mind if needed, Support can create custom profile attributes for you on the user. Like bonus points, they work with ranks/badge formulas, so great way to further segment down the users if needed.