$reply_data = array(
'ticket_id'=>9,
'vars' => array(
'ticket_id'=>9,
'staff_id' => null, // the reply is from this staff user
'client_id' => 2, // the reply is from this client user
'contact_id' => null, // the reply is from this client contact user
'type' => "reply", // this is a ticket reply
'details' => "API reply", // the ticket reply description
'status' => "open", // status of the ticket
'staff_id' => null, // the staff user the ticket is assigned to
),
'files' => null,
'new_ticket' => false // this reply is for a newly created ticket
);
$response = $api->post("support_managerpro.support_managerpro_tickets", "addReply", $reply_data);
this page return this error info:{"message":"The requested resource does not exist.","response":null}
What should I do to use API to achieve a reply?thanks!
support_managerpro::
Model's addReply method():
/**
* Adds a reply to a ticket. If ticket data (e.g. department_id, status, priority, summary) have changed
* then this will also invoke SupportManagerproTickets::edit() to update the ticket, and record any log entries.
*
* Because of this functionality, this method is assumed to (and should) already be in a transaction when called,
* and SupportManagerproTickets::edit() should not be called separately.
*
* @param int $ticket_id The ID of the ticket to reply to
* @param array $vars A list of reply vars, including:
* - staff_id The ID of the staff member this reply is from (optional)
* - client_id The ID of the client this reply is from (optional)
* - contact_id The ID of a client's contact that this reply is from (optional)
* - type The type of reply (i.e. "reply, "note", "log") (optional, default "reply")
* - details The details of the ticket (optional)
* - department_id The ID of the ticket department (optional)
* - summary The ticket summary (optional)
* - priority The ticket priority (optional)
* - status The ticket status (optional)
* - ticket_staff_id The ID of the staff member the ticket is assigned to (optional)
* @param array $files A list of file attachments that matches the global FILES array, which contains an array of "attachment" files
* @param boolean $new_ticket True if this reply is apart of ticket being created, false otherwise (default false)
* @return int The ID of the ticket reply on success, void on error
*/
public function addReply($ticket_id, array $vars, array $files = null, $new_ticket = false) {
$vars['ticket_id'] = $ticket_id;
$vars['date_added'] = date("c");
if (!isset($vars['type']))
$vars['type'] = "reply";
// Remove reply details if it contains only the signature
if (isset($vars['details']) && isset($vars['staff_id'])) {
if (!isset($this->SupportManagerproStaff))
Loader::loadModels($this, array("SupportManagerpro.SupportManagerproStaff"));
$staff_settings = $this->SupportManagerproStaff->getSettings($vars['staff_id'], Configure::get("Blesta.company_id"));
if (isset($staff_settings['signature']) && trim($staff_settings['signature']) == trim($vars['details']))
$vars['details'] = "";
}
// Determine whether or not options have changed that need to be logged
$log_options = array();
// "status" should be the last element in case it is set to closed, so it will be the last log entry added
$loggable_fields = array('department_id' => "department_id", 'ticket_staff_id' => "staff_id", 'summary' => "summary",
'priority' => "priority", 'status' => "status");
if (!$new_ticket && (isset($vars['department_id']) || isset($vars['summary']) || isset($vars['priority']) || isset($vars['status']) || isset($vars['ticket_staff_id']))) {
if (($ticket = $this->get($ticket_id, false))) {
// Determine if any log replies need to be made
foreach ($loggable_fields as $key => $option) {
// Save to be logged iff the field has been changed
if (isset($vars[$key]) && property_exists($ticket, $option) && $ticket->{$option} != $vars[$key])
$log_options[] = $key;
}
}
}
// Check whether logs are being added simultaneously, and if so, do not
// add a reply iff no reply details, nor files, are attached
// i.e. allow log entries to be added without a reply/note regardless of vars['type']
$skip_reply = false;
if (!empty($log_options) && empty($vars['details']) && (empty($files) || empty($files['attachment']['name'][0])))
$skip_reply = true;
if (!$skip_reply) {
$this->Input->setRules($this->getReplyRules($vars, $new_ticket));
if ($this->Input->validates($vars)) {
// Create the reply
$fields = array("ticket_id", "staff_id", "contact_id", "type", "details", "date_added");
$this->Record->insert("support_repliespro", $vars, $fields);
$reply_id = $this->Record->lastInsertId();
// Update reply ticket status to awaiting_reply if replyed by staff
if (isset($vars['staff_id'])){
if ($vars['staff_id'] > 0 && $vars['type'] == "reply" && $vars['status'] != "awaiting_reply"){
$this->edit($vars['ticket_id'], array('status' => "awaiting_reply"));
}
}
// Handle file upload
if (!empty($files['attachment'])) {
Loader::loadComponents($this, array("SettingsCollection", "Upload"));
// Set the uploads directory
$temp = $this->SettingsCollection->fetchSetting(null, Configure::get("Blesta.company_id"), "uploads_dir");
$upload_path = $temp['value'] . Configure::get("Blesta.company_id") . DS . "support_managerpro_files" . DS;
$this->Upload->setFiles($files, false);
$this->Upload->setUploadPath($upload_path);
$file_vars = array('files' => array());
if (!($errors = $this->Upload->errors())) {
// Will not overwrite existing file
$this->Upload->writeFile("attachment", false, null, array($this, "makeFileName"));
$data = $this->Upload->getUploadData();
// Set the file names/paths
foreach ($files['attachment']['name'] as $index => $file_name) {
if (isset($data['attachment'][$index])) {
$file_vars['files'][] = array(
'name' => $data['attachment'][$index]['orig_name'],
'file_name' => $data['attachment'][$index]['full_path']
);
}
}
$errors = $this->Upload->errors();
}
// Error, could not upload the files
if ($errors) {
$this->Input->setErrors($errors);
// Attempt to remove the files if they were somehow written
foreach ($file_vars['files'] as $files) {
if (isset($files['file_name']))
@unlink($files['file_name']);
}
return;
}
else {
// Add the attachments
$file_fields = array("reply_id", "name", "file_name");
foreach ($file_vars['files'] as $files) {
if (!empty($files))
$this->Record->insert("support_attachmentspro", array_merge($files, array('reply_id' => $reply_id)), $file_fields);
}
}
}
}
}
// Only attempt to update log options if there are no previous errors
if (!empty($log_options) && !$this->errors()) {
// Update the support ticket
$data = array_intersect_key($vars, $loggable_fields);
$ticket_staff_id_field = array();
if (isset($data['ticket_staff_id']))
$ticket_staff_id_field = (isset($data['ticket_staff_id']) ? array('staff_id' => $data['ticket_staff_id']) : array());
$this->edit($ticket_id, array_merge($data, $ticket_staff_id_field), false);
if (!($errors = $this->errors())) {
// Log each support ticket field change
foreach ($log_options as $field) {
$log_vars = array(
'staff_id' => (array_key_exists("staff_id", $vars) ? $vars['staff_id'] : $this->system_staff_id),
'type' => "log"
);
$lang_var1 = "";
switch ($field) {
case "department_id":
$department = $this->Record->select("name")->from("support_departmentspro")->
where("id", "=", $vars['department_id'])->fetch();
$lang_var1 = ($department ? $department->name : "");
break;
case "priority":
$priorities = $this->getPriorities();
$lang_var1 = (isset($priorities[$vars['priority']]) ? $priorities[$vars['priority']] : "");
break;
case "status":
$statuses = $this->getStatuses();
$lang_var1 = (isset($statuses[$vars['status']]) ? $statuses[$vars['status']] : "");
break;
case "ticket_staff_id":
if (!isset($this->Staff))
Loader::loadModels($this, array("Staff"));
$staff = $this->Staff->get($vars['ticket_staff_id']);
if ($vars['ticket_staff_id'] && $staff)
$lang_var1 = $staff->first_name . " " . $staff->last_name;
else
$lang_var1 = Language::_("SupportManagerproTickets.log.unassigned", true);
default:
break;
}
$log_vars['details'] = Language::_("SupportManagerproTickets.log." . $field, true, $lang_var1);
$this->addReply($ticket_id, $log_vars);
}
}
}
// Return the ID of the reply
if (isset($reply_id))
return $reply_id;
}
Question
ty0716
resolvent :
=================================================================================================================================
Now i need to use api reply tickets. But I've had some problems.
This is my code:
when i use
this page return {"message":"An unexpected error occured.","response":"Internal error: Failed to retrieve the default value"}
when i use
this page return this error info:{"message":"The requested resource does not exist.","response":null}
What should I do to use API to achieve a reply?thanks!
support_managerpro::
Model's addReply method():
2 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.