alfreddagenais/zohobooksapi

2.2.2 2018-10-02 12:49 UTC

This package is auto-updated.

Last update: 2024-09-12 07:31:30 UTC


README

这个库是一个PHP SDK,简化了Zoho Books API v3(https://www.zoho.com/books/api/v3/)的使用。它提供了一个界面来简化与API的交互,而不必担心实际的REST请求,并通过使用非常简单的Model类来包装各种响应,这些类可以与其他任何库或框架一起使用。

安装

composer require webleit/zohobooksapi

用法

为了使用这个库,只需要引入composer的autoload文件,然后启动库本身。为了使库工作,你需要为Zoho Books API提供一个认证令牌。

require './vendor/autoload.php';
$zohoBooks = new \Webleit\ZohoBooksApi\ZohoBooks('authtoken');

如果你在账户中有多个组织,你可以将组织ID作为第二个参数指定

$zohoBooks = new \Webleit\ZohoBooksApi\ZohoBooks('authtoken', 'organization_id');

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]);

返回类型

任何“list”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');

任何“resource”API调用都返回一个类Model对象,该类是针对你正在获取的单个资源定制的。例如,调用

$invoice = $zohoBooks->invoices->get('idoftheinvoice');
$id = $invoice->getId();
$data = $invoice->toArray();
$total = $invoice->total;

将返回一个\Webleit\ZohoBooksApi\Models\Invoice对象,该对象是Arrayable和Jsonable的,因此可以以多种方式使用。

贡献

发现错误、发送pull请求或改进文档 - 欢迎任何贡献,并高度赞赏。

版本控制

使用语义版本控制规范(SemVer)。

版权和许可

版权归Weble Srl所有,根据MIT许可协议。