LANG SELRCT

Apps Script Reference  (Create: Create new Spreadsheet | Create new Apps Script

Wednesday, April 3, 2019

zendeskのAPI TOKENを取得したい(base64にエンコードする)


歯車アイコン > API > Enabled > +ボタン


API Token Descriptionに任意の説明を入力します
API Token をCopyします



zendeskのAPIをたたくときのAuthorizationは Basic " + base64_token という形らしい
    "headers": {
      "Content-type": "application/json",
      "Authorization": " Basic " + base64_token
    }


token は email + "/token:" + zendesk_api_token という形のようなので
Generating a new API token にあるようにbase64エンコードしてやる


それを実現するコード


コード.gs
function createBase64Token() {
  var token = Utilities.base64Encode(getProp('email') + '/token:' + getProp('zendesk_token'));
  Logger.log(token);
  return token;
}

function getProp(key) {
  return PropertiesService.getScriptProperties().getProperty(key);
}


これをそのままbase64_tokenに返しても良いですが、都度エンコードする必要もないので、スクリプトのプロパティに保存して呼んだ方が良いかも。


参考

Generating a new API token
https://support.zendesk.com/hc/en-us/articles/226022787-Generating-a-new-API-token-
Authorization: "Basic (base-64-encoded username/token:API_TOKEN_HERE)"


APIリクエストの認証
https://support.zendesk.com/hc/en-us/articles/115000510267-Authentication-for-API-requests

Latest post

Extracting data from Google Sheets with regular expressions

Introduction Regular expressions are a powerful tool that can be used to extract data from text.  In Google Sheets, regular expressions ca...