spinegar / sugar7wrapper
该包最新版本(v2.0.0)没有可用的许可证信息。
SugarCRM REST客户端
v2.0.0
2019-04-16 14:06 UTC
Requires
- php: >=7.2
- guzzlehttp/guzzle: ^6.3.0
Requires (Dev)
- phpunit/phpunit: ^8
This package is not auto-updated.
Last update: 2024-09-14 14:45:11 UTC
README
许可证:MIT
内容
关于 安装 使用 示例 自定义和/或未定义端点 故障排除
关于
一个简单的PHP库,用于与SugarCRM v10或更高版本的REST API交互。
v2.0.0
v2.0.0提供了一些小更新,以保持库与PHP生态系统的更新。
-
已更新命名空间,以避免与Sugar版本混淆。您需要将命名空间更新为
\Spinegar\SugarRestClient\Rest
以实例化库。 -
添加了对Guzzle 6的支持。
-
connect
方法已被弃用,现在由库在与Sugar API交互时处理。
通过Composer安装
编辑composer.json
{ "require": { "spinegar/sugar7wrapper": "^v2.0.0" } }
然后使用composer安装
$ composer install
3.使用示例
/* Instantiate and authenticate */ $sugar = new \Spinegar\SugarRestClient\Rest(); $sugar->setUrl('https://sugar/rest/v11/') ->setUsername('user') ->setPassword('password'); /* Instantiate and authenticate for a specific platform*/ $sugar->setUrl('https://sugar/rest/v11/') ->setUsername('user') ->setPassword('password') ->setPlatform('api'); /* Retrieve all records in the Cases module */ $sugar->search('Cases'); /* Retrieve all records in the Cases module where the name = 'Case1 Name' or 'Case2 Name' */ $sugar->search('Cases', array( 'q' => '"Case1 Name" "Case2 Name"' )); /* Retrieve the name field for all records in the Cases module */ $sugar->search('Cases', array( 'fields' => 'name' )); /* Retrieve all records with filter params in the Contacts module */ $sugar->filter('Contacts', array( 'filter' => array( array('first_name' => 'First Name'), ) )); /* Count all records with filter params in the Cases module */ $sugar->countRecords('Cases', array( 'filter' => array( array('status' => 'New'), ) )); /* Retrieve a specific record from the Cases module */ $sugar->retrieve('Cases', $record_id); /* Create a case */ $sugar->create('Cases', array( 'name' => 'Case Name', 'status' => 'Assigned' )); /* Update a case */ $sugar->update('Cases', $record_id, array( 'status' => 'Closed' )); /* Favorite a case */ $sugar->favorite('Cases', $record_id); /* Unfavorite a case */ $sugar->unfavorite('Cases', $record_id); /* Retrieve cases related to an account */ $sugar->related('Accounts', $record_id, 'cases'); /* Relate a case to an account */ $sugar->relate('Accounts', $record_id, 'cases', $related_record_id); /*Relate a contact to an opportunity and set relationship data */ $sugar->relate('Opportunities', $record_id, 'contacts', $related_record_id, array( 'contact_role' => 'Influencer' )); /* Delete relationship between an account and case */ $sugar->unrelate('Accounts', $record_id, 'cases', $related_record_id); /* Update relationship data */ $sugar->updateRelationship('Opportunities', $record_id, 'contacts', $related_record_id, array( 'contact_role' => 'Influencer' )); /* Retrieve a list of attachments for a case */ $attachments = $sugar->related('Cases', $record_id, 'notes'); foreach($attachments['records'] as $attachment) { $output[] = $sugar->files('Notes', $attachment['id']); } return $output; /* Delete the file associated to the filename field of a note */ $sugar->deleteFile('Notes', $record_id, 'filename'); /* Download the file associated to the filename field of a note to the server */ $sugar->download('Notes', $record_id, 'filename', '/path/to/destination.ext'); /* Upload a file associated to the filename field of a note to the server */ $sugar->upload('Notes', $record_id, 'filename', '/path/of/local/file.ext');
- 自定义和未定义端点
使用以下方法调用自定义或未定义端点。
/* Get Endpoint*/ $parameters = array(); $sugar->getEndpoint('MyCustomEndpoint', $parameters); /* Post Endpoint*/ $parameters = array(); $sugar->postEndpoint('MyCustomEndpoint', $parameters); /* Put Endpoint*/ $parameters = array(); $sugar->putEndpoint('MyCustomEndpoint', $parameters); /* Delete Endpoint*/ $parameters = array(); $sugar->deleteEndpoint('MyCustomEndpoint', $parameters);
- 故障排除
如果您连接到受保护的站点(https)有问题,请尝试以下操作
$sugar = new \Spinegar\Sugar7Wrapper\Rest(); $sugar->setClientOption('verify', false); // This is the important part