Enterprise License Manager API:開發人員指南

本文說明帳戶層級和經銷商管理員可以如何使用 Enterprise License Manager API 管理使用者授權指派作業。在您啟用帳戶的產品 SKU 授權並建立使用者之後,請使用 Enterprise License Manager API 為帳戶中的使用者指派、更新、擷取及刪除授權。

在此版本中,帳戶和經銷商管理員使用 Enterprise License Manager API。具備 License Management 權限的委派管理員也可以使用 Enterprise License Manager API。

注意:Google 客戶使用的是 Enterprise License Manager API。如要瞭解 Google 第三方應用程式開發人員如何管理授權,請參閱 Google Workspace Marketplace API

Enterprise License Manager API 是以 Representational State Transfer (符合 REST 樣式) 的網路服務設計方法為基礎。

管理授權

指派授權

在進行這項作業之前,客戶或經銷商已訂購 Google 產品授權並建立了使用者。如要將其中一項產品授權指派給這位使用者,請使用下列 POST HTTP 要求。按照授權要求的說明加入 Authorization 標頭。如需產品和 SKU ID 的相關資訊,請參閱該 API 提供的產品與 SKU

POST https://www.googleapis.com/apps/licensing/v1/product/productId/sku/skuId/user

注意:您可以為使用者指派各種 Google 產品的授權。但使用者一次只能為每項產品指派一個 SKU 授權。使用 API 即可將使用者的 SKU 授權重新指派給該產品中的其他 SKU 授權。

以下範例將 Google-Drive-storage-20GB SKU 指派給主要電子郵件地址為 alex@example.com 的使用者:

POST https://www.googleapis.com/apps/licensing/v1/product/Google-Drive-storage/sku/Google-Drive-storage-20GB/user

JSON 要求主體:

{
  "userId" : "alex@example.com",
}

成功的回應會傳回 200 HTTP 狀態碼。如需可能的錯誤代碼,請參閱 API 的錯誤代碼。如果成功,回應會傳回 JSON 資料格式的授權指派狀態。

JSON 回應

{
  "kind": "licensing#licenseAssignment",
  "etags": "etag value",
  "selfLink": "https://www.googleapis.com/apps/licensing/v1/product/Google-Drive-storage/sku/Google-Drive-storage-20GB/user/alex@example.com",
  "userId": "alex@example.com",
  "productId": "Google-Drive-storage",
  "skuId": "Google-Drive-storage-20GB",
  "skuName": "Google Drive storage 20 GB",
  "productName": "Google Drive storage"
}

詳情請參閱 LicenseAssignments 插入方法參考資料頁面。

為同一產品中使用不同的 SKU 重新指派使用者的產品 SKU

如要將使用者的授權重新指派給同一產品中的新授權 SKU,請使用下列 PUT HTTP 要求。API 也支援修補語法。按照授權要求的說明加入 Authorization 標頭。如需產品和 SKU ID 的相關資訊,請參閱該 API 提供的產品與 SKU

PUT https://www.googleapis.com/apps/licensing/v1/product/productId/sku/the current skuId/user/user's email

本範例將現有的 Google-Drive-storage-20GB SKU 更新為 Google-Drive-storage-50GB。目前的授權 SKU 位於要求的 URI 中,而新的授權 SKU 位於要求的主體中:

PUT https://www.googleapis.com/apps/licensing/v1/product/Google-Drive-storage/sku/Google-Drive-storage-20GB/user/alex@example.com

JSON 要求主體含有:

{
  "kind": "licensing#licenseAssignment",
  "etags": "etag value",
  "selfLink": "https://www.googleapis.com/apps/licensing/v1/product/Google-Drive-storage/sku/Google-Drive-storage-50GB/user/alex@example.com",
  "userId": "alex@example.com",
  "productId": "Google-Drive-storage",
  "skuId": "Google-Drive-storage-50GB",
  "skuName": "Google Drive storage 50 GB",
  "productName": "Google Drive storage"
}

成功的回應會傳回 200 HTTP 狀態碼。如需可能的錯誤代碼,請參閱 API 的錯誤代碼。如果成功,回應會傳回 JSON 資料格式的授權指派狀態。

JSON 回應

