LoginSignup
3
3

More than 5 years have passed since last update.

Enterprise Licence Manager APIの実行結果(有償版)

Posted at

GoogleAppsScript Advent Calendar 2015 3日目の記事を受けて実際に実行してみました。
無償版では使えないということで、有償版で実行した結果を載せています。

元記事

Google Apps ScriptでEnterprise Licence Manager APIを叩く
http://qiita.com/ttyokoyama/items/ea8859fef7bdbbe51001

実行前の準備については元記事を参照ください。

ライセンス一覧の取得

※ログ出力の部分を一部変えています。

コード.gs
function myFunction() {
  var pageToken;

  var list = AdminLicenseManager.LicenseAssignments
  .listForProduct('Google-Apps', '<your domain>', {maxResults: 500,
                                                  pageToken: pageToken});

  for(var i = 0; i < list.items.length; i++) {
    Logger.log({
      productId: list.items[i].productId,
      skuId: list.items[i].skuId
    });
    Logger.log("-----------------");
  }
}

実行結果

割り当てているライセンスの一覧が取得できました。
ss1.png

ライセンスの削除

元記事では「これはできない」と記載されていましたが、管理コンソールからお支払い→ライセンスの管理と進んで、自動ライセンス割当を解除したらライセンスを削除することが出来ました。
※こうすればできるよというだけで、通常は自動割当で問題ないと思います。

ss2.png

コード.gs

function deletesample() {
  AdminLicenseManager.LicenseAssignments.remove("Google-Apps", "Google-Apps-Unlimited", "<your account>");
}

なおvoidのため戻り値はありません。

実行結果

実行前
ss3.png

実行後
ss4.png

ライセンスが割り当てられていないと、ログインしてもメールやドライブなどのサービスへのアクセス権がないということで使えません。

ライセンスの更新

第1引数が変更後のライセンスで、後ろは現在のライセンスのproductId,skuIdを渡します。
※実行環境の都合で元記事から変更するライセンスの部分を変えています。

コード.gs
function updatesample() {

  var res = AdminLicenseManager.LicenseAssignments.update({productId: "Google-Vault",
                                                           skuId: "Google-Vault-Former-Employee",
                                                           userId: "<your account>"}
                                                          , "Google-Vault", "Google-Vault", "<your account>");
  Logger.log(res);
}

実行結果

実行前
ss5.png

実行後
ss6.png

まとめ

実行した結果です。
契約によって使えるライセンスが違ったりするので必ずしもサンプルコードで動くとは限りません。

自分はユーザー退職時のアカウント停止自動化で元従業員ライセンスを割り当てる部分を使用しています。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3