Bulk Updating End Users API Fails

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 

    /api/v2/users/update_many.json
     
    Now 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" } }
    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:

     

    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());
    }
    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

Please sign in to leave a comment.

Powered by Zendesk