{
  "kind": "licensing#licenseAssignment",
  "etags": "etag value",
  "selfLink": "https://www.googleapis.com/apps/licensing/v1/product/Google-Drive-storage/sku/Google-Drive-storage-50GB/user/alex@example.com",
  "userId": "alex@example.com",
  "productId": "Google-Drive-storage",
  "skuId": "Google-Drive-storage-50GB",
  "skuName": "Google Drive storage 50 GB",
  "productName": "Google Drive storage"
}

詳情請參閱 LicenseAssignments 的更新方法修補方法參考頁面。

擷取所有指派給特定產品授權的使用者

如要取得特定產品的所有使用者授權,請使用下列 GET HTTP 要求。按照授權要求的說明加入 Authorization 標頭。customerId 查詢字串是客戶的主網域名稱。maxResults 查詢字串會決定要在 API 回應中傳回多少使用者授權項目:

GET https://www.googleapis.com/apps/licensing/v1/product/productId/users?customerId=primary domain name&maxResults=max results per page

如需產品和 SKU ID,請參閱 API 提供的產品與 SKU

以下範例會列出 example.com 網域中指派給 Google 雲端硬碟儲存空間產品授權的所有使用者,結果第一頁:

GET https://www.googleapis.com/apps/licensing/v1/product/Google-Drive-storage/users?customerId=example.com&maxResults=2

成功的回應會傳回 200 HTTP 狀態碼。如需可能的錯誤代碼,請參閱 API 的錯誤代碼。如果成功,回應會傳回 JSON 格式的授權清單。

JSON 回應

