当用Google Enterprise License Manager API插入G Suite licenseAssignment时,错误400 "无效的JSON有效载荷"。

问题描述 投票:2回答:1

我一直在使用 谷歌企业许可管理API 在Google Apps Script中,成功为用户分配G Suite许可证多年。从上周五开始,42420,我就收到了一个 Invalid JSON payload 从API传回的错误。

我创建了这个对象来插入一个许可证分配。

{
  "userId": "[email protected]",
  "productId": "Google-Apps",
  "skuId": "Google-Apps-Unlimited"
}

我使用 UrlFetchApp 来调用谷歌应用脚本的API。

{
  "url": "https://www.googleapis.com/apps/licensing/v1/product/Google-Apps/sku/Google-Apps-Unlimited/user",
  "validateHttpsCertificates": true,
  "followRedirects": true,
  "payload": "{\"userId\":\"[email protected]\",\"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控制台启用了企业许可证管理API。

  • 我使用的是这里定义的正确的API端点URL和路径参数。LicenseAssignments: insert

  • userId, productIdskuId 包含在JSON有效载荷中

  • 我使用的是正确的 productIdskuId 为我们的域名,如这里所定义。谷歌产品和SKU ID

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

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

根据Google的开发者指南,我既在这里提出了这个问题,又提交了一个 发出 在Google Apps Script IssueTracker中。

json google-apps-script gsuite google-license-manager
1个回答
1
投票

根据 文件,有效载荷应只包含 userId. productIdskuId 只是路径参数,包含在url中就可以了。

请求体。

{
  "userId": string
}
© www.soinside.com 2019 - 2024. All rights reserved.