Bulk Updating End Users API Fails
Hi All,
I am in the process of writing a script in Google Apps Script so that I can bulk update or create End Users via the API but can't seem to make it work. Granted my skills are somewhat lacking but figured i would at least attempt it and learn as I go.
My spreadsheet is starting off simple; I have tried to either create or update 1 or 2 records using the fields name, email, tags and alias.
Below is the code I am trying to use.
-
A brief follow up on this; i have since changed the POST to PUT but still getting invalid endpoints error
-
Another update (I'm like a dog with a bone on this one :-) )
I realised that my endpoint was still wrong and it should be
/api/v2/users/update_many.jsonNow the issue i am getting is this:{ "error": { "title": "Invalid attribute", "message": "You passed an invalid value for the users attribute. Invalid parameter: users must be an array from api/v2/users/update_many" } } -
If this is ever of use to anyone else I have solved my issue with help from Stack Overflow; updated script is below:
function updateManyUsers() {varsheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');var [headers, ...rows] = sheet.getDataRange().getDisplayValues();Logger.log([headers,rows]);varusers = rows.map(r => {vartemp = {};headers.forEach((h, j) => {if (r[j] != "") temp[h] = r[j];});returntemp;});varuser = 'morris.coyle@retacted/token';varpwd = 'redacted';varoptions = {'method': 'PUT','headers': {'Authorization': "Basic " + Utilities.base64Encode(user + ':' + pwd)},'payload': JSON.stringify({ users }),'contentType': 'application/json','muteHttpExceptions': true};varresponse = UrlFetchApp.fetch(url, options);Logger.log(response.getContentText());} -
Hey Morris! I don't have anything helpful to add here, I'm just thrilled to see someone else fighting with Google Apps Script and Zendesk, and that you posted your solution. It took me a week just to get authentication working the first time I tried to set up a script. Thank you for posting this, I've got a project coming up in a similar vein and you just saved me a LOT of time.
Please sign in to leave a comment.
4 Comments