tklein / php-sdk-zoho-desk
用于 Zoho Desk API v1 集成的 PHP SDK。
3.0.4
2024-04-02 19:19 UTC
Requires
- php: ^7.4||^8.0
- ext-curl: *
- ext-json: *
- ext-mbstring: *
README
此 SDK 库
设置
composer require tklein/php-sdk-zoho-desk
功能
您可以在 Zoho Desk 中执行所有 CRUD 操作。请检查您是否有适当的已注册 OAuth 访问令牌的允许操作范围。
设置
所有基本常量设置都可在 \Zoho\Desk\Api\Metadata
中找到。
首先,您需要一个有效的访问令牌。首先,从您的订阅区域连接到 Zoho 开发者控制台
对于欧洲,URL 为:[https://api-console.zoho.eu]
- 创建或使用现有的 "Self Client" 应用程序。您可能需要以下信息
- 使用适当的范围生成授权码。
aaaserver.profile.READ
范围是强制性的 完整的范围列表可在:[https://desk.zoho.com/DeskAPIDocument#OauthTokens#UsingOAuthtokenAPI] - 使用 Zoho SDK 生成持久性身份验证令牌文件
- 客户端 ID:您可以在 Zoho API 开发者控制台中找到它
- 客户端密钥:您可以在 Zoho API 开发者控制台中找到它
- 重定向 URL:这是一个虚拟 URL,它是 OAuth 标准的一部分,但未积极使用
- 当前用户电子邮件:这是创建自我客户端集成时使用的用户电子邮件([https://accounts.zoho./oauth/user/info])
- 组织 ID:这是您 Zoho Desk 应用程序中的组织 ID:设置和配置 -> 开发者空间 -> API -> Zoho Desk API -> OrgId(组织 ID)字段值
include __DIR__ . /* Relative path to the vendor autoloader */ '/vendor/autoload.php'; use Zoho\Desk\Api\Metadata; use Zoho\Desk\Client\ConfigProviderBuilder; use Zoho\OAuth\ZohoOAuth; $configBuilder = ConfigProviderBuilder::getInstance(); $configBuilder->setClientId(/* Client ID */) ->setClientSecret(/* Client Secret */) ->setRedirectUrl(/* Redirect Url */) ->setCurrentUserEmail(/* User Email */) ->setApiBaseUrl(/* API Endpoint by region */) ->setApiVersion(Metadata::API_VERSION) ->setOrgId(/* Org ID */) ->setIsSandbox(/* Sandbox Status */) ->setAccountsUrl(/* Accounts Url */) ->setTokenPersistencePath(/* Persistence Path */); // Add php code if the zcrm_oauthtokens.txt to create the file if it does not already exists. ZohoOAuth::initialize($configBuilder->create()->get()); ZohoOAuth::getClientInstance()->generateAccessToken($grantCode);
使用您的 API 详细信息和凭据创建配置对象。
include __DIR__ . /* Relative path to the vendor autoloader */ '/vendor/autoload.php'; use Zoho\Desk\Api\Metadata; use Zoho\Desk\Client\ConfigProviderBuilder; $configBuilder = ConfigProviderBuilder::getInstance(); $configBuilder->setClientId(/* Client ID */) ->setClientSecret(/* Client Secret */) ->setRedirectUrl(/* Redirect Url */) ->setCurrentUserEmail(/* User Email */) ->setApiBaseUrl(/* API Endpoint by region */) ->setApiVersion(Metadata::API_VERSION) ->setOrgId(/* Org ID */) ->setIsSandbox(/* Sandbox Status */) ->setAccountsUrl(/* Accounts Url */) ->setTokenPersistencePath(/* Persistence Path */);
您可以使用来自 Metadata
类的以下预定义值
final class Metadata { public const API_FIELD_CURRENT_USER_EMAIL = 'currentUserEmail'; public const API_FIELD_BASE_URL = 'apiBaseUrl'; public const API_FIELD_VERSION = 'apiVersion'; public const API_ENDPOINT_US = 'desk.zoho.com/api'; public const API_ENDPOINT_AU = 'desk.zoho.com.au/api'; public const API_ENDPOINT_EU = 'desk.zoho.eu/api'; public const API_ENDPOINT_IN = 'desk.zoho.in/api'; public const API_ENDPOINT_CN = 'desk.zoho.com.cn/api'; public const API_VERSION = 'v1'; public const ACCESS_TYPE = 'offline'; public const ORG_ID = 'orgId'; public const API_ACCOUNTS_US = 'https://accounts.zoho.com'; public const API_ACCOUNTS_AU = 'https://accounts.zoho.com.au'; public const API_ACCOUNTS_EU = 'https://accounts.zoho.eu'; public const API_ACCOUNTS_IN = 'https://accounts.zoho.in'; public const API_ACCOUNTS_CN = 'https://accounts.zoho.com.cn'; }
文档
SDK 的入口点是网关外观
use Zoho\Desk\Gateway; $gateway = new Gateway($configBuilder->create());
外观易于使用
use Zoho\Desk\Exception\CouldNotDeleteException; use Zoho\Desk\Exception\CouldNotReadException; use Zoho\Desk\Exception\CouldNotSaveException; use Zoho\Desk\Model\ListCriteriaBuilder; $ticketDataObject = $gateway->getDataObjectFactory()->create('tickets', /* Entity values */); try { $ticketDataObject = $gateway->getOperationPool()->getCreateOperation('tickets')->create($ticketDataObject); } catch (CouldNotSaveException $e) { // Handle the exception... } try { $ticketDataObject = $gateway->getOperationPool()->getReadOperation('tickets')->get(1234); } catch (CouldNotReadException $e) { // Handle the exception... } try { $criteriaBuilder = new ListCriteriaBuilder(); // $criteriaBuilder->setFields()->setFilters()... $ticketList = $gateway->getOperationPool()->getListOperation('tickets')->getList($criteriaBuilder->create()); $ticketList = $gateway->getOperationPool()->getListOperation('tickets')->getByIds([1,2,3]); } catch (CouldNotReadException $e) { // Handle the exception... } try { $ticketDataObject = $gateway->getOperationPool()->getUpdateOperation('tickets')->update($ticketDataObject); } catch (CouldNotSaveException $e) { // Handle the exception... } try { $gateway->getOperationPool()->getDeleteOperation('tickets', ['resolution'])->delete(1234); } catch (CouldNotDeleteException $e) { // Handle the exception... }
支持
向问题跟踪器提出新的 请求。
作者
许可证
本项目采用 MIT 许可证 - 请参阅 LICENSE 详细信息。
这就是全部了!