asimlqt/netsuite-rest-api-php
Composer 安装命令:
composer require asimlqt/netsuite-rest-api-php
包简介
A REST API client for Netsuite
README 文档
README
Requirements
- PHP >= 8.1
- PSR-7, PSR-17 and PSR-18 implementations
Installation
composer require asimlqt/netsuite-rest-api-php
Usage
The first step is to create a factory instance passing in the netsuite API settings. All the params are required.
$factory = new NetsuiteRestApi\NetsuiteClientFactory( $companyUrl, $accountId, $consumerKey, $consumerSecret, $tokenId, $tokenSecret );
After that call the create method which will return an instance of the REST API client.
$client = $factory->create();
You can now call any endpoint you want on the client e.g.
try { $response = $client->customer->get('1234'); } catch (ApiException $e) { echo $e->getMessage(); }
Error Handling
Make sure to wrap all API calls in a try/catch. There is only one exception that
will be thrown when an API call fails NetsuiteRestApi\Client\ApiException
To get the actual response object simply call the getResponse() method of the exception instance.
This will return a Psr\Http\Message\ResponseInterface.
API methods available
Every endpoint has the following 6 methods:
- list
- get
- insert
- delete
- update
- upsert
Note: not all of these are available for every endpoint in Netsuite. For the time being this client does not prevent you from calling unavailable methods, however, you will receive an error from Netsuite.
Pagination
The only endpoint that supports pagination is list. This will return a cursor that implements Iterator so you can iterate over it as you would normally.
try { $cursor = $client->currency->list(); foreach ($cursor as $item) { echo $item['id']; } } catch (ApiException $e) { echo $e->getMessage(); }
The cursor will iterate over individual entities. When all entities have been iterated over it will automatically fetch the next page if available.
Note: Even if you supply a limit query parameter, the cursor will still iterate over all available entities in Netsuite.
$cursor = $client->currency->list(['limit' => 3]);
The limit query parameter only provides the ability to set how many entities to fetch on each API call.
If you want to only iterate over a set number of entities even though there is more available then wrap the cursor in a LimitIterator.
$cursor = $client->customer->list(['limit' => 10]); foreach (new LimitIterator($cursor, 0, 10) as $item) { ... }
asimlqt/netsuite-rest-api-php 适用场景与选型建议
asimlqt/netsuite-rest-api-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 32.97k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2024 年 05 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 asimlqt/netsuite-rest-api-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 asimlqt/netsuite-rest-api-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 32.97k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-05-27