Get User Scopes
This query retrieves user scopes and access permissions for the authenticated user. User scopes define which resources and data the current user can access within the Causely platform.
Prerequisite
This example reuses the helper utilities defined in the Authentication and GraphQL Clients sections—fetching an access token, creating the GraphQL client, and sending a request with the post_query wrapper (CLI, Python, or Go). Keep those helpers in scope before running this query.
- python
- javascript
- bash
- go
- graphql
import os
if __name__ == "__main__":
# Get credentials from environment
cid, secret = os.getenv("CAUSELY_CLIENT_ID"), os.getenv("CAUSELY_CLIENT_SECRET")
if not cid or not secret:
raise EnvironmentError("Missing CAUSELY_CLIENT_ID or CAUSELY_CLIENT_SECRET")
# Get access token and create GraphQL client
token = get_causely_access_token(cid, secret)
client = create_graphql_client(token)
# Prepare query variables
variables = {
"filter": {
"nameExpr": ""
}
}
# Execute the query
query = """
query getUserScopes($filter: UserScopeFilter, $first: Int, $after: String, $last: Int, $before: String) {
getUserScopes(
filter: $filter
first: $first
after: $after
last: $last
before: $before
) {
totalCount
edges {
node {
id
name
audience
ownerId
lastUpdate
scopes {
typeName
typeValues
__typename
}
__typename
}
cursor
__typename
}
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
totalCount
__typename
}
__typename
}
}
"""
result = post_query(client, query, variables)
print(result)
const { CAUSELY_CLIENT_ID, CAUSELY_CLIENT_SECRET } = process.env;
if (!CAUSELY_CLIENT_ID || !CAUSELY_CLIENT_SECRET) {
console.error('Missing CAUSELY_CLIENT_ID or CAUSELY_CLIENT_SECRET');
process.exit(1);
}
(async () => {
try {
// Get access token and create GraphQL client
const token = await getCauselyAccessToken(CAUSELY_CLIENT_ID, CAUSELY_CLIENT_SECRET);
const client = createGraphQLClient(token);
// Prepare query variables
const variables = {
filter: {
nameExpr: '',
},
};
// Execute the query
const query = `
query getUserScopes($filter: UserScopeFilter, $first: Int, $after: String, $last: Int, $before: String) {
getUserScopes(
filter: $filter
first: $first
after: $after
last: $last
before: $before
) {
totalCount
edges {
node {
id
name
audience
ownerId
lastUpdate
scopes {
typeName
typeValues
__typename
}
__typename
}
cursor
__typename
}
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
totalCount
__typename
}
__typename
}
}
`;
const result = await postQuery(client, query, variables);
console.log(JSON.stringify(result, null, 2));
} catch (err) {
console.error('Error:', err.message);
process.exit(1);
}
})();
# Set up credentials and get token
export CAUSELY_CLIENT_ID=<YOUR_CLIENT_ID>
export CAUSELY_CLIENT_SECRET=<YOUR_CLIENT_SECRET>
export CAUSELY_ACCESS_TOKEN=$(response=$(curl -s -w "\n%{http_code}" -X POST https://auth.causely.app/frontegg/identity/resources/auth/v2/api-token \
-H "Content-Type: application/json" \
-d "{\"clientId\": \"${CAUSELY_CLIENT_ID}\", \"secret\": \"${CAUSELY_CLIENT_SECRET}\"}"); \
http_code=$(echo "$response" | tail -n1); \
body=$(echo "$response" | sed '$d'); \
if [ "$http_code" = "200" ]; then echo "$body" | jq -r .access_token; else echo "$body" >&2; false; fi)
# Create query and variables files
cat > user_scopes_query.graphql << 'EOF'
query getUserScopes($filter: UserScopeFilter, $first: Int, $after: String, $last: Int, $before: String) {
getUserScopes(
filter: $filter
first: $first
after: $after
last: $last
before: $before
) {
totalCount
edges {
node {
id
name
audience
ownerId
lastUpdate
scopes {
typeName
typeValues
__typename
}
__typename
}
cursor
__typename
}
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
totalCount
__typename
}
__typename
}
}
EOF
cat > user_scopes_variables.json << EOF
{
"filter": {
"nameExpr": ""
}
}
EOF
# Execute the query using gq (if available) or curl
if command -v gq &> /dev/null; then
post_query "user_scopes_query.graphql" "user_scopes_variables.json"
else
query=$(cat user_scopes_query.graphql | tr '\n' ' ')
variables=$(cat user_scopes_variables.json)
post_query_curl "$query" "$variables"
fi
# Clean up temporary files
rm -f user_scopes_query.graphql user_scopes_variables.json
package main
import (
"fmt"
"os"
)
func main() {
// Get credentials from environment
id, secret := os.Getenv("CAUSELY_CLIENT_ID"), os.Getenv("CAUSELY_CLIENT_SECRET")
if id == "" || secret == "" {
fmt.Fprintln(os.Stderr, "Missing CAUSELY_CLIENT_ID or CAUSELY_CLIENT_SECRET")
os.Exit(1)
}
// Get access token and create GraphQL client
token, err := getToken(id, secret, "https://auth.causely.app/frontegg/identity/resources/auth/v2/api-token")
if err != nil {
fmt.Fprintln(os.Stderr, "Error getting token:", err)
os.Exit(1)
}
client := createGraphQLClient(token)
// Prepare query variables
variables := map[string]interface{}{
"filter": map[string]interface{}{
"nameExpr": "",
},
}
// Execute the query
query := `query getUserScopes($filter: UserScopeFilter, $first: Int, $after: String, $last: Int, $before: String) {
getUserScopes(
filter: $filter
first: $first
after: $after
last: $last
before: $before
) {
totalCount
edges {
node {
id
name
audience
ownerId
lastUpdate
scopes {
typeName
typeValues
__typename
}
__typename
}
cursor
__typename
}
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
totalCount
__typename
}
__typename
}
}`
result, err := postQuery(client, query, variables)
if err != nil {
fmt.Fprintln(os.Stderr, "Error running query:", err)
os.Exit(1)
}
fmt.Println(result)
}
query getUserScopes($filter: UserScopeFilter, $first: Int, $after: String, $last: Int, $before: String) {
getUserScopes(filter: $filter, first: $first, after: $after, last: $last, before: $before) {
totalCount
edges {
node {
id
name
audience
ownerId
lastUpdate
scopes {
typeName
typeValues
__typename
}
__typename
}
cursor
__typename
}
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
totalCount
__typename
}
__typename
}
}
Variables:
{
"filter": {
"nameExpr": ""
}
}