Updating user licenses

306 views
Skip to first unread message

Iain Bailey

unread,
Dec 6, 2021, 11:28:04 AM12/6/21
to Google Apps Script Community
I'm probably making a silly mistake here but I can't work out the correct way to update a user license in workspace from the documentation as it only has an example of a newly inserted license.

Inserting a new license for a new user works but I need to update all my current users with new SKU's.

function updateLicense() {

var productId = 'Google-Apps';
var skuId = '1010020026'; //enterprise sku
var userId = 'user...@example.com';
var results = AdminLicenseManager.LicenseAssignments.update(productId, skuId, userId)
Logger.log(results);
}

Throws this error: Exception: Invalid number of arguments provided. Expected 4-5 only
updateLicense
@ License.gs:11

I assume it needs a 4th parameter but the documentation only lists product sku & user.



"(method) Licensing_v1.Licensing.V1.Collection.LicenseAssignmentsCollection.update(resource: Licensing_v1.Licensing.V1.Schema.LicenseAssignment, productId: string, skuId: string, userId: string): Licensing_v1.Licensing.V1.Schema.LicenseAssignment

Reassign a user's product SKU with a different SKU in the same product.

@paramproductId — A product's unique identifier. For more information about products in this version of the API, see Products and SKUs.

@paramskuId — A product SKU's unique identifier. For more information about available SKUs in this version of the API, see Products and SKUs.

@paramuserId — The user's current primary email address. If the user's email address changes, use the new email address in your API requests. Since a userId is subject to change, do not use a userId value as a key for persistent data. This key could break if the current user's email address changes. If the userId is suspended, the license status changes."


any help appreciated.

Thank you

Stephen Barker

unread,
Dec 7, 2021, 11:00:02 AM12/7/21
to Google Apps Script Community
My understanding is update needs a "to" productID/skuId/userId and a "from" productID/skuId/userId kind of like this:

const newData = { 
                                 productId: 'Google-Apps', 
                                 skuId: '1010020026'
                                 userId: 'us...@example.com', 
                                };
var oProductId =  'Google-Apps;
var oSkuId = '1010060003'; 
var oUserId = 'us...@example.com'; 
var updatedLicenseAssignment = AdminLicenseManager.LicenseAssignments .update(newData, oProductId, oSkuId, oUserId);
Logger.log( updatedLicenseAssignment );

If you are just updating SKUs I would use .patch
Reply all
Reply to author
Forward
0 new messages