/** * Initialize API connection */ public function init() { $_config = new kyConfig($this->getApiURL(), $this->getApiKey(), $this->getSecretKey()); $_config->setIsStandardURLType(true); $_config->setDebugEnabled(true); kyConfig::set($_config); }
/** * Initialize client configuration object. */ public function init() { $configObj = JModuleHelper::getModule('mod_kayako')->params; $configValue = json_decode($configObj, 1); $config = $config = new kyConfig($configValue['apiurl'], $configValue['apikey'], $configValue['secretkey']); $config->setIsStandardURLType(true); kyConfig::set($config); }
/** * Initialize API connection */ public function init() { $apiUrl = Mage::helper('kayako')->getKayakoApiUrl(); $apiKey = Mage::helper('kayako')->getKayakoApiKey(); $secretKey = Mage::helper('kayako')->getKayakoSecretKey(); $_config = new kyConfig($apiUrl, $apiKey, $secretKey); $_config->setIsStandardURLType(true); $_config->setDebugEnabled(true); kyConfig::set($_config); }
/** * Returns field value as formatted date. * * @param string $format Output format of the date. If null the format set in client configuration is used. * @return string */ public function getDate($format = null) { if ($format === null) { $format = kyConfig::get()->getDateFormat(); } return date($format, $this->timestamp); }
/** * Returns expiration date of the user or null when expiration is disabled. * * @see http://www.php.net/manual/en/function.date.php * * @param string $format Output format of the date. If null the format set in client configuration is used. * @return string * @filterBy * @orderBy */ public function getExpiry($format = null) { if ($this->expiry == null) { return null; } if ($format === null) { $format = kyConfig::get()->getDatetimeFormat(); } return date($format, $this->expiry); }
/** * Returns date and time when the comment was created. * * @see http://www.php.net/manual/en/function.date.php * * @param string $format Output format of the date. If null the format set in client configuration is used. * @return string * @filterBy * @orderBy */ public function getDateline($format = null) { if ($this->dateline == null) { return null; } if ($format === null) { $format = kyConfig::get()->getDatetimeFormat(); } return date($format, $this->dateline); }
<?php ini_set('html_errors', 0); ini_set('display_errors', 1); ini_set('error_reporting', E_ALL); require_once dirname(__FILE__) . "/ressources/kayaco/kyIncludes.php"; define('DEBUG', true); kyConfig::set(new kyConfig("http://www.articatech.net/support/api/index.php", "bea5b97c-a838-8ca4-9dda-aec5043cccae", "MmUxYzRmMDMtM2RjNC1iY2Y0LTRkOGEtNjYzN2Q3N2U3MWE2N2FiZjk2NzEtMzQxZS0yMTA0LTUxN2YtOWZiY2VkOTQyNTMy")); $registered_user_group = kyUserGroup::getAll()->filterByTitle("30 days free")->first(); echo "registered_user_group: {$registered_user_group}\n"; //load some user organization $org = new kyUserOrganization(); $org->setName("MyCompany"); $data = $org->buildData(true); $org->create(); print_r($data); $user_organizations = kyUserOrganization::getAll(); foreach ($user_organizations as $user_organization) { $id = $user_organization->getId(); $company = $user_organization->getName(); echo "Company: {$company} -> {$id}\n"; } return; /** * Create new user in Registered group: * fullname: Anno Ying * email: anno.ying@example.com * password: qwerty123 */ $user = $registered_user_group->newUser("Daniel touzeau", "*****@*****.**", "qwerty123")->setUserOrganization($user_organization)->setSalutation(kyUser::SALUTATION_MR)->setSendWelcomeEmail(true)->create();
/** * Sends the request to Kayako server and returns parsed response. * * @param string $controller Kayako controller to call. Null to use default controller defined for object. * @param string $method HTTP verb. * @param array $parameters Optional. List of additional parameters (like object identifiers or search parameters). * @param array $data Optional. Data array with parameter name as key and parameter value as value. * @param array $files Optional. Array of files in form of: array('<parameter name>' => array('file_name' => '<file name>', 'contents' => '<file contents>'), ...). * @return array */ protected function processRequest($controller, $method, $parameters = array(), $data = array(), $files = array()) { $url = $this->getRequestData($controller, $method, $parameters, $data); $headers = array(); $request_body = $this->buildPostBody($data, $files, $headers); $curl_options = array(CURLOPT_HEADER => false, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_CONNECTTIMEOUT => 2, CURLOPT_FORBID_REUSE => true, CURLOPT_FRESH_CONNECT => true, CURLOPT_HTTPHEADER => $headers, CURLOPT_URL => $url); switch ($method) { case self::METHOD_GET: break; case self::METHOD_POST: $curl_options[CURLOPT_POSTFIELDS] = $request_body; $curl_options[CURLOPT_POST] = true; break; case self::METHOD_PUT: if ($this->config->isPUTAsMemoryStream()) { $fh = fopen('php://memory', 'rw'); fwrite($fh, $request_body); rewind($fh); $curl_options[CURLOPT_INFILE] = $fh; $curl_options[CURLOPT_INFILESIZE] = strlen($request_body); $curl_options[CURLOPT_PUT] = true; } else { $curl_options[CURLOPT_CUSTOMREQUEST] = 'PUT'; $curl_options[CURLOPT_POSTFIELDS] = $request_body; } break; case self::METHOD_DELETE: $curl_options[CURLOPT_CUSTOMREQUEST] = 'DELETE'; break; } $curl_options[CURLOPT_HTTPHEADER] = $headers; if ($this->config->isDebugEnabled()) { error_log('Sending REST request to Kayako:'); error_log(sprintf(' %s: %s', $method, $curl_options[CURLOPT_URL])); if ($method === self::METHOD_POST || $method === self::METHOD_PUT) { error_log(sprintf(' Body: %s', $request_body)); } } $curl_handle = curl_init(); curl_setopt_array($curl_handle, $curl_options); $response = curl_exec($curl_handle); if ($this->config->isDebugEnabled()) { error_log('Response from Kayako server:'); error_log($response); } //removing any output prior to proper XML response (ex. Kayako notices) $xml_start_pos = stripos($response, "<?xml"); if ($xml_start_pos > 0) { $response = substr($response, $xml_start_pos); } if ($response === false) { throw new kyException(sprintf('CURL error: %s (%s)', curl_error($curl_handle), curl_errno($curl_handle))); } $http_status = curl_getinfo($curl_handle, CURLINFO_HTTP_CODE); if ($http_status != 200) { throw new kyException(sprintf("HTTP error: %s", $http_status)); } curl_close($curl_handle); if ($method === self::METHOD_DELETE) { return null; } $result = ky_xml_to_array($response); if ($result === false) { throw new kyException("Error parsing XML response."); } if (count($result) === 1 && array_key_exists('_contents', $result) && strlen($result['_contents']) === 0) { $result = array(); } return $result; }
/** * Returns REST client. * * @return kyRESTClientInterface */ protected static function getRESTClient() { return kyConfig::get()->getRESTClient(); }
/** * Returns expiration date of Service Level Agreement plan assignment or null when expiration is disabled. * * @see http://www.php.net/manual/en/function.date.php * * @param string $format Output format of the date. If null the format set in client configuration is used. * @return string * @filterBy * @orderBy */ public function getSLAPlanExpiry($format = null) { if ($format === null) { $format = kyConfig::get()->getDatetimeFormat(); } return date($format, $this->sla_plan_expiry); }
/** * Initializes the client. */ function initKayako() { $config = new kyConfig(BASE_URL, API_KEY, SECRET_KEY); $config->setDebugEnabled(DEBUG); kyConfig::set($config); }
/** * Returns date and time this note was created. * * @see http://www.php.net/manual/en/function.date.php * * @param string $format Output format of the date. If null the format set in client configuration is used. * @return string * @filterBy * @orderBy */ public function getCreationDate($format = null) { if ($format === null) { $format = kyConfig::get()->getDatetimeFormat(); } return date($format, $this->creation_date); }
/** * Returns field default value. * * @return string * @filterBy * @orderBy */ public function getDefaultValue() { switch ($this->type) { case self::TYPE_TEXT: case self::TYPE_TEXTAREA: case self::TYPE_PASSWORD: return $this->default_value; break; case self::TYPE_DATE: return date(kyConfig::get()->getDateFormat(), $this->default_value); break; default: return null; break; } }
<?php require_once "vendor/kayako-sdk/kyIncludes.php"; require_once "vendor/autoload.php"; $config = json_decode(file_get_contents("config/config.json"), true); $api_settings = $config["kayako"]; kyConfig::set(new kyConfig($api_settings["url"], $api_settings["key"], $api_settings["secret"])); $klein = new \Klein\Klein();
<?php /** * @copyright 2001-2015 Kayako * @license https://www.freebsd.org/copyright/freebsd-license.html * @link https://github.com/kayako/whmcs-integration */ //Include config file require_once __DIR__ . '/config.php'; //Include all necessary classes and helper methods require_once 'API/kyIncludes.php'; //Include common functions require_once 'functions.php'; //Initialize the client kyConfig::set(new kyConfig(API_URL, API_KEY, SECRET_KEY)); $_ticketObject = kyTicket::get($_GET['tid']); $_customField = $_ticketObject->getCustomField($_GET['field']); $_customFieldValue = $_customField->getValue(); Download($_customFieldValue[0], $_customFieldValue[1]);
/** * Sets the current library configuration. * * Should be called before before contacting the API. * * @param kyConfig $config Configuration. * @return kyConfig */ public static function set(kyConfig $config) { self::$current_config = $config; return self::$current_config; }
/** * @copyright 2001-2015 Kayako * @license https://www.freebsd.org/copyright/freebsd-license.html * @link https://github.com/kayako/whmcs-integration */ require_once __DIR__ . '/config.php'; require_once 'API/kyConfig.php'; require_once 'API/kyRESTClientInterface.php'; require_once 'API/kyRESTClient.php'; require_once 'API/kyHelpers.php'; //Include common functions require_once 'functions.php'; //Include constants file require_once 'constants.php'; kyConfig::set(new kyConfig(API_URL, API_KEY, SECRET_KEY)); $_restClient = kyConfig::get()->getRESTClient(); $_newsController = '/News/NewsItem'; $_commentController = '/News/Comment'; if (isset($_GET['itemid'])) { if ($_GET['action'] == 'savecomment') { $_itemIDKey = 'newsitemid'; $_itemID = $_GET['itemid']; $_rootCommentElement = 'newsitemcomment'; include 'savecomment.php'; } include 'announcementitem.php'; } else { include 'announcementlist.php'; } $smarty->assign('_baseURL', WHMCS_URL); $smarty->assign('_templateURL', getcwd() . '/templates/kayako');
/** * Returns date and time when to bill the worker. * * @see http://www.php.net/manual/en/function.date.php * * @param string $format Output format of the date. If null the format set in client configuration is used. * @return string * @filterBy * @orderBy */ public function getBillDate($format = null) { if ($format === null) { $format = kyConfig::get()->getDatetimeFormat(); } return date($format, $this->bill_date); }
/** * Returns statistics for all tickets in database. Result is cached. * Format or result: * <pre> * array( * 'departments' => array( //statistics per department (if there are no tickets in department then there will be no record with its id here) * <department id> => array( //tickets assigned to department with this id * 'last_activity' => <date and time of last activity on tickets in this department>, * 'total_items' => <total amount of tickets in this department>, * 'total_unresolved_items' => <total amount of unresolved tickets in this department>, * 'ticket_statuses' => array( //statistics per ticket status in the department * <ticket status id> => array( * 'last_activity' => <date and time of last activity on tickets with this status in this department>, * 'total_items' => <total amount of tickets with this status in this department> * ), * ... * ), * 'ticket_types' => array( //statistics per ticket type in the department * <ticket type id> => array( * 'last_activity' => <date and time of last activity on tickets of this type in this department>, * 'total_items' => <total amount of tickets of this type in this department>, * 'total_unresolved_items' => <total amount of unresolved tickets of this type in this department>, * ), * ..., * 'unknown' => array( //in Kayako 4.01.204 all ticket types will be unknown because of a bug (http://dev.kayako.com/browse/SWIFT-1465) * ... * ) * ) * 'ticket_owners' => array( //statistics per ticket owner in the department * <owner staff id> => array( * 'last_activity' => <date and time of last activity on tickets assigned to this staff in this department>, * 'total_items' => <total amount of tickets assigned to this staff in this department>, * 'total_unresolved_items' => <total amount of unresolved tickets assigned to this staff in this department>, * ), * ..., * 'unassigned' => array( //tickets not assigned to any staff * ... * ) * ) * ), * ..., * 'unknown' => array( //tickets in Trash * ... * ) * ), * 'ticket_statuses' => array( //statistics per ticket status in all departments * <ticket status id> => array( * 'last_activity' => <date and time of last activity on tickets with this status in all departments>, * 'total_items' => <total amount of tickets with this status in all departments> * ), * ... * ), * 'ticket_owners' => array( //statistics per ticket owner in all departments * <owner staff id> => array( * 'last_activity' => <date and time of last activity on tickets assigned to this staff in all department>, * 'total_items' => <total amount of tickets assigned to this staff in all department>, * 'total_unresolved_items' => <total amount of unresolved tickets assigned to this staff in all department>, * ), * ..., * 'unassigned' => array( //tickets not assigned to any staff no matter what department * ... * ) * ) * ) * </pre> * * @param bool $reload True to reload statistics data from server. * @return array */ public static function getStatistics($reload = false) { if (self::$statistics !== null && !$reload) { return self::$statistics; } self::$statistics = array('departments' => array(), 'ticket_statuses' => array(), 'ticket_owners' => array()); $raw_stats = self::getRESTClient()->get('/Tickets/TicketCount', array()); foreach ($raw_stats['departments'][0]['department'] as $department_raw_stats) { $department_id = intval($department_raw_stats['_attributes']['id']); $department_stats = array(); $department_stats['last_activity'] = intval($department_raw_stats['lastactivity']) > 0 ? date(kyConfig::get()->getDatetimeFormat(), $department_raw_stats['lastactivity']) : null; $department_stats['total_items'] = $department_raw_stats['totalitems']; $department_stats['total_unresolved_items'] = $department_raw_stats['totalunresolveditems']; foreach ($department_raw_stats['ticketstatus'] as $ticket_status_raw_stats) { $ticket_status_id = intval($ticket_status_raw_stats['_attributes']['id']); $ticket_status_stats = array(); $ticket_status_stats['last_activity'] = intval($ticket_status_raw_stats['_attributes']['lastactivity']) > 0 ? date(kyConfig::get()->getDatetimeFormat(), $ticket_status_raw_stats['_attributes']['lastactivity']) : null; $ticket_status_stats['total_items'] = $ticket_status_raw_stats['_attributes']['totalitems']; $department_stats['ticket_statuses'][$ticket_status_id] = $ticket_status_stats; } //this is broken in Kayako 4.01.240, tickettype id is always 0 (unknown) - http://dev.kayako.com/browse/SWIFT-1465 foreach ($department_raw_stats['tickettype'] as $ticket_type_raw_stats) { $ticket_type_id = intval($ticket_type_raw_stats['_attributes']['id']); $ticket_type_stats = array(); $ticket_type_stats['last_activity'] = intval($ticket_type_raw_stats['_attributes']['lastactivity']) > 0 ? date(kyConfig::get()->getDatetimeFormat(), $ticket_type_raw_stats['_attributes']['lastactivity']) : null; $ticket_type_stats['total_items'] = $ticket_type_raw_stats['_attributes']['totalitems']; $ticket_type_stats['total_unresolved_items'] = $ticket_type_raw_stats['_attributes']['totalunresolveditems']; $department_stats['ticket_types'][$ticket_type_id > 0 ? $ticket_type_id : 'unknown'] = $ticket_type_stats; } foreach ($department_raw_stats['ownerstaff'] as $owner_staff_raw_stats) { $staff_id = intval($owner_staff_raw_stats['_attributes']['id']); $owner_staff_stats = array(); $owner_staff_stats['last_activity'] = intval($owner_staff_raw_stats['_attributes']['lastactivity']) > 0 ? date(kyConfig::get()->getDatetimeFormat(), $owner_staff_raw_stats['_attributes']['lastactivity']) : null; $owner_staff_stats['total_items'] = $owner_staff_raw_stats['_attributes']['totalitems']; $owner_staff_stats['total_unresolved_items'] = $owner_staff_raw_stats['_attributes']['totalunresolveditems']; $department_stats['ticket_owners'][$staff_id > 0 ? $staff_id : 'unassigned'] = $owner_staff_stats; } //unknown department is for example for tickets in Trash self::$statistics['departments'][$department_id > 0 ? $department_id : 'unknown'] = $department_stats; } foreach ($raw_stats['statuses'][0]['ticketstatus'] as $ticket_status_raw_stats) { $ticket_status_id = intval($ticket_status_raw_stats['_attributes']['id']); $ticket_status_stats = array(); $ticket_status_stats['last_activity'] = intval($ticket_status_raw_stats['_attributes']['lastactivity']) > 0 ? date(kyConfig::get()->getDatetimeFormat(), $ticket_status_raw_stats['_attributes']['lastactivity']) : null; $ticket_status_stats['total_items'] = $ticket_status_raw_stats['_attributes']['totalitems']; self::$statistics['ticket_statuses'][$ticket_status_id] = $ticket_status_stats; } foreach ($raw_stats['owners'][0]['ownerstaff'] as $owner_staff_raw_stats) { $staff_id = intval($owner_staff_raw_stats['_attributes']['id']); $owner_staff_stats = array(); $owner_staff_stats['last_activity'] = intval($owner_staff_raw_stats['_attributes']['lastactivity']) > 0 ? date(kyConfig::get()->getDatetimeFormat(), $owner_staff_raw_stats['_attributes']['lastactivity']) : null; $owner_staff_stats['total_items'] = $owner_staff_raw_stats['_attributes']['totalitems']; $owner_staff_stats['total_unresolved_items'] = $owner_staff_raw_stats['_attributes']['totalunresolveditems']; self::$statistics['ticket_owners'][$staff_id > 0 ? $staff_id : 'unassigned'] = $owner_staff_stats; } return self::$statistics; }
<?php require_once "../kyIncludes.php"; print "<pre>"; /** * Initialization. */ kyConfig::set(new kyConfig("<API URL>", "<API key>", "<Secret key>")); kyConfig::get()->setDebugEnabled(true); /** * Optional. Setting defaults for new tickets. * WARNING: * Names may be different in your instalation. */ $default_status_id = kyTicketStatus::getAll()->filterByTitle("Open")->first()->getId(); $default_priority_id = kyTicketPriority::getAll()->filterByTitle("Normal")->first()->getId(); $default_type_id = kyTicketType::getAll()->filterByTitle("Issue")->first()->getId(); kyTicket::setDefaults($default_status_id, $default_priority_id, $default_type_id); $general_department = kyDepartment::getAll()->filterByTitle("General")->filterByModule(kyDepartment::MODULE_TICKETS)->first(); /** * Cleanup - delete what's left from previous run of this example. */ $example_department = kyDepartment::getAll()->filterByTitle("Printers (example)"); if (count($example_department) > 0) { $tickets_to_delete = kyTicket::getAll($example_department)->filterBySubject("Printer not working (example)"); $tickets_to_delete->deleteAll(); if (count($tickets_to_delete) > 0) { printf("Tickets DELETED:\n%s", $tickets_to_delete); } } $users_to_delete = kyUser::getAll()->filterByEmail("*****@*****.**");