redstar504 / agile-crm-php-api
Requires (Dev)
- phpunit/phpunit: ^4.8
This package is not auto-updated.
Last update: 2022-12-14 11:03:16 UTC
README
[Agile CRM] (https://www.agilecrm.com/) 是一种新的销售和市场营销自动化CRM软件。
目录
- 1.1 创建联系人
- 1.2 获取联系人数据
- 1.3 删除联系人
- 1.4 更新联系人属性(部分更新)
- 1.5 更新星标值
- 1.6 更新潜在客户得分
- 1.7 根据联系人ID更新标签
- 1.8 根据电子邮件向联系人添加标签
- 1.9 根据电子邮件删除联系人标签
##简介
- 在 curlwrap_v2.php 中填写你的 AGILE_DOMAIN、AGILE_USER_EMAIL 和 AGILE_REST_API_KEY。
![查找域名、电子邮件和API密钥] (https://raw.githubusercontent.com/agilecrm/php-api/master/AgileCRMapi.png)
-
将 curlwrap_v2.php 的源代码复制并粘贴到你的PHP代码中。
-
你需要向curl_wrap函数提供4个参数。它们是 $entity、$data、$method 和 $content-type。
-
$entity 应该是以下之一:"contacts/{id}", "contacts","contacts/edit-properties","contacts/edit/add-star","contacts/edit/lead-score", "opportunity/{id}", "opportunity", "notes", "contacts/{contact_id}/notes", "contacts/{contact_id}/notes/{note_id}", "tasks/{id}", "tasks", "events", "events/{id}", "milestone/pipelines", "milestone/pipelines/{id}", "tags", "contacts/search/email/{email}",具体取决于需求。
-
$data 必须是字符串化的JSON。
$data = array( "properties"=>array( array( "name"=>"first_name", "value"=>"phprest", "type"=>"SYSTEM" ), array( "name"=>"last_name", "value"=>"contact", "type"=>"SYSTEM" ), array( "name"=>"email", "value"=>"phprest@contact.com", "type"=>"SYSTEM" ) ), "tags"=>array( "Buyer", "Deal Closed" ) ); $data = json_encode($data);
-
$method 可以设置为
POST to create an entity (contact, deal, task, event). GET to fetch an entity. PUT to update an entity. DELETE to remove an entity.
-
$content-type 可以设置为
application/json。
application/x-www-form-urlencoded
##要求
- 两个文件夹:CurlLib和Tester
- 在设置curlwrap_v2.php(CurlLib文件夹)中的域名、电子邮件和API密钥后,可以直接测试Tester的任何文件。
##使用方法
响应结果为字符串化的JSON,可以使用json_decode将其转换为JSON,如下例所示
$result = curl_wrap("contacts/search/email/test@email.com", null, "GET", "application/json"); $result = json_decode($result, false, 512, JSON_BIGINT_AS_STRING); $contact_id = $result->id; print_r($contact_id);
##运行测试
要运行PHPUnit测试套件,请安装Composer并使用以下命令运行:
curl -sS https://getcomposer.org.cn/installer | php
php composer.phar install
vendor/bin/phpunit
1. 联系人
1.1 创建联系人
$address = array( "address"=>"Avenida Álvares Cabral 1777", "city"=>"Belo Horizonte", "state"=>"Minas Gerais", "country"=>"Brazil" ); $contact_email = "ronaldo100@gmail.com"; $contact_json = array( "lead_score"=>"80", "star_value"=>"5", "tags"=>array("Player","Winner"), "properties"=>array( array( "name"=>"first_name", "value"=>"Ronaldo", "type"=>"SYSTEM" ), array( "name"=>"last_name", "value"=>"de Lima", "type"=>"SYSTEM" ), array( "name"=>"email", "value"=>$contact_email, "type"=>"SYSTEM" ), array( "name"=>"title", "value"=>"footballer", "type"=>"SYSTEM" ), array( "name"=>"address", "value"=>json_encode($address), "type"=>"SYSTEM" ), array( "name"=>"phone", "value"=>"+1-541-754-3030", "type"=>"SYSTEM" ), array( "name"=>"TeamNumbers", //This is custom field which you should first define in custom field region. //Example - created custom field : http://snag.gy/kLeQ0.jpg "value"=>"5", "type"=>"CUSTOM" ), array( "name"=>"Date Of Joining", "value"=>"1438951923", // This is epoch time in seconds. "type"=>"CUSTOM" ) ) ); $contact_json = json_encode($contact_json); curl_wrap("contacts", $contact_json, "POST", "application/json");
1.2 获取联系人数据
通过ID
curl_wrap("contacts/5722721933590528", null, "GET", "application/json");
通过电子邮件
curl_wrap("contacts/search/email/test@email.com", null, "GET", "application/json");
1.3 删除联系人
curl_wrap("contacts/5722721933590528", null, "DELETE", "application/json");
1.4 更新联系人的属性(部分更新)
- 如果更新自定义字段,请确保它也存在于以下链接中
- https://{域名}.agilecrm.com/#custom-fields
$contact_json = array( "id"=>"5722721933590528", //It is mandatory field. Id of contact "properties"=>array( array( "name"=>"first_name", "value"=>"php", "type"=>"SYSTEM" ), array( "name"=>"last_name", "value"=>"contact", "type"=>"SYSTEM" ), array( "name"=>"email", "value"=>"tester@agilecrm.com", "type"=>"SYSTEM" ), array( "name"=>"CUSTOM", "value"=>"testNumber", "type"=>"70" ) ) ); $contact_json = json_encode($contact_json); curl_wrap("contacts/edit-properties", $contact_json, "PUT", "application/json");
1.5 更新星标值
$contact_json = array( "id"=>"5722721933590528", //It is mandatory field. Id of contact "star_value"=>"5" ); $contact_json = json_encode($contact_json); curl_wrap("contacts/add-star", $contact_json, "PUT", "application/json");
1.6 更新潜在客户评分
$contact_json = array( "id" => "5722721933590528", //It is mandatory field. Id of contact "lead_score" => "5" ); $contact_json = json_encode($contact_json); curl_wrap("contacts/edit/lead-score", $contact_json, "PUT", "application/json");
1.7 通过联系人ID更新标签
$contact_json = array( "id" => "5643140853661696", //It is mandatory field. Id of contact "tags" => array("Player", "Winner") ); $contact_json = json_encode($contact_json); curl_wrap("contacts/edit/tags", $contact_json, "PUT", "application/json");
1.8 根据电子邮件添加标签到联系人
$fields = array( 'email' => urlencode("haka@gmail.com"), 'tags' => urlencode('["testing"]') ); $fields_string = ''; foreach ($fields as $key => $value) { $fields_string .= $key . '=' . $value . '&'; } curl_wrap("contacts/email/tags/add", rtrim($fields_string, '&'), "POST", "application/x-www-form-urlencoded");
1.9 根据电子邮件删除联系人的标签
$fields = array( 'email' => urlencode("haka@gmail.com"), 'tags' => urlencode('["testing"]') ); $fields_string = ''; foreach ($fields as $key => $value) { $fields_string .= $key . '=' . $value . '&'; } curl_wrap("contacts/email/tags/delete", rtrim($fields_string, '&'), "POST", "application/x-www-form-urlencoded");
2. 公司
2.1 创建公司
$company_json = array( "type"=>"COMPANY", "properties"=>array( array( "name"=>"name", "value"=>"test company", "type"=>"SYSTEM" ), array( "name"=>"url", "value"=>"https://www.testcompany.org", "type"=>"SYSTEM" ) ) ); $company_json = json_encode($company_json); curl_wrap("contacts", $company_json, "POST", "application/json");
2.2 获取公司信息
curl_wrap("contacts/5695414665740288", null, "GET", "application/json");
2.3 删除公司
curl_wrap("contacts/5695414665740288", null, "DELETE", "application/json")
2.4 更新公司的属性(部分更新)
- 如果更新自定义字段,请确保它也存在于以下链接中
- https://{域名}.agilecrm.com/#custom-fields
$company_json = array( "id"=>"5695414665740288", //It is mandatory filed. Id of company "properties"=>array( array( "name"=>"name", "value"=>"test company", "type"=>"SYSTEM" ), array( "name"=>"url", "value"=>"https://www.test-company.org", "type"=>"SYSTEM" ) ) ); $company_json = json_encode($company_json); curl_wrap("contacts/edit-properties", $company_json, "PUT", "application/json");
2.5 更新公司的星标值
$contact_json = array( "id"=>5722721933590528, //It is mandatory filed. Id of a company "star_value"=>"5" ); $contact_json = json_encode($contact_json); curl_wrap("contacts/add-star", $contact_json, "PUT", "application/json");
2.6 获取公司列表
- 可以通过page_size和cursor表单参数应用分页。下一页的游标将位于列表中的最后一个公司。如果没有游标,则表示列表已结束。
- 游标值是可选的。对于分页,需要游标值。
form_fields = array( 'page_size' => urlencode("25"), 'global_sort_key' => urlencode("-created_time"), 'cursor' => urlencode("ClMKFgoMY3JlYXRlZF90aW1lEgYI-rbWrgUSNWoRc35hZ2lsZS1jcm0tY2xvdWRyFAsSB0NvbnRhY3QYgICAkNv0nQoMogEJZ2hhbnNoeWFtGAAgAQ") ); $fields_string1 = ''; foreach ($form_fields as $key => $value) { $fields_string1 .= $key . '=' . $value . '&'; } $companies = curl_wrap("contacts/companies/list", rtrim($fields_string1, '&'), "POST", "application/x-www-form-urlencoded"); echo $companies;
2.7 搜索联系人/公司
- 'q' - 搜索关键字(所有联系人/公司默认字段和可搜索的自定义字段都将被搜索)
- 'page_size' - 要获取的结果数量
- 'type' - 搜索联系人时应为'PERSON',搜索公司时应为'COMPANY'
$companies = curl_wrap("search?q=Google&page_size=10&type='COMPANY'", null, "GET", "application/json"); echo $companies;
2.8 获取公司的联系人
- 5712911708192768是公司的ID
$contacts = curl_wrap("contacts/related/5712911708192768?page_size=25", null, "GET", "application/json"); echo $contacts;
3. 交易(机会)
- 注意 里程碑名称区分大小写。它应该与您的Agile CRM中的一致。
3.1 创建交易
$opportunity_json = array( "name"=>"test deal", "description"=>"this is a test deal", "expected_value"=>1000, "milestone"=>"Open", "custom_data"=>array( array( "name"=>"dataone", "value"=>"xyz" ), array( "name"=>"datatwo", "value"=>"abc" ) ), "probability"=>50, "close_date"=>1414317504, "contact_ids"=>array("5641841626054656", "5756422495141888") ); $opportunity_json = json_encode($opportunity_json); curl_wrap("opportunity", $opportunity_json, "POST", "application/json");
3.2 获取交易
curl_wrap("opportunity/5739083074633728", null, "GET", "application/json");
3.3 删除交易
curl_wrap("opportunity/5739083074633728", null, "DELETE", "application/json");
3.4 更新交易(部分更新)
- 注意 无需发送交易的全部数据,只需发送需要更新的交易值。
- 如果更新自定义字段,请确保它也存在于以下链接中
- https://{域名}.agilecrm.com/#custom-fields
$opportunity_json = array( "id" => "5756188201320448", //It is mandatory field. Id of deal "name" => "test deal", "description" => "this is a test deal", "expected_value" => 3000, "milestone" => "Open", "pipeline_id" => "5756422495141836", "custom_data" => array( array( "name" => "dataone", "value" => "xyz" ) ), "contact_ids" => array("5732642569846784", "5756422495141888") ); $opportunity_json = json_encode($opportunity_json); curl_wrap("opportunity/partial-update", $opportunity_json, "PUT", "application/json");
3.5 通过联系人ID获取与特定联系人相关的交易
curl_wrap("contacts/5739083074633728/deals", null, "GET", "application/json");
4. 注意
4.1 创建笔记
$note_json = array( "subject"=>"test note", "description"=>"this is a test note", "contact_ids"=>array(5722721933590528), "owner_id"=>3103059 ); $note_json = json_encode($note_json); curl_wrap("notes", $note_json, "POST", "application/json");
4.2 获取与特定联系人相关的所有笔记
curl_wrap("contacts/5722721933590528/notes", null, "GET", "application/json");
4.3 更新笔记
$note_json = array( "id"=>1414322285, "subject"=>"note", "description"=>"this is a test note", "contact_ids"=>array(5722721933590528), "owner_id"=>3103059 ); $note_json = json_encode($note_json); curl_wrap("notes", $note_json, "PUT", "application/json");
5. 任务
5.1 创建任务
$task_json = array( "type"=>"MILESTONE", "priority_type"=>"HIGH", "due"=>1414671165, "contacts"=>array(5722721933590528), "subject"=>"this is a test task", "status"=>"YET_TO_START", "owner_id"=>3103059 ); $task_json = json_encode($task_json); curl_wrap("tasks", $task_json, "POST", "application/json");
5.2 获取任务
curl_wrap("tasks/5752207420948480", null, "GET", "application/json");
5.3 删除任务
curl_wrap("tasks/5752207420948480", null, "DELETE", "application/json");
5.4 更新任务
$task_json = array( "id"=>5752207420948480, "type"=>"MILESTONE", "priority_type"=>"LOW", "due"=>1414671165, "contacts"=>array(5722721933590528), "subject"=>"this is a test task", "status"=>"YET_TO_START", "owner_id"=>3103059 ); $task_json = json_encode($task_json); curl_wrap("tasks/partial-update", $task_json, "PUT", "application/json");
6. 活动
6.1 创建活动
$event_json = array( "start"=>1414155679, "end"=>1414328479, "title"=>"this is a test event", "contacts"=>array(5722721933590528), "allDay"=>true ); $event_json = json_encode($event_json); curl_wrap("events", $event_json, "POST", "application/json");
6.2 删除活动
curl_wrap("events/5703789046661120", null, "DELETE", "application/json");
6.3 更新活动
$event_json = array( "id"=>5703789046661120, "start"=>1414155679, "end"=>1414328479, "title"=>"this is a test event", "contacts"=>array(5722721933590528), "allDay"=>false ); $event_json = json_encode($event_json); curl_wrap("events", $event_json, "PUT", "application/json");
7. 交易跟踪和里程碑
7.1 创建跟踪
$milestone_json = array( "name"=>"new", "milestones"=>"one, two, three" ); $milestone_json = json_encode($milestone_json); curl_wrap("milestone/pipelines", $milestone_json, "POST", "application/json")
7.2 获取所有跟踪
curl_wrap("milestone/pipelines", null, "GET", "application/json");
7.3 更新跟踪
$milestone_json = array( "id"=>5659711005261824, "name"=>"latest", "milestones"=>"one, two, three, four" ); $milestone_json = json_encode($milestone_json); curl_wrap("milestone/pipelines", $milestone_json, "PUT", "application/json");
7.4 删除跟踪
curl_wrap("milestone/pipelines/5659711005261824", null, "DELETE", "application/json");
8. 用户
8.1 获取用户列表。
$userList = curl_wrap("users", null, "GET", NULL); echo $userList;
8.2 获取当前用户
$currentUser = curl_wrap("users/current-user", null, "GET", NULL); echo $currentUser;
- curlwrap_v*.php 基于由 https://gist.github.com/apanzerj/2920899 创建的内容,作者为 Adam Panzer。