【问题标题】:Error 400 "Invalid JSON payload" when inserting G Suite licenseAssignment with Google Enterprise License Manager API使用 Google Enterprise License Manager API 插入 G Suite licenseAssignment 时出现错误 400“无效 JSON 负载”
【发布时间】:2020-08-12 17:10:44
【问题描述】:

多年来,我一直在使用 Google Apps 脚本中的 Google Enterprise License Manager API 为用户成功分配 G Suite 许可。自上周五(2020 年 4 月 24 日)以来,我从 API 收到了 Invalid JSON payload 错误。

我创建此对象以插入许可证分配:

{
  "userId": "user@domain.com",
  "productId": "Google-Apps",
  "skuId": "Google-Apps-Unlimited"
}

我使用UrlFetchApp 从 Google Apps 脚本调用 API:

{
  "url": "https://www.googleapis.com/apps/licensing/v1/product/Google-Apps/sku/Google-Apps-Unlimited/user",
  "validateHttpsCertificates": true,
  "followRedirects": true,
  "payload": "{\"userId\":\"user@domain.com\",\"productId\":\"Google-Apps\",\"skuId\":\"Google-Apps-Unlimited\"}",
  "useIntranet": false,
  "headers": {
    "Authorization": "Bearer ya29.xxxx",
    "X-Forwarded-For": "x.x.x.x"
  },
  "method": "post",
  "contentType": "application/json"
}

通常这是有效的,但现在我收到了这个回复:

{
  "error": {
    "code": 400,
    "message": "Invalid JSON payload received. Unknown name \"productId\" at 'body': Cannot find field.\nInvalid JSON payload received. Unknown name \"skuId\" at 'body': Cannot find field.",
    "errors": [
      {
        "message": "Invalid JSON payload received. Unknown name \"productId\" at 'body': Cannot find field.\nInvalid JSON payload received. Unknown name \"skuId\" at 'body': Cannot find field.",
        "reason": "invalid"
      }
    ],
    "status": "INVALID_ARGUMENT"
  }
}

我已经确认:

  • 我们的域有 G Suite Business 许可证,我的帐户是超级管理员帐户,并且我已在 GCP 控制台中启用 Enterprise License Manager API。

  • 我正在使用此处定义的正确 API 端点 URL 和路径参数:LicenseAssignments: insert

  • userIdproductIdskuId 包含在 JSON 有效负载中

  • 我在此处定义的域中使用正确的 productIdskuIdGoogle Product and SKU IDs

  • 用户存在于我们的 G Suite 域中

  • 这会影响我测试过的多个用户,包括有和没有当前许可证分配的用户

根据 Google 的开发者指南,我已经在这里提出了这个问题,并在 Google Apps Script IssueTracker 中提交了issue

【问题讨论】:

  • 顺便说一句,包含所有细节、链接和研究的优秀问题。

标签: json google-apps-script google-license-manager google-workspace


【解决方案1】:

根据documentation,有效负载应仅包含userIdproductIdskuId 只是路径参数,包含在 url 中就足够了。

请求正文:

{
  "userId": string
}

【讨论】:

  • 确实,从有效负载中删除 productIdskuId 有效。我猜它一直被设计为只需要 userId 在正文中,但它以前允许其他两个属性存在但丢弃它们,但现在他们“修复”了它。
猜你喜欢
  • 2021-03-06
  • 2018-07-31
  • 2017-11-26
  • 1970-01-01
  • 2021-02-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多