Zendesk Ticket Update
Update a specified Zendesk ticket.
2018 (C) Questetra, Inc. (MIT License)
Configs
  • A: Sub Domain *
  • B: email *
  • C: API Token *
  • D: Select TEXT DATA for Ticket Id *
  • E: Select SELECT DATA for Ticket Status *
  • F: Select TEXT DATA for Ticket Comment
  • X: Select TEXT DATA for Log
Script
//// == コンフィグの参照 / Config Retrieving ==
var subDomain = configs.get("conf_SubDomain") + "";
var email = configs.get("conf_Email") + "";
var apiToken = configs.get("conf_ApiToken") + "";


//// == ワークフローデータの参照 / Data Retrieving ==
var ticketId = engine.findDataByNumber( configs.get("conf_TicketId") ) + "";
var ticketStatus = engine.findDataByNumber( configs.get("conf_TicketStatus") ).get(0).getValue() + "";


//以下は必須指定でないもの
var dataNum_TicketComment = configs.get("conf_TicketComment") + "";
var ticketComment = "";
if ((dataNum_TicketComment !== "") && (engine.findDataByNumber( dataNum_TicketComment ))) {
  ticketComment = engine.findDataByNumber( dataNum_TicketComment ) + "";
}


//// == 演算 / Calculating ==
var uri = "https://" + subDomain + ".zendesk.com/api/v2/tickets/" + ticketId + ".json";

var requestObj = {
  "ticket": {
    "status": "",
    "comment": { "body": "" }
  }
};
requestObj.ticket.status = ticketStatus;
requestObj.ticket.comment.body = ticketComment;

var response = httpClient.begin()
  .basic( email + "/token", apiToken )
  .body( JSON.stringify( requestObj ), "application/json")
  .put( uri );


//// == ワークフローデータへの代入 / Data Updating ==
//ログデータの指定があれば
var dataNum_Log = configs.get("conf_Log") + "";
if (dataNum_Log !== "") {
  var log = "";
  log += "---request json--- " + "\n";
  log += JSON.stringify( requestObj ) + "\n";
  log += "---PUT request--- " + response.getStatusCode() + "\n";
  log += response.getResponseAsString() + "\n";
  engine.setDataByNumber( dataNum_Log, log );
}

Download

Capture

See also

%d bloggers like this: