rams007 / zohobooksapi
Zoho Books API v3 - PHP SDK
Requires
- php: ^7.2 || ^8.0
- doctrine/inflector: ^2.0
- guzzlehttp/guzzle: ^6.0 || ^7.0
- illuminate/collections: ^v8.0 || ^9.0 || ^10.0 || ^11.0
- weble/zohoclient: ^4.2
Requires (Dev)
- cache/filesystem-adapter: ^1.1
- phpunit/phpunit: ^7.0 || ^8.0 || ^9.0 || ^10.0
- dev-master
- 5.5.9
- 5.5.7
- 5.5.6
- 5.5.5
- 5.5.4
- 5.5.3
- 5.5.2
- 5.5.1
- 5.5.0
- 5.4.8
- 5.4.7
- 5.4.6
- 5.4.5
- 5.4.4
- 5.4.3
- 5.4.2
- 5.4.1
- 5.4.0
- 5.3.0
- 5.2.4
- 5.2.3
- 5.2.2
- 5.2.1
- 5.2.0
- 5.1.0
- 5.0.3
- 5.0.2
- 5.0.1
- 5.0.0
- 4.5.1
- 4.5.0
- 4.4.2
- 4.4.1
- 4.4.0
- 4.3.2
- 4.3.1
- 4.3.0
- 4.2.0
- 4.1.0
- 4.0.0
- 3.3.3
- 3.3.2
- 3.3.1
- 3.3.0
- 3.2.0
- 3.1.1
- 3.1.0
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.5
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.3
- 2.0.2
- 2.0.0
- 1.0
This package is auto-updated.
Last update: 2024-10-01 00:09:28 UTC
README
Zoho Books API v3 - PHP SDK
此库是一个PHP SDK,简化了Zoho Books Api版本3(https://www.zoho.com/books/api/v3/)的使用。它提供了一个接口,简化了与API的交互,无需担心实际的REST请求,并使用非常简单的Model类包装各种响应,然后可以与任何其他库或框架一起使用。
安装
composer require webleit/zohobooksapi
用法
为了使用此库,只需引入composer自动加载文件,然后启动库本身。为了使库能够工作,您需要通过zoho apis进行身份验证。
在线模式
require './vendor/autoload.php'; // setup the generic zoho oath client $oAuthClient = new \Weble\ZohoClient\OAuthClient('[CLIENT_ID]', '[CLIENT_SECRET]'); $oAuthClient->setRefreshToken('[REFRESH_TOKEN]'); $oAuthClient->setRegion(\Weble\ZohoClient\Enums\Region::us()); $oAuthClient->useCache($yourPSR6CachePool); // setup the zoho books client $client = new \Webleit\ZohoBooksApi\Client($oAuthClient); $client->setOrganizationId('[YOUR_ORGANIZATION_ID]'); // Create the main class $zohoBooks = new \Webleit\ZohoBooksApi\ZohoBooks($client);
离线模式
当您需要自行独立更新访问令牌时,建议使用此模式。用于所有“机器到机器”通信,当您使用API进行,例如,与第三方应用程序(如您的ERP或电子商务网站)同步时,这是最好的方式。有关此模式的更多详细信息,请参阅https://github.com/Weble/ZohoClient#example-usage-offline-mode。
require './vendor/autoload.php'; // setup the generic zoho oath client $oAuthClient = new \Weble\ZohoClient\OAuthClient('[CLIENT_ID]', '[CLIENT_SECRET]'); $oAuthClient->setRefreshToken('[REFRESH_TOKEN]'); $oAuthClient->setRegion(\Weble\ZohoClient\Enums\Region::us()); $oAuthClient->useCache($yourPSR6CachePool); $oAuthClient->offlineMode(); // Access Token $accessToken = $oAuthClient->getAccessToken(); $isExpired = $oAuthClient->accessTokenExpired(); // setup the zoho books client $client = new \Webleit\ZohoBooksApi\Client($oAuthClient); $client->setOrganizationId('[YOUR_ORGANIZATION_ID]'); // Create the main class $zohoBooks = new \Webleit\ZohoBooksApi\ZohoBooks($client);
API调用
要调用任何API,只需使用在API文档中报告的相同名称。您可以使用getAvailableModules()方法获取支持的API列表
$zohoBooks->getAvailableModules();
例如,您可以使用以下方式获取发票列表
$invoices = $zohoBooks->invoices->getList();
或联系人列表
$contacts = $zohoBooks->contacts->getList();
列表调用
要从模块中获取资源列表,请使用getList()方法
$invoices = $zohoBooks->invoices->getList();
您可以传递一些参数来过滤结果(请参阅Zoho Books API文档中的示例)
$invoices = $zohoBooks->invoices->getList(['status' => 'unpaid']);
要浏览页面,请在getList调用中使用“page”和“per_page”参数
$invoices = $zohoBooks->invoices->getList(['status' => 'unpaid', 'page' => 3, 'per_page' => 200]);
返回类型
任何“列表”API调用返回一个Collection对象,它是Laravel Collection包。因此,您可以将结果用作Collection,允许映射、减少、序列化等。
$invoices = $zohoBooks->invoices->getList(); $data = $invoices->toArray(); $json = $invoices->toJson(); // After fetch filtering in php $filtered = $invoices->where('total', '>', 200); // Grouping $filtered = $invoices->groupBy('customer_id');
任何“资源”API调用返回一个类特定的Model对象,该类用于您正在检索的单个资源。例如,调用
$invoice = $zohoBooks->invoices->get('idoftheinvoice'); $id = $invoice->getId(); $data = $invoice->toArray(); $total = $invoice->total;
将返回一个\Webleit\ZohoBooksApi\Models\Invoice对象,它是Arrayable和Jsonable的,因此可以以多种方式使用。
Zoho Books令牌过期说明
- 每个访问令牌仅有效一小时,并且仅用于定义在作用域内的操作。
- 刷新令牌不会过期。当访问令牌过期时,请使用它来刷新访问令牌。
- 您每分钟只能生成最多五个刷新令牌。
贡献
查找错误、发送拉取请求或改进文档——任何贡献都受欢迎并高度赞赏。
版本控制
使用语义版本规范(SemVer)。
版权和许可证
版权所有 Weble Srl,根据MIT许可证。