innovaat / topdesk-api
TOPdesk API的PHP实现
v0.0.5
2022-03-30 14:00 UTC
Requires
- php: 7.*|^8.0
- ext-json: *
- guzzlehttp/guzzle: 6.*|^7.0
This package is auto-updated.
Last update: 2024-09-19 22:54:00 UTC
README
TOPdesk API的PHP包装器。
安装
composer require innovaat/topdesk-api
指南
我们的TOPdesk API实现包含以下特性
- 使用应用程序密码(推荐)或令牌(旧版)进行简单登录。
- 自动重试功能,当发生连接错误或状态码 >= 500 时,会重试请求。我们曾经历过TOPdesk API的各种不稳定情况,希望这可以最大限度地减少这些不足。
- 直接调用常用API端点的函数(例如
createIncident($params)
、getIncidentById($id)
、getListOfIncidents()
、escalateIncidentById($id)
、deescalateIncidentById($id)
、getListOfDepartments()
、createDepartment($params)
、getListOfBranches()
、createBranch($params)
等)。 - 使用
$api->request($method, $uri, $json = [], $query = [])
对其他端点提供简单的语法。
// Create a new API instance, endpoint should end on "/tas/". $api = new \Innovaat\Topdesk\Api('https://partnerships.topdesk.net/tas/');
根据您的身份验证选择,调用 useLogin
或 useApplicationPassword
。
// RECOMMENDED $api->useApplicationPassword('yourusername', 'ipsal-a7aid-6ybuq-ucjwg-axt4i');
// LEGACY LOGIN WITH TOKEN $api->useLogin('yourusername', 'yourpassword', function($token) { // Callback function that receives a single parameter `$token` for you to persist. // It should return the persisted token as well. if($token) { file_put_contents('token.txt', $token); } return file_exists('token.txt') ? file_get_contents('token.txt') : null; });
现在您的API应该准备好使用了。
$incidents = $api->getListOfIncidents([ 'start' => 0, 'page_size' => 10 ]); foreach($incidents as $incident) { var_dump($incident['number']); }
许多请求已实现为API的直接函数。但是,并非所有功能都已实现。对于手动API请求,请使用 request()
函数。
$api->request('GET', 'api/incidents/call_types', [ // Optional array to be sent as JSON body (for POST/PUT requests). ], [ // Optional (search) query parameters, see API documentation for supported values. ], [ // Optional parameters for the Guzzle request itself. // @see http://docs.guzzlephp.org/en/stable/request-options.html ])