LANG SELRCT

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

Sunday, April 28, 2019

node-zendeskでチケット情報を取得してみる(tickets.show)


この記事では
node-zendeks の  tickets.show で
指定したチケットの情報を表示するコードを書いて実行するところまで行きます

node-zendesk を使ったことがない場合はまず Example を試しましょう
node-zendeskを使ってみる(Example)



STEP
  1. index.jsを書いて保存する
  2. index.jsを実行する


STEP1:index.jsを書いて保存します
  • username, token, remoteUri は各自の環境に応じたものを入れます
  • ticketId は対象のチケットIDを指定します

index.js 
var zendesk = require('node-zendesk');

var client = zendesk.createClient({
  username: 'Email',
  token: 'API TOKEN',
  remoteUri: 'https://NAME.zendesk.com/api/v2'
});

var ticketId = 16;
client.tickets.show(ticketId, function(err, req, result) {
  if (err) return handleError(err);
  console.log(JSON.stringify(result, null, 2, true));
});

function handleError(err) {
  console.log(err);
  process.exit(-1);
}



STEP2:実行してみる

ターミナル
index.jsが入っているディレクトリ $ node index.js

zendeskの対象チケットの情報が、このように返ってきました
MacBook-Air-8:nodezendeskTest NAME$ node index.js
{
  "url": "https://NAME.zendesk.com/api/v2/tickets/16.json",
  "id": 16,
  "external_id": null,
  "via": {
    "channel": "api",
    "source": {
      "from": {},
      "to": {},
      "rel": null
    }
  },
  "created_at": "DATETIME",
  "updated_at": "DATETIME",
  "type": null,
  "subject": "テストタイトルです!",
  "raw_subject": "テストタイトルです!",
  "description": "本文です",
  "priority": null,
  "status": "open",
  "recipient": null,
  "requester_id": ID,
  "submitter_id": ID,
  "assignee_id": ID,
  "organization_id": 3 ID,
  "group_id": ID,
  "collaborator_ids": [],
  "follower_ids": [],
  "email_cc_ids": [],
  "forum_topic_id": null,
  "problem_id": null,
  "has_incidents": false,
  "is_public": true,
  "due_at": null,
  "tags": [
    "test1",
    "test2",
    "test3",
    "りんご"
  ],
  "custom_fields": [
    {
      "id": 360018014474,
      "value": "めろん"
    },
    {
      "id": 360018442253,
      "value": ""
    },
    {
      "id": 360018495613,
      "value": ""
    },
    {
      "id": 360017830594,
      "value": ""
    },
    {
      "id": 360018428654,
      "value": "りんご"
    }
  ],
  "satisfaction_rating": null,
  "sharing_agreement_ids": [],
  "fields": [
    {
      "id": 360018014474,
      "value": "めろん"
    },
    {
      "id": 360018442253,
      "value": ""
    },
    {
      "id": 360018495613,
      "value": ""
    },
    {
      "id": 360017830594,
      "value": ""
    },
    {
      "id": 360018428654,
      "value": "りんご"
    }
  ],
  "followup_ids": [],
  "brand_id": ID,
  "allow_channelback": false,
  "allow_attachments": true
}


参考

node-zendesk / ReadMe.md / tickets / show
https://github.com/blakmatrix/node-zendesk#tickets

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...