Home > Blockchain >  Zendesk Update Users API From Google Sheets
Zendesk Update Users API From Google Sheets

Time:03-09

I'm going to start by saying it's immensely frustrating half knowing how to do something but never quite being able to finish; this is another one of those projects for me.

Scenario: Using a Google Sheet and Apps Script I am attempting to update several User records in Zendesk using their Logger Output

This is an image of the data in my sheet My Sheet Data

Suplimental: In order to get better at this i would like to put myself on a learning path but am unsure what the path is; most of my automation work and scripting is done using Google Apps script so would people recommend a JavaScript course? I alter between that and Python not knowing what would suit me best to get a better understanding of this kind of issue.

Many thanks in advance.

CodePudding user response:

From your endpoint in your script, I thought that you might have wanted to use "Batch update". Ref If my understanding is correct, the following sample curl in the official document can be used. Ref

curl https://{subdomain}.zendesk.com/api/v2/users/update_many.json \
  -d '{"users": [{"id": 10071, "name": "New Name", "organization_id": 1}, {"external_id": "123", "verified": true}]}' \
  -H "Content-Type: application/json" -X PUT \
  -v -u {email_address}:{password}

If this sample curl command is converted to Google Apps Script using your script, how about the following modification?

Modified script:

function updateManyUsers2() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');
  var [headers, ...rows] = sheet.getDataRange().getDisplayValues();
  var users = rows.map(r => {
    var temp = {};
    headers.forEach((h, j) => {
      if (r[j] != "") temp[h] = r[j];
    });
    return temp;
  });
  var url = 'https://itsupportdesk1611575857.zendesk.com/api/v2/users/update_many.json';
  var user = 'myemailaddresshere/token';
  var pwd = 'mytoken';
  var options = {
    'method': 'PUT',
    'headers': {
      'Authorization': "Basic "   Utilities.base64Encode(user   ':'   pwd)
    },
    'payload': JSON.stringify({ users }),
    'contentType': 'application/json',
    'muteHttpExceptions': true
  };
  var response = UrlFetchApp.fetch(url, options);
  Logger.log(response.getContentText());
}

Note:

  • From the official document, it says Bulk or batch updates up to 100 users.. So, when you want to use more data, please modify the above script. Please be careful about this.

  • If an error occurs, please check the values of users, user and pwd, again.

Reference:

  • Related