<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-M74D8PB" height="0" width="0" style="display:none;visibility:hidden">
Loading
Skip to NavigationSkip to Main Content

Use the Okta API to Return the Number of Users in a Group

Lifecycle Management
Okta Classic Engine
Okta Identity Engine

Overview

Return the number of users in a group using the Okta API by adding the expand=stats query parameter to a GET request. This parameter prompts Okta to return additional details about the group in the response, including the user count.

Applies To

  • Okta Identity Engine (OIE)
  • Okta Classic Engine
  • Okta API
  • Groups

Solution

How is the number of users in a group returned using the Okta API?

 

Add the query parameter expand=stats to the GET request to prompt Okta to return additional details about the group in the response.

Review the following request examples for retrieving the user count for all groups, filtered groups, or a specific group based on the group ID.

# ALL groups
GET https://{OktaDomainName}.com/api/v1/groups?limit=100&expand=stats

# Groups matching filter criteria
GET https://{OktaDomainName}.com/api/v1/groups?filter=lastMembershipUpdated gt 2017-04-17T23:16:50.000Z &expand=stats

# Specific group based on Group ID (gid)
GET https://{OktaDomainName}.com/api/v1/groups/00gwXXXXXXXXXXX?expand=stats

 

Review the following response example displaying the user count in the statistics section.

[
{
  "id": "00gwXXXXXXXXXXX",
  "lastUpdated": "2017-03-31T23:16:50.000Z",
  "lastMembershipUpdated": "2017-04-17T23:16:50.000Z",
"...": "...",
  "type": "APP_GROUP",
  "...": "...",
  "profile": {
    "name": "Domain Group 1",
    "...": "...",
    "externalId": "nYGXXXXXXXXXXX=="
  },
  "_embedded": {
  "stats": {
    "usersCount": 301,
    "appCount": 0,
    "groupPushMappingsCount": 0,
    "...": "..."
  }
},
  "...": "..."
},
{}
]

Display app-sourced groups in addition to the user count.

 

Add the app option to the query parameter to display app-sourced groups alongside the user count.

Review the following request example for retrieving all groups with the application and statistics parameters expanded.

# ALL groups
GET https://{OktaDomainName}.com/api/v1/groups?limit=100&expand=app,stats

Related References

Recommended content

Documentation
Functions
Documentation
Search Groups
Documentation
Find Groups
Loading
Use the Okta API to Return the Number of Users in a Group | Okta Support