ncbp/psa-api-client 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ncbp/psa-api-client

Composer 安装命令:

composer require ncbp/psa-api-client

包简介

ConnectWise PSA REST API Client

README 文档

README

A modular, resilient, and type-safe PHP SDK for interacting with the ConnectWise PSA REST API. Built for modern PHP 8.3+ applications, with first-class support for Symfony and PSR standards.

Features

  • Modular Architecture: Middleware-based pipeline (Onion Model) for easy extension.
  • Resilient by Design: Intelligent retry policy with exponential backoff and jitter; respects Retry-After headers.
  • Multiple Auth Strategies: Support for standard API Keys and Member Hash (Hosted API/Pods) authentication.
  • Fluent Query Builder: Abstract away complex PSA query syntax with PsaCriteria.
  • Automated Pagination: Lazy-loading PsaIterator for both Navigable and high-performance Forward-Only paging.
  • Functional Results: Either-style PsaResult container for clean, exception-free logic.
  • Security: Automatic redaction of sensitive data in logs and source verification for webhooks.

Installation

composer require ncbp/psa-api-client

Quick Start

Basic Initialization (API Key)

use NCBP\Integration\ConnectWise\Psa\ApiClient\Core\PsaClient;
use NCBP\Integration\ConnectWise\Psa\ApiClient\Authentication\PsaApiKeyAuthenticator;
use Symfony\Component\HttpClient\HttpClient;

$httpClient = HttpClient::create();
$authenticator = new PsaApiKeyAuthenticator('your-company', 'public-key', 'private-key');

$client = new PsaClient(
    $httpClient,
    $authenticator,
    'https://na.myconnectwise.net',
    'your-client-id'
);

Automatic Environment Discovery

If you don't know the specific codebase or site URL for a partner:

$result = PsaClient::createDiscovered(
    $httpClient,
    $authenticator,
    'na.myconnectwise.net',
    'your-company',
    'your-client-id'
);

if ($result->isSuccess()) {
    $client = $result->value();
}

Usage

Querying with Criteria

use NCBP\Integration\ConnectWise\Psa\ApiClient\Query\PsaCriteria;
use NCBP\Integration\ConnectWise\Psa\ApiClient\Query\PsaOperator;

$criteria = PsaCriteria::create()
    ->where('status/name', PsaOperator::NotEquals, 'Closed')
    ->whereContains('summary', 'Urgent')
    ->orderBy('dateCreated', 'desc')
    ->setPageSize(100);

$result = $client->get('service/tickets', $criteria);

if ($result->isSuccess()) {
    $tickets = $result->value();
    // Use the data...
}

Automated Pagination

Iterate through thousands of records without worrying about page boundaries. The PsaIterator will automatically fetch subsequent pages as you iterate.

$tickets = $client->paginate('service/tickets', $criteria);

// Check for errors before or after iteration
if ($error = $tickets->getLastError()) {
    echo "Pagination failed: " . $error->getMessage();
}

foreach ($tickets as $ticket) {
    echo $ticket['summary'] . PHP_EOL;
}

Functional Composition

Transform results cleanly using map() and onFailure():

$client->get('service/tickets/123')
    ->map(fn(array $data) => new TicketDTO($data))
    ->onFailure(fn(PsaError $e) => $logger->error($e->getMessage()))
    ->value(); // Returns TicketDTO or null

Patch Operations

Use the PsaPatchBuilder to ensure correct formatting:

use NCBP\Integration\ConnectWise\Psa\ApiClient\Core\Util\PsaPatchBuilder;

$patch = PsaPatchBuilder::create()
    ->replace('summary', 'Updated Summary')
    ->add('notes', 'Added a note');

$client->patch('service/tickets/123', $patch);

Advanced Features

Webhook Verification

Verify the integrity and source of ConnectWise PSA callbacks:

use NCBP\Integration\ConnectWise\Psa\ApiClient\Callback\Authentication\PsaCallbackAuthenticator;

$authenticator = new PsaCallbackAuthenticator(
    'https://na.myconnectwise.net', 
    'your-company',
    'v4_6_release', // Optional
    $httpClient     // Optional
);

// Verify signature
$isValid = $authenticator->authenticate($rawPayload, $signatureHeader, $signingKey);

// Or fetch the signing key securely if you have the key_url from metadata
$result = $authenticator->fetchSigningKey($keyUrl);
if ($result->isSuccess()) {
    $signingKey = $result->value();
}

Hosted API Context Resolution

If building a custom Pod or Tab, resolve URI tokens easily:

use NCBP\Integration\ConnectWise\Psa\ApiClient\Core\Util\PsaContextResolver;

$context = PsaContextResolver::resolve($_GET);
$endpoint = $context->getEndpoint(); // e.g., 'service/tickets'
$recordId = $context->getRecordId();

Configuration

Custom Middleware

You can inject your own middleware into the pipeline:

$client = new PsaClient(
    $httpClient,
    $authenticator,
    $siteUrl,
    $clientId,
    'v4_6_release',
    [
        new MyCustomMiddleware(),
        // Note: Providing custom middleware replaces the default stack.
        // Include default middlewares manually if needed.
    ]
);

Requirements

  • PHP 8.3+
  • symfony/http-client (or any implementation of HttpClientInterface)
  • psr/log
  • psr/clock

License

MIT License. See LICENSE for details.

ncbp/psa-api-client 适用场景与选型建议

ncbp/psa-api-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「api client」 「connectwise」 「ConnectWise PSA」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 ncbp/psa-api-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 ncbp/psa-api-client 我们能提供哪些服务?
定制开发 / 二次开发

基于 ncbp/psa-api-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 28
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-11