Not sure this is the correct channel to ask in, bu...
# troubleshoot
b
Not sure this is the correct channel to ask in, but I’ll ask anyways. Is there a way to see the role of a user via the GraphQL API? I’ve been using listUsers to get all the users and can see everything about each apart from their role. Thanks!
g
Yes, there is! You just need to query the corpUser and searchs for Relationships. Example:
Copy code
query {
  corpUser(urn: "urn:li:corpuser:patrick.braz") {
    username
    relationships(input: {
      direction: OUTGOING
      start: 0
      count: 10
      types: "IsMemberOfRole"
    }){
      relationships {
        type
        entity {
          urn
          type
        }
      }
    }
  }
}
Returns:
Copy code
{
  "data": {
    "corpUser": {
      "username": "patrick.braz",
      "relationships": {
        "relationships": [
          {
            "type": "IsMemberOfRole",
            "entity": {
              "urn": "urn:li:dataHubRole:Admin",
              "type": "DATAHUB_ROLE"
            }
          }
        ]
      }
    }
  },
  "extensions": {}
}
And in the Graphiql tab you can see the entities documentation page:
Just access https://<your frontend host>/api/graphiql#
b
Thanks so much Patrick, this works perfectly! I was trying to get the role for all users in the one request, posting the query for anyone else interested:
Copy code
{
  listUsers(input: { start: 0, count:10 }) {
    start
    count
    users {
      urn
      relationships(input: {direction: OUTGOING start:0 count:10 types: "IsMemberOfRole"
      }) {
        relationships {
          type
          entity {
            urn
            type
          }
        }
      }
    }
  }
}