{
  "kind" : "licensing#licenseAssignmentList",
  "etag": "etag value",
  "nextPageToken" : "the next page token value",
  "items": [
  {
    "kind": "licensing#licenseAssignment",
    "etags": "etag value",
    "selfLink": "https://www.googleapis.com/apps/licensing/v1/product/Google-Drive-storage/sku/Google-Drive-storage-50GB/user/alex@example.com",
    "userId": "alex@example.com",
    "productId": "Google-Drive-storage",
    "skuId": "Google-Drive-storage-50GB",
    "skuName": "Google Drive storage 50 GB",
    "productName": "Google Drive storage"
  },
  {
    "kind": "licensing#licenseAssignment",
    "etags": "etag value",
    "selfLink": "https://www.googleapis.com/apps/licensing/v1/product/Google-Drive-storage/sku/Google-Drive-storage-200GB/user/keshav@example.com",
    "userId": "keshav@example.com",
    "productId": "Google-Drive-storage",
    "skuId": "Google-Drive-storage-200GB",
    "skuName": "Google Drive storage 200 GB",
    "productName": "Google Drive storage"
  },
  ...
}

詳情請參閱 LicenseAssignments 的 listForProduct method 參考頁面。

擷取指派給特定產品 SKU 的所有使用者

如要取得具備特定產品 SKU 授權的所有使用者清單,請使用以下 GET HTTP 要求。按照授權要求的說明加入 Authorization 標頭。customerId 查詢字串是客戶的主網域名稱。maxResults 查詢字串會判斷 API 回應中傳回的使用者項目數量:

GET https://www.googleapis.com/apps/licensing/v1/product/productId/sku/skuId/users?customerId=primary domain name&maxResults=max results per response page

如需產品和 SKU ID,請參閱 API 提供的產品與 SKU

這個範例傳回 example.com 網域中所有獲派 Google-Drive-storage-200GB SKU 授權的使用者第一頁。此回應會在每個網頁上列出兩個使用者項目:

GET https://www.googleapis.com/apps/licensing/v1/product/Google-Drive-storage/sku/Google-Drive-storage-200GB/users?customerId=example.com&maxResults=2

成功的回應會傳回 200 HTTP 狀態碼。如需可能的錯誤代碼,請參閱 API 的錯誤代碼。如果成功,回應會傳回 JSON 格式的授權清單。

JSON 回應

{
  "kind" : "licensing#licenseAssignmentList",
   "etag": "etag value",
   "nextPageToken" : "next page token's value",
   "items": [
    {
     "kind": "licensing#licenseAssignment",
     "etags": "etag value",
     "selfLink": "https://www.googleapis.com/apps/licensing/v1/product/Google-Drive-storage/sku/Google-Drive-storage-200GB/user/alex@example.com",
     "userId": "alex@example.com",
     "productId": "Google-Drive-storage",
     "skuId": "Google-Drive-storage-200GB",
     "skuName": "Google Drive storage 200 GB",
     "productName": "Google Drive storage"
    },
    {
     "kind": "licensing#licenseAssignment",
     "etags": "etag value",
     "selfLink": "https://www.googleapis.com/apps/licensing/v1/product/Google-Drive-storage/sku/Google-Drive-storage-200GB/user/mary@example.com",
     "userId": "mary@example.com",
     "productId": "Google-Drive-storage",
     "skuId": "Google-Drive-storage-200GB",
     "skuName": "Google Drive storage 200 GB",
     "productName": "Google Drive storage"
    },
    ...
  }

詳情請參閱 LicenseAssignments 的 listForProductAndSku 方法參考頁面。

依產品 SKU 擷取特定使用者的授權

如要依產品 SKU 取得特定使用者的授權,請使用以下 GET HTTP 要求。按照授權要求的說明加入 Authorization 標頭。如要瞭解產品和 SKU ID,請參閱該 API 提供的產品與 SKU

GET https://www.googleapis.com/apps/licensing/v1/product/productId/sku/skuId/user/userId

以下示例為 userId 為 alex@example.com 的使用者取得 50 GB 產品 SKU 的 Google 雲端硬碟儲存空間:

GET https://www.googleapis.com/apps/licensing/v1/product/Google-Drive-storage/sku/Google-Drive-storage-50GB/user/alex@example.com

如果使用者擁有這個授權,則代表成功的回應及 200 HTTP 狀態碼。如需可能的錯誤代碼,請參閱 API 的錯誤代碼。如果成功,回應會以 JSON 格式傳回使用者的授權。

JSON 回應

{
  "kind": "licensing#licenseAssignment",
  "etag": "etag value",
  "selfLink": "https://www.googleapis.com/apps/licensing/v1/product/Google-Drive-storage/sku/Google-Drive-storage-50GB/user/alex@example.com",
  "userId": "keshav@example.com",
  "productId": "Google-Drive-storage",
  "skuId": "Google-Drive-storage-50GB",
  "skuName": "Google Drive storage 50 GB",
  "productName": "Google Drive storage"
}

詳情請參閱 LicenseAssignments get method 參考頁面。

刪除授權

如要取消指派使用者的授權,請使用下列 DELETE HTTP 要求。按照授權要求的說明加入 Authorization 標頭。如要瞭解產品和 SKU ID,請參閱該 API 提供的產品與 SKU

DELETE https://www.googleapis.com/apps/licensing/v1/product/productId/sku/skuId/user/userId

以下示例為取消指派給 userId 為 alex@example.com 的使用者 Google-Drive-storage-50GB 授權:

DELETE https://www.googleapis.com/apps/licensing/v1/product/Google-Drive-storage/sku/Google-Drive-storage-50GB/user/alex@example.com

成功的回應會傳回 200 HTTP 狀態碼。如需可能的錯誤代碼,請參閱 API 的錯誤代碼

詳情請參閱 LicenseAssignments 刪除方法參考資料頁面。

錯誤代碼

如果要求失敗,回應中會簡要說明錯誤:

錯誤代碼 說明
400 要求無效 - 使用者電子郵件地址無效。
400 錯誤的要求 - SKU/產品不存在。
401 執行者沒有憑證,無法呼叫這個 API。
404 如果使用者沒有此授權,回應中會包含「找不到」錯誤代碼。
412 不符合先決條件。如要進一步瞭解這個錯誤,請查看 message 欄位。例如:
  • Auto License switching is not allowed.
  • Auto License un-assignment is not allowed.
  • For reassign operations, the new SKU should be different from the old SKU: sku
  • Reassign operation can't be performed on different products: product1, product2
  • Reassign operation can't be performed on different users: user1, user2
  • There aren't enough available licenses for the specified product-SKU pair
  • User already has a license for the specified product and SKU
  • User already has a license of the product, but with a different SKU. To reassign a new SKU for this product, use the 'update' operation.
503 無法使用授權管理員服務。