この記事では
node-zendeks の search.query で
カスタムフィールドの値を検索するコードを書いて実行するところまで行きます
node-zendesk を使ったことがない場合はまず Example を試しましょう
node-zendeskを使ってみる(Example)
STEP
- index.jsを書いて保存する
- index.jsを実行する
STEP1:index.jsを書いて保存します
- username, token, remoteUri は各自の環境に応じたものを入れます
- query の fieldValue: に検索したい値を入れます
index.js var zendesk = require('node-zendesk');
var client = zendesk.createClient({
username: 'Email',
token: 'API TOKEN',
remoteUri: 'https://NAME.zendesk.com/api/v2'
});
var query = "fieldValue:issue-00001";//この例では一意の値
client.search.query(query, function(err, req, result) {
if (err) return handleError(err);
console.log(JSON.stringify(result, null, 2, true));
console.log(result[0]['id']); //チケットIDを取得する
});
function handleError(err) {
console.log(err);
process.exit(-1);
}
|
補足
上のコードの例では
以下のように issue-00001 という値を持つカスタムフィールドがあり
その値は他のフィールドには存在しない一意である想定です
console.log(result[0]['id']) のところで0番目のチケットIDを取得しています
fieldValue で指定した値が一意でない場合は、検索結果の1番目以降のチケット情報も配列に返ってきます
特定のカスタムフィールドを指定して、その値のみを検索する機能は現状では存在しないようです
FYI
- http://www.pre-practice.net/2019/04/zendesk-apifieldvalue.html
- https://support.zendesk.com/hc/en-us/community/posts/209222988-How-to-search-tickets-by-using-custom-field-
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": [
"test1",
"test2",
"test3",
"りんご"
],
"custom_fields": [
{
"id": 360018014474,
"value": "めろん"
},
{
"id": 360018442253,
"value": ""
},
{
"id": 360018495613,
"value": "issue-00001"
},
{
"id": 360017830594,
"value": ""
},
{
"id": 360018428654,
"value": "りんご"
}
],
"satisfaction_rating": null,
"sharing_agreement_ids": [],
"fields": [
{
"id": 360018014474,
"value": "めろん"
},
{
"id": 360018442253,
"value": ""
},
{
"id": 360018495613,
"value": "issue-00001"
},
{
"id": 360017830594,
"value": ""
},
{
"id": 360018428654,
"value": "りんご"
}
],
"followup_ids": [],
"brand_id": ID,
"allow_channelback": false,
"allow_attachments": true,
"result_type": "ticket"
}
]
16
|
一番下の 16 という数字は、検索結果のチケットのIDです
参考
node-zendesk / ReadMe.md / search / query
https://github.com/blakmatrix/node-zendesk#search
How to search tickets by using custom field?
node-zendesk / ReadMe.md / search / query
https://github.com/blakmatrix/node-zendesk#search
search-query.js
https://github.com/blakmatrix/node-zendesk/blob/master/examples/search-query.js