Apps Script Addon: How to track admin domain install?

亡梦爱人 提交于 2021-01-28 14:39:48

问题


I'm trying to get the list of emails of users who installed my addon.

I'm using the onInstall trigger to get the email and push it to my database.

This is fine with individual installation (normal gmail or even admin who chooses to Individual Install)

But with Domain Install, onInstall event was not fired

So how can I track the Domain Installation?


回答1:


We can use the LicenseNotification endpoint of the G Suite Marketplace API:

https://developers.google.com/gsuite/marketplace/v2/reference/licenseNotification/list

The result will be something like this:

{
  "kind": "appsmarket#licenseNotificationList",
  "notifications": [
    {
      "kind": "appsmarket#licenseNotification",
      "id": "001566972002228000-000001",
      "applicationId": "xxx",
      "customerId": "test@gmail.com",
      "timestamp": "1566972001590",
      "provisions": [
        {
          "kind": "appsmarket#provisionNotification",
          "editionId": "default_edition",
          "seatCount": "1"
        }
      ]
    },
    {
      "kind": "appsmarket#licenseNotification",
      "id": "001568364120883000-000001",
      "applicationId": "xxx",
      "customerId": "domainabc.com",
      "timestamp": "1568364119585",
      "provisions": [
        {
          "kind": "appsmarket#provisionNotification",
          "editionId": "default_edition",
          "seatCount": "-1"
        }
      ]
    },
    ...
  ],
  "nextPageToken": "001569976724468000-000001"
}

Inside the notifications array, notice some object that has "seatCount": "-1"

Those are domain installations that we are looking for.

We just need to get the value inside "customerId": "domainabc.com",



来源:https://stackoverflow.com/questions/57943614/apps-script-addon-how-to-track-admin-domain-install

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!