如何使用 osticket API 密钥

可能

我已经从 osticket (v.1.10) 管理面板生成了一个 API 密钥,并将我的 IP 设置为 127.0.0.1,我已经下载了这个 php 脚本,但我不知道保存这个文档的路径以及 URL 应该是什么(它是我的管理面板 URL 还是其他?)以及如何测试它?

#!/usr/bin/php -q
<?php
#
# Configuration: Enter the url and key. That is it.
#  url => URL to api/task/cron e.g #  http://yourdomain.com/support/api/tickets.json
#  key => API's Key (see admin panel on how to generate a key)
#  $data add custom required fields to the array.
#
#  Originally authored by [email protected]
#  Modified by ntozier@osTicket / tmib.net

// If 1, display things to debug.
$debug="0";

// You must configure the url and key in the array below.

$config = array(
        'url'=>'http://site.tld/api/tickets.json',  // URL to site.tld/api/tickets.json
		    'key'=>'27ADED3FED6AC18D8068FCB942DB4442'  // API Key goes here
);
# NOTE: some people have reported having to use "http://your.domain.tld/api/http.php/tickets.json" instead.

if($config['url'] === 'http://site.tld/api/tickets.json') {
  echo "<p style=\"color:red;\"><b>Error: No URL</b><br>You have not configured this script with your URL!</p>";
  echo "Please edit this file ".__FILE__." and add your URL at line 18.</p>";
  die();  
}		
if(IsNullOrEmptyString($config['key']) || ($config['key'] === '27ADED3FED6AC18D8068FCB942DB4442'))  {
  echo "<p style=\"color:red;\"><b>Error: No API Key</b><br>You have not configured this script with an API Key!</p>";
  echo "<p>Please log into osticket as an admin and navigate to: Admin panel -> Manage -> Api Keys then add a new API Key.<br>";
  echo "Once you have your key edit this file ".__FILE__." and add the key at line 19.</p>";
  die();
}
		
# Fill in the data for the new ticket, this will likely come from $_POST.
# NOTE: your variable names in osT are case sensiTive. 
# So when adding custom lists or fields make sure you use the same case
# For examples on how to do that see Agency and Site below.
$data = array(
    'name'      =>      'John Doe',  // from name aka User/Client Name
    'email'     =>      '[email protected]',  // from email aka User/Client Email
    'phone' 	  =>		  '1234567890',  // phone number aka User/Client Phone Number
    'subject'   =>      'Test API message',  // test subject, aka Issue Summary
    'message'   =>      'This is a test of the osTicket API',  // test ticket body, aka Issue Details.
    'ip'        =>      $_SERVER['REMOTE_ADDR'], // Should be IP address of the machine thats trying to open the ticket.
	  'topicId'   =>      '1', // the help Topic that you want to use for the ticket 
	//'Agency'  =>		'58', //this is an example of a custom list entry. This should be the number of the entry.
	//'Site'	=>		'Bermuda'; // this is an example of a custom text field.  You can push anything into here you want.	
    'attachments' => array()
);

# more fields are available and are documented at:
# https://github.com/osTicket/osTicket-1.8/blob/develop/setup/doc/api/tickets.md

if($debug=='1') {
  print_r($data);
  die();
}

# Add in attachments here if necessary
# Note: there is something with this wrong with the file attachment here it does not work.
$data['attachments'][] =
array('file.txt' =>
        'data:text/plain;base64;'
            .base64_encode(file_get_contents('/file.txt')));  // replace ./file.txt with /path/to/your/test/filename.txt
 

#pre-checks
function_exists('curl_version') or die('CURL support required');
function_exists('json_encode') or die('JSON support required');

#set timeout
set_time_limit(30);

#curl post
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $config['url']);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_USERAGENT, 'osTicket API Client v1.8');
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Expect:', 'X-API-Key: '.$config['key']));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result=curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($code != 201)
    die('Unable to create ticket: '.$result);

$ticket_id = (int) $result;

# Continue onward here if necessary. $ticket_id has the ID number of the
# newly-created ticket

function IsNullOrEmptyString($question){
    return (!isset($question) || trim($question)==='');
}
?>

提前致谢

可能

原来我只需要更改里面的 URL 和 KEY 即可$config=array()如果您遇到与我尝试从 API on 测试新票证相同的问题localhost,您需要做的就是将 URL 更改为http://127.0.0.1/yourosticketsite/api/http.php/tickets.json.

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在 osTicket 中实现客户回复 API

来自分类Dev

如何使用openweathermap API密钥?

来自分类Dev

如何使用API密钥保护REST API

来自分类Dev

使用OpenWeatherMap API密钥

来自分类Dev

osTicket API:在python中创建新的票证

来自分类Dev

如何获取CyberArk的API密钥?

来自分类Dev

如何获得Mandrill API密钥?

来自分类Dev

如何轮换 Firebase 的 API 密钥?

来自分类Dev

使用RestServer的Api密钥无效

来自分类Dev

未经授权使用 API 密钥

来自分类Dev

如何通过唯一的API密钥使用多个Google API

来自分类Dev

在Amazon API Gateway中使用API密钥

来自分类Dev

使用API密钥保护我的API

来自分类Dev

Google API密钥使用限制和密钥/应用

来自分类Dev

如何使用Kafka Consumer API中的密钥读取数据?

来自分类Dev

如何使用PHP生成强大的独特API密钥?

来自分类Dev

Bouncy Castle API如何知道使用哪个密钥加密?

来自分类Dev

如何在Google静态地图中使用API密钥?

来自分类Dev

如何使用Web api密钥发送FCM消息?

来自分类Dev

如何使用多个随机YouTube v3 API密钥

来自分类Dev

如何使用Gatsby存储和访问API密钥和密码?

来自分类Dev

如何在Android上安全使用Google Map API密钥?

来自分类Dev

如何通过NPM使用TinyMCE 5 API密钥

来自分类Dev

SwiftUI-如何使用动态密钥访问API响应数据?

来自分类Dev

如何使用Chef管理安全的应用程序API密钥

来自分类Dev

如何使用uisng xcode提取或解压json密钥(从API)?

来自分类Dev

如何同时使用两个 google api 密钥?

来自分类Dev

如何使用 urllib 向 Datadog 发送 API 密钥?

来自分类Dev

如何使用 Powershell 在 Azure API 管理中禁用订阅密钥

Related 相关文章

热门标签

归档