LANG SELRCT

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

Saturday, April 27, 2019

node-zendeskでチケットを作成してみる(tickets.create)


この記事では
node-zendeks の  ticket-create.js でチケットを作って行きます


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



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


STEP1:index.jsを書いて保存します
  • username, token, remoteUri は各自の環境に応じたものを入れます
  • subject, body は任意の文字列を設定します

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

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

var ticket = {
    "ticket":
      {
        "subject":"テストタイトルです",
        "comment": {
          "body": "本文です"
        }
      }
    };
  
  client.tickets.create(ticket,  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": 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": [],
  "custom_fields": [
    {
      "id": 360018014474,
      "value": null
    },
    {
      "id": 360018442253,
      "value": null
    },
    {
      "id": 360018495613,
      "value": null
    },
    {
      "id": 360017830594,
      "value": null
    },
    {
      "id": 360018428654,
      "value": null
    }
  ],
  "satisfaction_rating": null,
  "sharing_agreement_ids": [],
  "fields": [
    {
      "id": 360018014474,
      "value": null
    },
    {
      "id": 360018442253,
      "value": null
    },
    {
      "id": 360018495613,
      "value": null
    },
    {
      "id": 360017830594,
      "value": null
    },
    {
      "id": 360018428654,
      "value": null
    }
  ],
  "followup_ids": [],
  "brand_id": ID,
  "allow_channelback": false,
  "allow_attachments": true
}



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