Recent searches
No recent searches
Bulk Updating End Users API Fails
Answered
Posted Mar 07, 2022
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.
function UpdateUsers(){
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');
var [headers, ...rows] = sheet.getDataRange().getValues();
vardata = {}
varitems = []
rows.forEach(function(r) {
varobj={}
r.forEach(function (c, j) {
obj[headers[j]] = c
})
vardata = {}//moved
data['users'] = obj// moved this inside your loop
items.push(data) // pushed the object into the items array
})
Logger.log("Log JSON Stringify Items: " + JSON.stringify(items))
items.forEach(function(i) { // added this to loop over objects in items
varuser = 'myemailaddresshere/token';
varpwd = 'mytokenhere';
varoptions = {
'method' : 'post',
'headers': {
'Authorization': "Basic " + Utilities.base64Encode(user + ':' + pwd)
},
'payload' : JSON.stringify(i),
'contentType': 'application/json',
'muteHttpExceptions': true
};
UrlFetchApp.fetch(url, options);
Logger.log(i)
varresponse = UrlFetchApp.fetch(url, options);
Logger.log(response);
})
}
The error being returned is: {"error":"InvalidEndpoint","description":"Not found"}
1
4
4 comments
Morris Coyle
A brief follow up on this; i have since changed the POST to PUT but still getting invalid endpoints error
1
Morris Coyle
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
1
Morris Coyle
If this is ever of use to anyone else I have solved my issue with help from Stack Overflow; updated script is below:
1
CJ Johnson
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.
0