Search code examples
jsongoogle-apps-scriptgoogle-license-managergoogle-workspace

Error 400 "Invalid JSON payload" when inserting G Suite licenseAssignment with Google Enterprise License Manager API


I've been using the Google Enterprise License Manager API in Google Apps Script to assign G Suite licenses to users successfully for years. Since last Friday, 4/24/20 I've been getting an Invalid JSON payload error back from the API.

I create this object to insert a license assignment:

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

I use UrlFetchApp to call the API from Google Apps Script:

{
  "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"
}

Normally this works but now I've been getting back this response:

{
  "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"
  }
}

I have confirmed that:

  • Our domain has G Suite Business licenses, my account is a Super Admin account, and I have enabled the Enterprise License Manager API in the GCP console.

  • I am using the correct API endpoint URL and path parameters defined here: LicenseAssignments: insert

  • userId, productId and skuId are included in the JSON payload

  • I am using the correct productId and skuId for our domain as defined here: Google Product and SKU IDs

  • The user exists in our G Suite domain

  • This affects multiple users that I have tested with, both users with and without current license assignments

As per Google's Developer guidelines I've both asked this question here and submitted an issue in the Google Apps Script IssueTracker.


Solution

  • As per documentation, the payload should only contain userId. productId and skuId are just path parameters and including it in the url should be enough.

    Request Body:

    {
      "userId": string
    }