curl --request GET \
--url 'https://YOURSITE.konstant.ly/openapi/v1/users/1234567890/groups' \
--header 'X-API-KEY: 1qaz2wsx3edc4rfv1qaz2wsx3edc4rfv'
import requests
from typing import List, Dict
def get_user_groups(api_key: str, user_id: str) -> List[Dict]:
url = f"https://YOURSITE.konstant.ly/openapi/v1/users/{user_id}/groups"
headers = {"X-API-KEY": api_key}
response = requests.get(url, headers=headers)
if response.status_code == 404:
raise ValueError(f"User {user_id} not found")
response.raise_for_status()
return response.json()['groups']
# Example usage
try:
groups = get_user_groups("1qaz2wsx3edc4rfv1qaz2wsx3edc4rfv", "1234567890")
print(f"User belongs to {len(groups)} groups:")
for group in groups:
print(f" - {group['name']} (ID: {group['id']})")
except Exception as e:
print(f"Failed to fetch user groups: {str(e)}")
const axios = require('axios');
async function getUserGroups(apiKey, userId) {
try {
const response = await axios.get(
`https://YOURSITE.konstant.ly/openapi/v1/users/${userId}/groups`,
{
headers: { 'X-API-KEY': apiKey }
}
);
return response.data.groups;
} catch (error) {
if (error.response?.status === 404) {
throw new Error(`User ${userId} not found`);
}
throw error;
}
}
// Example usage
getUserGroups('1qaz2wsx3edc4rfv1qaz2wsx3edc4rfv', '1234567890')
.then(groups => {
console.log(`User belongs to ${groups.length} groups:`);
groups.forEach(group => {
console.log(` - ${group.name} (ID: ${group.id})`);
});
})
.catch(error => console.error('Failed:', error.message));
{
"groups": [
{
"id": 1,
"parentId": null,
"name": "Sales Team",
"usersCount": 15,
"coursesCount": 5,
"image": null,
"attributes": {}
},
{
"id": 2,
"parentId": 1,
"name": "Regional Sales - London",
"usersCount": 8,
"coursesCount": 3,
"image": null,
"attributes": {}
}
]
}
{
"status": 404,
"message": "Not found"
}
Users
List User Groups
List the groups the user belongs to
GET
/
users
/
{userId}
/
groups
curl --request GET \
--url 'https://YOURSITE.konstant.ly/openapi/v1/users/1234567890/groups' \
--header 'X-API-KEY: 1qaz2wsx3edc4rfv1qaz2wsx3edc4rfv'
import requests
from typing import List, Dict
def get_user_groups(api_key: str, user_id: str) -> List[Dict]:
url = f"https://YOURSITE.konstant.ly/openapi/v1/users/{user_id}/groups"
headers = {"X-API-KEY": api_key}
response = requests.get(url, headers=headers)
if response.status_code == 404:
raise ValueError(f"User {user_id} not found")
response.raise_for_status()
return response.json()['groups']
# Example usage
try:
groups = get_user_groups("1qaz2wsx3edc4rfv1qaz2wsx3edc4rfv", "1234567890")
print(f"User belongs to {len(groups)} groups:")
for group in groups:
print(f" - {group['name']} (ID: {group['id']})")
except Exception as e:
print(f"Failed to fetch user groups: {str(e)}")
const axios = require('axios');
async function getUserGroups(apiKey, userId) {
try {
const response = await axios.get(
`https://YOURSITE.konstant.ly/openapi/v1/users/${userId}/groups`,
{
headers: { 'X-API-KEY': apiKey }
}
);
return response.data.groups;
} catch (error) {
if (error.response?.status === 404) {
throw new Error(`User ${userId} not found`);
}
throw error;
}
}
// Example usage
getUserGroups('1qaz2wsx3edc4rfv1qaz2wsx3edc4rfv', '1234567890')
.then(groups => {
console.log(`User belongs to ${groups.length} groups:`);
groups.forEach(group => {
console.log(` - ${group.name} (ID: ${group.id})`);
});
})
.catch(error => console.error('Failed:', error.message));
{
"groups": [
{
"id": 1,
"parentId": null,
"name": "Sales Team",
"usersCount": 15,
"coursesCount": 5,
"image": null,
"attributes": {}
},
{
"id": 2,
"parentId": 1,
"name": "Regional Sales - London",
"usersCount": 8,
"coursesCount": 3,
"image": null,
"attributes": {}
}
]
}
{
"status": 404,
"message": "Not found"
}
Retrieve a list of all groups that a specific user is a member of.
Request Headers
API Key. Go to your Konstantly site > Settings > API and copy the value from there.
URL Parameters
User API ID
Response
Array of groups the user belongs to
Show Group object properties
Show Group object properties
Group ID
Parent group ID
Group name
Number of users in the group
Number of courses assigned to the group
Custom group attributes
Error Responses
curl --request GET \
--url 'https://YOURSITE.konstant.ly/openapi/v1/users/1234567890/groups' \
--header 'X-API-KEY: 1qaz2wsx3edc4rfv1qaz2wsx3edc4rfv'
import requests
from typing import List, Dict
def get_user_groups(api_key: str, user_id: str) -> List[Dict]:
url = f"https://YOURSITE.konstant.ly/openapi/v1/users/{user_id}/groups"
headers = {"X-API-KEY": api_key}
response = requests.get(url, headers=headers)
if response.status_code == 404:
raise ValueError(f"User {user_id} not found")
response.raise_for_status()
return response.json()['groups']
# Example usage
try:
groups = get_user_groups("1qaz2wsx3edc4rfv1qaz2wsx3edc4rfv", "1234567890")
print(f"User belongs to {len(groups)} groups:")
for group in groups:
print(f" - {group['name']} (ID: {group['id']})")
except Exception as e:
print(f"Failed to fetch user groups: {str(e)}")
const axios = require('axios');
async function getUserGroups(apiKey, userId) {
try {
const response = await axios.get(
`https://YOURSITE.konstant.ly/openapi/v1/users/${userId}/groups`,
{
headers: { 'X-API-KEY': apiKey }
}
);
return response.data.groups;
} catch (error) {
if (error.response?.status === 404) {
throw new Error(`User ${userId} not found`);
}
throw error;
}
}
// Example usage
getUserGroups('1qaz2wsx3edc4rfv1qaz2wsx3edc4rfv', '1234567890')
.then(groups => {
console.log(`User belongs to ${groups.length} groups:`);
groups.forEach(group => {
console.log(` - ${group.name} (ID: ${group.id})`);
});
})
.catch(error => console.error('Failed:', error.message));
{
"groups": [
{
"id": 1,
"parentId": null,
"name": "Sales Team",
"usersCount": 15,
"coursesCount": 5,
"image": null,
"attributes": {}
},
{
"id": 2,
"parentId": 1,
"name": "Regional Sales - London",
"usersCount": 8,
"coursesCount": 3,
"image": null,
"attributes": {}
}
]
}
{
"status": 404,
"message": "Not found"
}
Was this page helpful?
⌘I