Forum Discussion

CharleneDougal1's avatar
CharleneDougal1
Qrew Member
2 years ago

API_UserRoles

Is there a way to filter API_UserRoles based on Role ID?



------------------------------
Charlene Dougall
------------------------------

6 Replies

  • MarkShnier__You's avatar
    MarkShnier__You
    Qrew #1 Challenger

    Can you explain further what you mean?  What is your use case?



    ------------------------------
    Mark Shnier (Your Quickbase Coach)
    mark.shnier@gmail.com
    ------------------------------
    • CharleneDougal1's avatar
      CharleneDougal1
      Qrew Member

      Yes,  when  I run
      http://target_domain/db/target_dbid?a=API_UserRoles&apptoken=app_token

      I get the following XML result which list all users and their role.  Is there a way to query for certain roles (for example only query role id=18).  Similar how we can query, API_DoQuery.


      <qdbapi>
      <action>API_UserRoles</action>
      <errcode>0</errcode>
      <errtext>No error</errtext>
      <users>
      <user type="user" id="69394206.8yji">
      <name>First Last</name>
      <lastAccess>1679500826997</lastAccess>
      <lastAccessAppLocal>03-22-2023 12:00 PM</lastAccessAppLocal>
      <firstName>First</firstName>
      <lastName>Last</lastName>
      <roles>
      <role id="12">
      <name>Administrator</name>
      <access id="1">Administrator</access>
      </role>
      </roles>
      </user>
      <user type="user" id="84394302.ma9h">
      <name>First1 Last1</name>
      <lastAccess>1671212881400</lastAccess>
      <lastAccessAppLocal>01-16-2023 12:48 PM</lastAccessAppLocal>
      <firstName>First1</firstName>
      <lastName>Last1</lastName>
      <roles>
      <role id="18">
      <name>Officer</name>
      <access id="2">Basic Access with Share</access>
      </role>
      </roles>
      </user>
      </users>
      </qdbapi>



      ------------------------------
      Charlene Dougall
      ------------------------------
      • MarkShnier__You's avatar
        MarkShnier__You
        Qrew #1 Challenger

        Sorry, I don't have an answer.



        ------------------------------
        Mark Shnier (Your Quickbase Coach)
        mark.shnier@gmail.com
        ------------------------------
  • DougHenning1's avatar
    DougHenning1
    Community Manager

    If you're using Pipelines you can use Jinja to filter the data for a specific role.  This code finds all the users with the user role of id 18 in the data in step A:

    {% set users = a.json.qdbapi.users.user -%}
    {% set searchRoleId = '18' -%}
    {% for user in users if (user.roles.role | selectattr("@id", "eq", searchRoleId)|list|count) > 0 or user.roles.role['@id'] == searchRoleId -%}
    {{ user.name }} ({{user["@id"]}}){{ "," if not loop.last }}
    {% endfor -%}
    • Update 1st line with your step letter
    • Update 2nd line with role id to search for
    • The 3rd line is where the filtering happens.  Roles can either be a list or single object, so the if statement handles both of those scenarios.
    • The 4th line is where you can display the user data. In the code above it's retrieving the user name and id and displaying on a new line for each.


    If you're wondering about the 3rd line syntax, the if statement needs to be added as part of the for loop so that the loop counter works correctly.

    Hope that helps!



    ------------------------------
    Doug Henning
    ------------------------------