Source
public static function createSessionId($userid = 1, $sessionid = '09e7d4286dfdca4ba7be15e0f3b2b55a') {
<?php
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
require_once 'vendor/autoload.php';
require_once dirname(__FILE__).'/../../../include/defines.inc.php';
require_once dirname(__FILE__).'/../../../include/hosts.inc.php';
class CAPIHelper {
// API request id.
protected static $request_id = 0;
// Debug info.
protected static $debug = [];
// Session id.
protected static $session = null;
/**
* Reset API helper state.
*/
public static function reset() {
static::$request_id = 0;
static::clearDebugInfo();
static::setSessionId(null);
}
/**
* Make API call.
*
* @param mixed $data String containing request data as json.
* @param string $sessionid Authorization token.
*
* @return array
*
* @throws Exception if API call fails.
*/
public static function callRaw($data, ?string $sessionid = null) {
global $URL;
if (!is_string($URL)) {
$URL = PHPUNIT_URL.'api_jsonrpc.php';
}
if (is_array($data)) {
$data = json_encode($data);
}
$debug = [
'request' => $data,
'response' => null