KiKu
KiKu

Reputation: 377

How to pull only specific OU user data using Admin SDK

How to pull only specific OU user data using Admin SDK

i tried with query: 'orgUnitPath=/Gsuite POC Users', but it generate all users info

Below is my Sample Code

  do {
    page = AdminReports.UserUsageReport.get('all', date, {
      query: 'orgUnitPath=/Gsuite POC Users',
      parameters: parameters.join(','),
      maxResults: 500,
      pageToken: pageToken
    });

Upvotes: 1

Views: 672

Answers (1)

Raserhin
Raserhin

Reputation: 2686

If you look at the official documentation for the endpoint you are using, there is an actual parameter to filter the results for OrgUnit.

orgUnitID string ID of the organizational unit to report on. User activity will be shown only for users who belong to the specified organizational unit.

It will be as easy as to include this parameter:

do {
    page = AdminReports.UserUsageReport.get('all', date, {
      orgUnitId= <<your org ID here>>,
      parameters: parameters.join(','),
      maxResults: 500,
      pageToken: pageToken
    });

You can retrieve the organization units ID of all your units here or directly with the get endpoint if you already know the path.

Upvotes: 2

Related Questions