Forum Discussion

jeffshurtliff's avatar
5 years ago

Obtain group membership roles for a user across multiple group hubs?

Does any know how best to retrieve the group membership roles for a user across multiple group hubs without making a dozen or more separate API calls?

I am able to confirm membership when querying for a single group hub just fine using the roles collection.

 

QUERY:
SELECT id FROM roles WHERE users.id = '46' AND node.id = 'grouphub:archer-staging'

RESULT:
{
  "status" : "success",
  "message" : "",
  "http_code" : 200,
  "data" : {
    "type" : "roles",
    "list_item_type" : "role",
    "size" : 1,
    "items" : [ {
      "type" : "role",
      "id" : "g:archer-staging:Owner"
    } ]
  },
  "metadata" : { }
}

 

 

However,  despite the developer docs stating that the IN operator is supported for the node.id constraint, when I give it a try I only ever get back the top-level (i.e. community-level) roles and never the membership roles, even if I try passing only one node ID within the IN operator, as shown below.

 

QUERY:
SELECT id FROM roles WHERE users.id = '46' AND node.id IN('grouphub:archer-staging')

RESPONSE:
{
  "status" : "success",
  "message" : "",
  "http_code" : 200,
  "data" : {
    "type" : "roles",
    "list_item_type" : "role",
    "size" : 2,
    "items" : [ {
      "type" : "role",
      "id" : "t:Administrator"
    }, {
      "type" : "role",
      "id" : "t:Employee"
    } ]
  },
  "metadata" : { }
}

 

 

I suppose I could use a custom endpoint but it still feels like there has to be a better way than performing nearly a dozen (or more) separate queries to check for membership across some group hubs.

Anyone ever had to do something like this who has a nifty magic trick they can share? Thanks!!

 

EDIT:  I just stumbled upon the LiQL improvements in the upcoming 20.11 release which will definitely be awesome. But if anyone still has any thoughts of what can be done until that release becomes generally available I’d really appreciate it.

  • SuzieH's avatar
    SuzieH
    5 years ago

    HI jeffshurtliff. Unfortunately, I couldn't come back with a magical solution ğŸ˜•. The team said that we don't currently support node.id IN() and user.id =  together in the same WHERE clause for queries to the roles collection. (I'll have to clarify this in the API docs. I didn't think of your use case when I was writing the examples.) 

    An endpoint might be the way to go. Is the /batch endpoint something that could make the task more efficient/performant?




5 Replies

  • SuzieH's avatar
    SuzieH
    Khoros Alumni (Retired)
    5 years ago
    Hey Jeff. Which version are you on now? I'll bring your question up to the team that worked on that last enhancement to the membership API. Let's see if they have some suggestions.
  • SuzieH's avatar
    SuzieH
    Khoros Alumni (Retired)
    5 years ago

    HI jeffshurtliff. Unfortunately, I couldn't come back with a magical solution ğŸ˜•. The team said that we don't currently support node.id IN() and user.id =  together in the same WHERE clause for queries to the roles collection. (I'll have to clarify this in the API docs. I didn't think of your use case when I was writing the examples.) 

    An endpoint might be the way to go. Is the /batch endpoint something that could make the task more efficient/performant?




  • Hey SuzieH, no worries at all, thanks so much for looking into this for me!  I hadn't thought about using the /batch endpoint for something like this, so that is a great idea and I'll give it a try for sure!

    Thanks again!

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

    Please let me know how it goes. I'm guessing you're not the only one looking for functionality like this.