kerekit / minicrm-api

Mini CRM API 客户端

v2.0.2 2020-12-11 14:59 UTC

This package is auto-updated.

Last update: 2024-09-11 23:03:36 UTC


README

功能

  • 尊重速率限制,并在需要时延迟请求。
  • 提供基本的 get()post()put() 方法,适用于任何类型的请求。
  • 提供 getAll() 方法,用于连接所有页面上的项目。
  • 从构造函数参数处理身份验证。
  • 格式化请求并解析响应,如果失败则抛出自定义错误。

安装

使用以下命令安装最新版本:

$ composer require kerekit/minicrm-api

基本用法

<?php

use Kerekit\MiniCrmApi\{Client,Error};

/**
 * Config:
 * - $systemId: The number in address bar, right after the "r3.minicrm.hu/" part
 * - $apiKey: You can generate one in your account's Settings > System menu
 * - $production: Whether to use production (true) or test (false) server
 */
$systemId = '1234';
$apiKey = 'IDontPasteAnActualApiKeyHereDoYouThinkIAmThatStupid';
$production = false;

// Init API client
$api = new Client ($systemId, $apiKey, $production);

// Get the first page of projects in a single module
$response = $api->get ('Project', ['CategoryId' => 19, 'Page' => 0]);
echo "Got $response[Count] projects in module. Here is the FIRST PAGE:\n";
foreach ($response ['Results'] as $project) {
    echo "- #$project[Id] $project[Name]\n";
}
echo "\n";

// Load the projects of same criteria from all pages into an array
$projects = $api->getAll ('Project', ['CategoryId' => 19]);
$count = count ($projects);
echo "Got $count projects in module. Here is ALL OF THEM:\n";
foreach ($projects as $project) {
    echo "- #$project[Id] $project[Name]\n";
}
echo "\n";

// Update project name
try {
    $api->put ('Project/123', ['Name' => 'New project name']);
    echo "Project name successfully updated.\n";
} catch (Error $e) {
    echo "Failed to update project name: " . $e->getMessage () . "\n";
}

有关可用资源和参数,请参阅官方 MiniCRM API 文档。