0

I am currently consuming data from the G Suite API.

An inconvenience I have found is that for some of the APIs the number of resources available might be quite large.

For instance, when I consume the Users:list API (https://www.googleapis.com/admin/directory/v1/users), given the number of resources and the maximum number of results per query I need to perform a significant number of queries. Find below an example JSON response:

 {
  "kind": "admin#directory#users",
  "etag": "\"WqpSTs-zelqnIvn63V............................/v3ENarMfXkTh9ijs3OVkQRoUSVU\"",
  "users": [
    {
      "kind": "admin#directory#user",
      "id": "7720745322191632224007",
      "etag": "\"WqpSTs-zelqnIvn63V........................PfcSmik3zEJwHAl1UbgSk\"",
      "primaryEmail": ...,
      ...
    },
    {
      "kind": "admin#directory#user",
      "id": "227945583287518253104",
      "etag": "\"WqpSTs-zelqnIvn63V..........-zY30eInIGOmLI\"",
      "primaryEmail": ...,
      ...
    },
    ...
    N-users
    ...
  ]
}

I am running this query several times a day.

Ideally I would only retrieve the resources that have changed and the new ones, excluding from the response the ones that have not changed.

Is it possible to do that? If so, how?

Thank you in advance for your answers.

Atenea_v10
  • 87
  • 1
  • 8

1 Answers1

1

You could create custom attributes for your users, and then filter your requests using the query parameter according to your custom attribute.

Or define exactly what you mean by "changed" or "not changed" as the user properties will change on every login to update the last login attribute.

Update:

You can watch for changes on the list of users in your domain by supplying an address to receive notifications in a POST request to the watch endpoint:

https://www.googleapis.com/admin/directory/v1/users/watch


References:

Aerials
  • 4,231
  • 1
  • 16
  • 20
  • by changed/unchanged I mean if there is any way to detect whether each one of the users in the G Suite response (see previous example) has modified (or not) any of its properties. My goal is to prevent checking property by property against the values I already have from previous queries. Maybe the `etag` field could be of use? – Atenea_v10 May 22 '20 at 07:18
  • According to the [docs](https://developers.google.com/admin-sdk/directory/v1/reference/users/watch?hl=zh-tw#request-body) it seems I need to provide an address (an endpoint of my own) in the Request body. For the moment I do not want Google to push data into my services. What I want is to actively pull from Google and look for updates/changes. How could I do that? Thanks. – Atenea_v10 May 22 '20 at 09:46
  • 1
    There is no current method to ask for these changes on-demand. I suppose you would have to supply a time frame for which to receive results between. You can create a Feature Request though at: https://issuetracker.google.com/issues/new?component=191635&template=824102 – Aerials May 22 '20 at 10:20
  • Sorry. I missed your update about the POST request. – Atenea_v10 May 22 '20 at 10:22
  • Thanks again. I am not using POST notifications yet. For the moment I am only pulling data again and again (not very efficient) and I have noticed that the data retrieved from `Users:get` and `Users:list` is not updated at the same time for the same user. I have just checked it with the `lastLoginTime` field. – Atenea_v10 May 22 '20 at 10:34
  • is this possible to do within google apps script? – robquinn Jul 22 '21 at 16:13