opendns / autotask-php
Autotask Web 服务的一个 SOAP 客户端包装器
Requires
- php: >=7.4.0
README
简介
autotask-php 设计用于通过提供与官方文档匹配的接口,简化与 Autotask Web 服务 API 的交互。
Autotask 暴露的所有对象都位于 src/AutotaskObjects
文件夹中的包装类。
如果您发现任何错误,或有功能请求,请通过 GitHub 报告问题或发起拉取请求。
此客户端正在积极开发中,因此没有稳定版本。
安装
Composer
请确保您的机器上已安装 Composer。您需要在应用程序根目录中创建一个 composer.json
文件。
{ "require": { "opendns/autotask-php": "dev-master" } }
composer.json
文件创建后,按照 composer 的说明从 这里 安装 autotask-php 包。
Composer 会创建自己的自动加载器。将 vendor/autoload.php
包含在您的应用程序配置文件中,您将完全访问 autotask-php 客户端。
手动
- 从 GitHub 下载 zip 文件或克隆 git 仓库
- 如有必要,将 zip 文件解压缩到您希望的位置
- 添加一个
require_once
调用来包含src/autoload.php
以访问客户端。
require_once __DIR__ . '/src/autoload.php';
使用
支持 Autotask API 的当前版本;v1.6 和 v1.5。
版本 1.6
从版本 1.6 开始,Autotask 只允许 'API 用户' 类型,并且所有调用都必须在头部包含一个集成代码。请参考 Autotask 帮助中心中的 Autotask Web 服务文档来设置 API 用户账户并生成集成代码。
您可以设置您的 WSDL 文件或使用自动检测(https://webservices.autotask.net/atservices/1.6/atws.wsdl)
您可以在实例化客户端或之后设置集成代码。在每次 API 调用中,客户端都会检查版本是否为 1.6 并确认集成代码已设置(除了在 getZoneInfo() 上)。如果未找到,它将引发错误。
获取您的区域 WSDL 并设置您的集成代码(实例化过程)
// This code is designed to find your exact wsdl location. // If you already know your zone's wsdl URL, you can skip // this step. $username = 'admin@happymsp.biz'; $password = 'VeryVeryVeryVerySecurePassword'; $authWsdl = 'https://webservices.autotask.net/atservices/1.6/atws.wsdl'; $integrationCode = '27-character ID'; $opts = array('trace' => 1); $client = new ATWS\Client($authWsdl, $opts, $integrationCode); $zoneInfo = $client->getZoneInfo($username); print_r($zoneInfo);
获取您的区域 WSDL 然后设置您的集成代码
// This code is designed to find your exact wsdl location. // If you already know your zone's wsdl URL, you can skip // this step. $username = 'admin@happymsp.biz'; $password = 'VeryVeryVeryVerySecurePassword'; $authWsdl = 'https://webservices.autotask.net/atservices/1.6/atws.wsdl'; $opts = array('trace' => 1); $client = new ATWS\Client($authWsdl, $opts); $integrationCode = '27-character ID'; $client->setIntegrationCode($integrationCode); $zoneInfo = $client->getZoneInfo($username); print_r($zoneInfo);
版本 1.5
任何具有 '可以登录到 Web 服务 API' 权限的 Autotask 用户账户都可以通过此版本的 API 连接。
您可以设置您的 WSDL 文件或使用自动检测(https://webservices.autotask.net/atservices/1.5/atws.wsdl)
获取您的区域 WSDL
// This code is designed to find your exact wsdl location. // If you already know your zone's wsdl URL, you can skip // this step. $username = 'admin@happymsp.biz'; $password = 'VeryVeryVeryVerySecurePassword'; $authWsdl = 'https://webservices.autotask.net/atservices/1.5/atws.wsdl'; $opts = array('trace' => 1); $client = new ATWS\Client($authWsdl, $opts); $zoneInfo = $client->getZoneInfo($username); print_r($zoneInfo);
资源模拟
您的 API 仅用户可以模拟账户笔记、合同笔记、项目笔记、任务笔记、票据笔记和时间条目上的资源。因此,当用户通过与 Autotask 的集成添加笔记和时间条目到 Autotask 时,显示的是用户的名字(而不是 API 用户的名字)。
要求
- 集成用户需要在AutotaskIntegrations SOAP头部中提供标签。
- 集成用户和仅API用户都必须有添加或编辑时间条目的安全级别权限。
- 集成用户的安全级别必须允许模拟资源。
- 仅API用户的 安全级别必须允许在实体类型上进行模拟。
有关模拟安全级别的更多详细信息,请参阅资源模拟。
当调用setResourceImpersonation()方法时,它将用集成代码和模拟的资源替换现有的SOAP头部。这样您就可以在不创建新客户端的情况下更改资源模拟。
当实例化客户端时,如果您没有包含集成代码并且调用setResourceImpersonation()方法,则会抛出错误'使用资源模拟时需要集成代码'。要解决此问题,请调用方法setIntegrationCode('27字符ID')设置集成代码,然后您可以调用setResourceImpersonation()。
$authOpts = array( 'login' => $username, 'password' => $password, 'trace' => 1, // Allows us to debug by getting the XML requests sent ); $integrationCode = '27-character ID'; $wsdl = str_replace('.asmx', '.wsdl', $zoneInfo->getZoneInfoResult->URL); $client = new ATWS\Client($wsdl, $authOpts, $integrationCode); // Instantiate an Account Note object and assign values $accountNote = new ATWS\AutotaskObjects\AccountNote('Contact'); $accountNote->AccountID = 12345678; $accountNote->ActionType = 1; $accountNote->AssignedResourceID = 12345678; $accountNote->EndDateTime = "2019-01-28T18:18:00"; $accountNote->id = 0; $accountNote->Note = "Resource Impersonation Test"; $accountNote->StartDateTime = "2019-01-28T18:18:00"; $result = $client->setResourceImpersonation(87654321)->create($accountNote); // Print the results of the account note creation print_r($result);
或者,您可以在调用setResourceImpersonation()方法后调用create()或update()。
$authOpts = array( 'login' => $username, 'password' => $password, 'trace' => 1, // Allows us to debug by getting the XML requests sent ); $integrationCode = '27-character ID'; $wsdl = str_replace('.asmx', '.wsdl', $zoneInfo->getZoneInfoResult->URL); $client = new ATWS\Client($wsdl, $authOpts, $integrationCode); $client->setResourceImpersonation(87654321); // Instantiate an Account Note object and assign values $accountNote = new ATWS\AutotaskObjects\AccountNote('Contact'); $accountNote->AccountID = 12345678; $accountNote->ActionType = 1; $accountNote->AssignedResourceID = 12345678; $accountNote->EndDateTime = "2019-01-28T18:18:00"; $accountNote->id = 0; $accountNote->Note = "Resource Impersonation Test"; $accountNote->StartDateTime = "2019-01-28T18:18:00"; $result = $client->create($accountNote); // Print the results of the account note creation print_r($result);
搜索联系人
$authOpts = array( 'login' => $username, 'password' => $password, 'trace' => 1, // Allows us to debug by getting the XML requests sent ); $wsdl = str_replace('.asmx', '.wsdl', $zoneInfo->getZoneInfoResult->URL); $client = new ATWS\Client($wsdl, $authOpts, $integrationCode); // for version 1.6 // $client = new ATWS\Client($wsdl, $authOpts); // for version 1.5 with no integration code // Instantiate a Query object, designed to make complex // queries simple. $query = new ATWS\AutotaskObjects\Query('Contact'); $firstnameField = new ATWS\AutotaskObjects\QueryField('firstname'); $firstnameField->addExpression('Equals', 'Steve'); $query->addField($firstnameField); // If you want to debug the XML produced by the Query object // print($query->asXml()); // Print the results of the query print_r($client->query($query));
更详细的查询
我们提供了一些可能需要执行的高级查询的支持。给定的查询可以有多个QueryField
对象,而给定的QueryField
可以有多个QueryFieldExpression
对象。
$authOpts = array( 'login' => $username, 'password' => $password, 'trace' => 1, // Allows us to debug by getting the XML requests sent ); $wsdl = str_replace('.asmx', '.wsdl', $zoneInfo->getZoneInfoResult->URL); $client = new ATWS\Client($wsdl, $authOpts, $integrationCode); // for version 1.6 // $client = new ATWS\Client($wsdl, $authOpts); // for version 1.5 with no integration code // Instantiate a Query object, designed to make complex // queries simple. $query = new ATWS\AutotaskObjects\Query('Contact'); // Add a QueryField with multiple expressions $firstnameField = new ATWS\AutotaskObjects\QueryField('firstname'); // Multiple Expressions in a single Field results in a logical OR $firstnameField->addExpression('BeginsWith', 'S'); $firstnameField->addExpression('Contains', 'e'); $query->addField($firstnameField); $lastnameField = new ATWS\AutotaskObjects\QueryField('lastname'); $lastnameField->addExpression('BeginsWith', 'M'); // Add a second QueryField -- multiple Fields are ANDed together $query->addField($lastnameField); // print($query->asXml()); print_r($client->query($query));
非常详细的查询
需要访问涉及使用条件的非常详细的查询?autotask-php客户端已添加对条件查询的支持。使用条件时要注意的一点是顺序很重要。任何添加的QueryCondition
或QueryField
都将按照该顺序序列化为XML。
QueryCondition
对象可以包含其他QueryCondition
对象以及QueryField
对象。下面的示例试图展示使用QueryCondition
对象的可能性。
$authOpts = array( 'login' => $username, 'password' => $password, 'trace' => 1, // Allows us to debug by getting the XML requests sent ); $wsdl = str_replace('.asmx', '.wsdl', $zoneInfo->getZoneInfoResult->URL); $client = new ATWS\Client($wsdl, $authOpts, $integrationCode); // for version 1.6 // $client = new ATWS\Client($wsdl, $authOpts); // for version 1.5 with no integration code // Instantiate a Query object, designed to make complex // queries simple. $query = new ATWS\AutotaskObjects\Query('Contact'); // QueryConditions default to logical ANDs. If you want to // using logcal OR, specify it when creating the QueryCondition $wrappingCondition = new ATWS\AutotaskObjects\QueryCondition('OR'); $conditionOne = new \ATWS\AutotaskObjects\QueryCondition(); $conditionTwo = new \ATWS\AutotaskObjects\QueryCondition('OR'); $firstField = new ATWS\AutotaskObjects\QueryField('firstname'); $firstField->addExpression('Equals', 'Joe'); $secondField = new ATWS\AutotaskObjects\QueryField('firstname'); $secondField->addExpression('Equals', 'Larry'); $thirdField = new ATWS\AutotaskObjects\QueryField('lastname'); $thirdField->addExpression('Equals', 'Brown'); $fourthField = new ATWS\AutotaskObjects\QueryField('firstname'); $fourthField->addExpression('Equals', 'Mary'); $fifthField = new ATWS\AutotaskObjects\QueryField('lastname'); $fifthField->addExpression('Equals', 'Smith'); $sixthField = new ATWS\AutotaskObjects\QueryField('city'); $sixthField->addExpression('NotEqual', 'Albany'); // AND together the 2nd and 3rd fields into a condition $conditionOne->addField($secondField); $conditionOne->addField($thirdField); // AND together the 4th and 5th fields into a condition $conditionTwo->addField($fourthField); $conditionTwo->addField($fifthField); // OR together the 1st Condition and 2nd Condition // NOTE: This is an OR because of how $conditionTwo // was defined $wrappingCondition->addCondition($conditionOne); $wrappingCondition->addCondition($conditionTwo); // Add the 1st Field to the Query $query->addField($firstField); // OR together the 1st Field and the wrapping Condition // NOTE: This is an OR because of how $wrappingCondition // was defined. $query->addCondition($wrappingCondition); // AND together the 6th Field and (1st Field OR wrapping Condition) $query->addField($sixthField); // If you want to debug the XML produced by the Query object // print($query->asXml()); // Print the results of the query print_r($client->query($query));
由于上述示例非常复杂,我们包含了"SQL等效"条件以及客户端产生的XML。
( firstname = 'Joe' OR ( (firstname = 'Larry' AND lastname = 'Brown') OR (firstname = 'Mary' AND lastname = 'Smith') ) ) AND city <> 'Albany'
<queryxml> <entity>Contact</entity> <query> <field> firstname <expression op="Equals">Joe</expression> </field> <condition operator="or"> <condition> <field> firstname <expression op="Equals">Larry</expression> </field> <field> lastname <expression op="Equals">Brown</expression> </field> </condition> <condition operator="or"> <field> firstname <expression op="Equals">Mary</expression> </field> <field> lastname <expression op="Equals">Smith</expression> </field> </condition> </condition> <field> city <expression op="NotEqual">Albany</expression> </field> </query> </queryxml>