diff --git a/curlwrap_v2.php b/CurlLib/curlwrap_v2.php similarity index 67% rename from curlwrap_v2.php rename to CurlLib/curlwrap_v2.php index be712f1..2e68b84 100644 --- a/curlwrap_v2.php +++ b/CurlLib/curlwrap_v2.php @@ -1,55 +1,66 @@ + */ + + +# Enter your domain name , agile email and agile api key + define("AGILE_DOMAIN", "your_agile_domain"); define("AGILE_USER_EMAIL", "your_agile_user_email"); define("AGILE_REST_API_KEY", "your_agile_api_key"); -function curl_wrap($entity, $data, $method) -{ - $agile_url = "https://" . AGILE_DOMAIN . ".agilecrm.com/dev/api/" . $entity; - $agile_php_url = "https://" . AGILE_DOMAIN . ".agilecrm.com/core/php/api/" . $entity . "?id=" . AGILE_REST_API_KEY; +function curl_wrap($entity, $data, $method, $content_type) { + + if ($content_type == NULL) { + $content_type = "application/json"; + } + + $agile_url = "https://" . AGILE_DOMAIN . ".agilecrm.com/dev/api/" . $entity; $ch = curl_init(); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_MAXREDIRS, 10); curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, true); - switch ($method) { case "POST": - $url = ($entity == "tags" ? $agile_php_url : $agile_url); + $url = $agile_url; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); break; case "GET": - $url = ($entity == "tags" ? $agile_php_url . '&email=' . $data->{'email'} : $agile_url); + $url = $agile_url; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); break; case "PUT": - $url = ($entity == "tags" ? $agile_php_url : $agile_url); + $url = $agile_url; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); break; case "DELETE": - $url = ($entity == "tags" ? $agile_php_url : $agile_url); + $url = $agile_url; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); break; default: break; } - curl_setopt($ch, CURLOPT_HTTPHEADER, array( - 'Content-type : application/json; charset : UTF-8;', - 'Accept : application/json' + "Content-type : $content_type;", 'Accept : application/json' )); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERPWD, AGILE_USER_EMAIL . ':' . AGILE_REST_API_KEY); curl_setopt($ch, CURLOPT_TIMEOUT, 120); - + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); $output = curl_exec($ch); curl_close($ch); return $output; } -?> diff --git a/PHP_API_v2.0.0.php b/PHP_API_v2.0.0.php deleted file mode 100644 index 2c2e1bf..0000000 --- a/PHP_API_v2.0.0.php +++ /dev/null @@ -1,310 +0,0 @@ -{'email'} : $agile_url); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); - break; - case "PUT": - $url = ($entity == "tags" ? $agile_php_url : $agile_url); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); - curl_setopt($ch, CURLOPT_POSTFIELDS, $data); - break; - case "DELETE": - $url = ($entity == "tags" ? $agile_php_url : $agile_url); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); - break; - default: - break; - } - - curl_setopt($ch, CURLOPT_HTTPHEADER, array( - 'Content-type : application/json;','Accept : application/json' - )); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_USERPWD, AGILE_USER_EMAIL . ':' . AGILE_REST_API_KEY); - curl_setopt($ch, CURLOPT_TIMEOUT, 120); -curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); - $output = curl_exec($ch); - curl_close($ch); - return $output; -} - -echo ""; -echo "

Reference taken from : https://github.com/agilecrm/php-api

"; - -echo ""; -echo ""; - -// To set contacts system and custom data -function setContactField($name, $value,$result){ -$name = $name; -$value = $value; -$properties = $result->properties; -foreach ($properties as $propertie) { - //echo "$propertie->name
"; - if (strcasecmp($name, $propertie->name) == 0) { - echo "$propertie->value"; - $propertie->value=$value; - } -} -} -// To set deals custom data -function setDealCustom($name, $value,$result){ -$name = $name; -$value = $value; -$custom_data = $result->custom_data; -foreach ($custom_data as $custom_data1) { - //echo "$propertie->name
"; - if (strcasecmp($name, $custom_data1->name) == 0) { - echo "$custom_data1->value"; - $custom_data1->value=$value; - } -} -} -?> diff --git a/README-v1.0.0.md b/README-v1.0.0.md deleted file mode 100644 index 09e56fe..0000000 --- a/README-v1.0.0.md +++ /dev/null @@ -1,257 +0,0 @@ -php-api v1.0.0 -============== - -PHP Client to Access Agile Functionality - -# Intro - -1. Fill in the your ***agile API key*** and ***agile domain*** in the file **curlwrap_v1.php** - -2. Copy and paste the source of curlwrap_v1.php in your php code. - -3. You need to provide 3 parameters to the curl_wrap function. They are **subject**, **JSON data** and **action**. - - a. **subject** should be one of "contact", "tags", "score", "note", "task", "deal". - - b. **JSON data** - - JSON data format should be as shown below. Email is mandatory. - -```php - $contact_json = array( - "email" => "contact@test.com", - "first_name" => "test", - "last_name" => "contact", - "tags" => "tag1, tag2" - ); - - $contact_json = json_encode($contact_json); -``` - - c. **action parameter** must to set to - - POST if you need to add an entity to contact like tags, or contact itself. - - GET if you need to fetch an entity associated with the contact. - - PUT to update contact properties, add / subtract score, or remove tags. - - DELETE to delete a contact. - -# Usage - -#### 1. Contact - -###### 1.1 To create a contact - -```php -$contact_json = array( - "email" => "contact@test.com", - "first_name" => "test", - "last_name" => "contact", - "tags" => "tag1, tag2", - "company" => "abc corp", - "title" => "lead", - "phone" => "+1-541-754-3010", - "website" => "http://www.example.com", - "address" => "{\"city\":\"new delhi\", \"state\":\"delhi\",\"country\":\"india\"}" - ); - -$contact_json = json_encode($contact_json); - -curl_wrap("contact", $contact_json, "POST"); -``` -###### 1.2 To fetch contact data - -```php -$json = array("email" => "contact@test.com"); - -$json = json_encode($json); - -curl_wrap("contact", $json, "GET"); -``` -###### 1.3 To delete a contact - -```php -$json = array("email" => "contact@test.com"); - -$json = json_encode($json); - -curl_wrap("contact", $json, "DELETE"); -``` -###### 1.4 To update a contact - -```php -$contact_json = array( - "email" => "contact@test.com", - "website" => "http://www.example.com", - "company" => "abc corp" - ); - -$contact_json = json_encode($contact_json); - -curl_wrap("contact", $contact_json, "PUT"); -``` - -- 1.4.1 Adding custom property - -```php -$contact_json = array( - "email" => "contact@test.com", - "custom_property_name" => "custom_property_value" - ); - -$contact_json = json_encode($contact_json); - -curl_wrap("contact", $contact_json, "PUT"); -``` - -#### 2. Note - -###### 2.1 To add Note - -```php -$note_json = array( - "email" => "contact@test.com", - "subject" => "test", - "description" => "note added" - ); - -$note_json = json_encode($note_json); - -curl_wrap("note", $note_json, "POST"); -``` -###### 2.2 To fetch notes related to contact - -```php -$json = array("email" => "contact@test.com"); - -$json = json_encode($json); - -curl_wrap("note", $json, "GET"); -``` - -#### 3. Score - -###### 3.1 To add score to contact - -```php -$score_json = array( - "email" => "contact@test.com", - "score" => "50" - ); - -$score_json = json_encode($score_json); - -curl_wrap("score", $score_json, "PUT"); -``` -###### 3.2 To get the score related to particular contact - -```php -$json = array("email" => "contact@test.com"); - -$json = json_encode($json); - -curl_wrap("score", $json, "GET"); -``` -###### 3.3 To subtract the score of contact - -```php -$subscore_json = array("email" => "contact@test.com", "score" => "-20"); - -$subscore_json = json_encode($subscore_json); - -curl_wrap("score", $json, "PUT"); -``` -#### 4. Task - -###### 4.1 To add task to contact - -```php -$task_json = array( - "email" => "contact@test.com", - "type" => "MEETING", - "priority_type" => "HIGH", - "subject" => "test", - "due" => "1376047332" - ); - -$task_json = json_encode($task_json); - -curl_wrap("tags", $tag_json, "POST"); -``` -###### 4.2 To get tasks related to contact - -```php -$json = array("email" => "contact@test.com"); - -$json = json_encode($json); - -curl_wrap("task", $json, "GET"); -``` -#### 5. Deal - -###### 5.1 To add deal to contact - -```php -$deal_json = array( - "email" => "contact@test.com", - "name" => "Test Deal", - "description" => "testing deal", - "expected_value" => "100", - "milestone" => "won", - "probability" => "5", - "close_date" => "1376047332" - ); - -$deal_json = json_encode($deal_json); - -curl_wrap("deal", $deal_json, "POST"); -``` - -###### 5.2 To get deals related to contact - -```php -$json = array("email" => "contact@test.com"); - -$json = json_encode($json); - -curl_wrap("deal", $json, "GET"); -``` - -#### 6. Tags - -###### 6.1 To add tags to contact - -```php -$tag_json = array( - "email" => "contact@test.com", - "tags" => "tag1, tag2, tag3, tag4, tag5" - ); - -$tag_json = json_encode($tag_json); - -curl_wrap("tags", $tag_json, "POST"); -``` -###### 6.2 To get tags related to contact - -```php -$json = array("email" => "contact@test.com"); - -$json = json_encode($json); - -curl_wrap("tags", $json, "GET"); -``` -###### 6.3 To remove tags related to contact - -```php -$rm_tags_json = array( - "email" => "contact@test.com", - "tags" => "tag3, tag4" - ); - -$rm_tags_json = json_encode($rm_tags_json); - -curl_wrap("tags", $rm_tags_json, "PUT"); -``` -For example implementation of all available API refer to [sample.php](https://github.com/agilecrm/php-api/blob/master/sample.php). diff --git a/README.md b/README.md index 5597bd6..d2bb023 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ -#PHP API v2.0.0 +#PHP API v3.0.0 PHP Client to access Agile functionality #Intro -1. Fill in your **AGILE_DOMAIN**, **AGILE_USER_EMAIL**, **AGILE_REST_API_KEY** in [**PHP_API_v2.0.0.php**](https://github.com/agilecrm/php-api/blob/master/PHP_API_v2.0.0.php). +1. Fill in your **AGILE_DOMAIN**, **AGILE_USER_EMAIL**, **AGILE_REST_API_KEY** in [**curlwrap_v2.php**](https://github.com/ghanraut/php-api/blob/master/CurlLib/curlwrap_v2.php). -2. Copy and paste the source / include the [**PHP_API_v2.0.0.php**](https://github.com/agilecrm/php-api/blob/master/PHP_API_v2.0.0.php) in your php code.(Note: Few source code like create contact, update contact, get contact etc. all redy there. ) +2. Copy and paste the source / include the [**curlwrap_v2.php**](https://github.com/ghanraut/php-api/blob/master/CurlLib/curlwrap_v2.php) in your php code. -3. You need to provide 3 paramaters to the curl_wrap function. They are **$entity**, **$data**, **$method**. +3. You need to provide 4 paramaters to the curl_wrap function. They are **$entity**, **$data**, **$method**, **$content-type**. - **$entity** should be one of *"contacts/{id}", "contacts", "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}"* depending on requirement. @@ -47,19 +47,26 @@ $data = json_encode($data); GET to fetch an entity. - PUT to update entity. + PUT to update an entity. DELETE to remove an entity. +- **$content-type** can be set to + + application/json. + + application/x-www-form-urlencoded (To valid form type data) + #Usage Response is stringified json, can use json_decode to change to json as below example: ```javascript -$result = curl_wrap("contacts/search/email/test@email.com", null, "GET"); -$result = json_decode($result, true); -$contact_id = $result['id']; +$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); ``` ## 1. Contact @@ -67,28 +74,65 @@ $contact_id = $result['id']; #### 1.1 To create a contact ```javascript +$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"=>"phprest", + "value"=>"Ronaldo", "type"=>"SYSTEM" ), array( "name"=>"last_name", - "value"=>"contact", + "value"=>"de Lima", "type"=>"SYSTEM" ), array( "name"=>"email", - "value"=>"phprest@contact.com", + "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"); +curl_wrap("contacts", $contact_json, "POST", "application/json"); ``` #### 1.2 To fetch contact data @@ -96,27 +140,31 @@ curl_wrap("contacts", $contact_json, "POST"); ###### by id ```javascript -curl_wrap("contacts/5722721933590528", null, "GET"); +curl_wrap("contacts/5722721933590528", null, "GET", "application/json"); ``` ###### by email ```javascript -curl_wrap("contacts/search/email/test@email.com", null, "GET"); +curl_wrap("contacts/search/email/test@email.com", null, "GET", "application/json"); ``` #### 1.3 To delete a contact ```javascript -curl_wrap("contacts/5722721933590528", null, "DELETE"); +curl_wrap("contacts/5722721933590528", null, "DELETE", "application/json"); ``` #### 1.4 To update a contact -- **Note** To update contact, send all related data of the same contact aslo, otherwise we will get lost of data after update contact successfully done. +- **Note** Please send all data related to contact. ```javascript + $contact_json = array( - "id"=>5722721933590528, + "id"=>"5722721933590528",//It is mandatory filed. Id of contact + "lead_score"=>"80", + "star_value"=>"5", + "tags"=>array("Player","Winner"), "properties"=>array( array( "name"=>"first_name", @@ -130,14 +178,111 @@ $contact_json = array( ), array( "name"=>"email", - "value"=>"phprest@contact.com", + "value"=>"tester@agilecrm.com", + "type"=>"SYSTEM" + ) + ) +); + +$contact_json = json_encode($contact_json); +curl_wrap("contacts", $contact_json, "PUT", "application/json"); +``` + +#### 1.5 Update properties of a contact (Partial update) + +- **Note** Send only requierd properties data to update contact. No need to send all data of a contact. + +```javascript + +$contact_json = array( + "id"=>5722721933590528, //It is mandatory filed. 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", $contact_json, "PUT"); +curl_wrap("contacts/edit-properties", $contact_json, "PUT", "application/json"); +``` + +#### 1.6 Edit star value + +```javascript + +$contact_json = array( + "id"=>5722721933590528, //It is mandatory filed. Id of contact + "star_value"=>"5" +); + +$contact_json = json_encode($contact_json); +curl_wrap("contacts/add-star", $contact_json, "PUT", "application/json"); +``` + +#### 1.7 Add Score to a Contact using Email-ID + +```javascript + +$fields = array( + 'email' => urlencode("haka@gmail.com"), + 'score' => urlencode("30") + ); + $fields_string = ''; + foreach ($fields as $key => $value) { + $fields_string .= $key . '=' . $value . '&'; + } + +curl_wrap("contacts/add-score", rtrim($fields_string, '&'), "POST", "application/x-www-form-urlencoded"); +``` + +#### 1.8 Adding Tags to a contact based on Email + +```javascript + + $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 Delete Tags to a contact based on Email + +```javascript + + $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. Company @@ -162,19 +307,19 @@ $company_json = array( ); $company_json = json_encode($company_json); -curl_wrap("contacts", $company_json, "POST"); +curl_wrap("contacts", $company_json, "POST", "application/json"); ``` #### 2.2 To get a company ```javascript -curl_wrap("contacts/5695414665740288", null, "GET"); +curl_wrap("contacts/5695414665740288", null, "GET", "application/json"); ``` #### 2.3 To delete a company ```javascript -curl_wrap("contacts/5695414665740288", null, "DELETE") +curl_wrap("contacts/5695414665740288", null, "DELETE", "application/json") ``` #### 2.4 To update a company @@ -197,11 +342,13 @@ $company_json = array( ); $company_json = json_encode($company_json); -curl_wrap("contacts", $company_json, "PUT"); +curl_wrap("contacts", $company_json, "PUT", "application/json"); ``` # 3. Deal (Opportunity) +- **Note** Milestone name is case sensitive. It should be exactly as in your Agile CRM + #### 3.1 To create a deal ```javascript @@ -226,46 +373,81 @@ $opportunity_json = array( ); $opportunity_json = json_encode($opportunity_json); -curl_wrap("opportunity", $opportunity_json, "POST"); +curl_wrap("opportunity", $opportunity_json, "POST", "application/json"); ``` #### 3.2 To get a deal ```javascript -curl_wrap("opportunity/5739083074633728", null, "GET"); +curl_wrap("opportunity/5739083074633728", null, "GET", "application/json"); ``` #### 3.3 To delete a deal ```javascript -curl_wrap("opportunity/5739083074633728", null, "DELETE"); +curl_wrap("opportunity/5739083074633728", null, "DELETE", "application/json"); ``` #### 3.4 To update deal +- **Note** Please send all data related to deal. + ```javascript $opportunity_json = array( - "id"=>5739083074633728, - "name"=>"test", - "description"=>"this is a test deal", - "expected_value"=>1000, - "milestone"=>"Open", - "custom_data"=>array( - array( - "name"=>"data1", - "value"=>"abc" + "id" => "5202889022636032", //It is mandatory filed. Id of deal + "description" => "this is a test deal", + "expected_value" => 1000, + "milestone" => "Open", + "pipeline_id" => "5502889022636568", + "custom_data" => array( + array( + "name" => "dataone", + "value" => "xyz" + ), + array( + "name" => "datatwo", + "value" => "abc" + ) ), - array( - "name"=>"data2", - "value"=>"xyz" - ) - ), - "probability"=>50, - "close_date"=>1414317504, - "contact_ids"=>array(5722721933590528) + "probability" => 50, + "close_date" => 1414317504, + "contact_ids" => array("5641841626054656", "5756422495141888") +); + +$opportunity_json = json_encode($opportunity_json); +curl_wrap("opportunity", $opportunity_json, "PUT", "application/json"); +``` + +#### 3.5 To update deal (Partial update) + +```javascript +$opportunity_json = array( + "id" => "5202889022636032", //It is mandatory filed. Id of deal + "expected_value" => 1000, + "milestone" => "Open", + "pipeline_id" => "5502889022636568", + "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, "PUT"); +curl_wrap("opportunity/partial-update", $opportunity_json, "PUT", "application/json"); +``` + +#### 3.6 Get deals related to specific contact by contact id + +```javascript +curl_wrap("contacts/5739083074633728/deals", null, "GET", "application/json"); ``` # 4. Note @@ -281,13 +463,13 @@ $note_json = array( ); $note_json = json_encode($note_json); -curl_wrap("notes", $note_json, "POST"); +curl_wrap("notes", $note_json, "POST", "application/json"); ``` #### 4.2 To get all notes *related to specific contact* ```javascript -curl_wrap("contacts/5722721933590528/notes", null, "GET"); +curl_wrap("contacts/5722721933590528/notes", null, "GET", "application/json"); ``` #### 4.3 To update a note @@ -302,7 +484,7 @@ $note_json = array( ); $note_json = json_encode($note_json); -curl_wrap("notes", $note_json, "PUT"); +curl_wrap("notes", $note_json, "PUT", "application/json"); ``` @@ -322,19 +504,19 @@ $task_json = array( ); $task_json = json_encode($task_json); -curl_wrap("tasks", $task_json, "POST"); +curl_wrap("tasks", $task_json, "POST", "application/json"); ``` #### 5.2 To get a task ```javascript -curl_wrap("tasks/5752207420948480", null, "GET"); +curl_wrap("tasks/5752207420948480", null, "GET", "application/json"); ``` #### 5.3 To delete a task ```javascript -curl_wrap("tasks/5752207420948480", null, "DELETE"); +curl_wrap("tasks/5752207420948480", null, "DELETE", "application/json"); ``` #### 5.4 To update a task @@ -352,7 +534,7 @@ $task_json = array( ); $task_json = json_encode($task_json); -curl_wrap("tasks", $task_json, "PUT"); +curl_wrap("tasks", $task_json, "PUT", "application/json"); ``` # 6. Event @@ -368,13 +550,13 @@ $event_json = array( ); $event_json = json_encode($event_json); -curl_wrap("events", $event_json, "POST"); +curl_wrap("events", $event_json, "POST", "application/json"); ``` #### 6.2 To delete a event ```javascript -curl_wrap("events/5703789046661120", null, "DELETE"); +curl_wrap("events/5703789046661120", null, "DELETE", "application/json"); ``` #### 6.3 To update a event @@ -390,7 +572,7 @@ $event_json = array( ); $event_json = json_encode($event_json); -curl_wrap("events", $event_json, "PUT"); +curl_wrap("events", $event_json, "PUT", "application/json"); ``` # 7. Deal Tracks and Milestones @@ -404,13 +586,13 @@ $milestone_json = array( ); $milestone_json = json_encode($milestone_json); -curl_wrap("milestone/pipelines", $milestone_json, "POST") +curl_wrap("milestone/pipelines", $milestone_json, "POST", "application/json") ``` #### 7.2 To get all tracks ```javascript -curl_wrap("milestone/pipelines", null, "GET"); +curl_wrap("milestone/pipelines", null, "GET", "application/json"); ``` #### 7.3 To update track @@ -423,46 +605,13 @@ $milestone_json = array( ); $milestone_json = json_encode($milestone_json); -curl_wrap("milestone/pipelines", $milestone_json, "PUT"); +curl_wrap("milestone/pipelines", $milestone_json, "PUT", "application/json"); ``` #### 7.4 To delete a track ```javascript -curl_wrap("milestone/pipelines/5659711005261824", null, "DELETE"); -``` - -# 8. Tags - -#### 8.1 To add tags to contact - -```javascript -$tag_json = array( - "email" => "phprest@contact.com", - "tags" => "tag1, tag2, tag3, tag4, tag5" - ); - -$tag_json = json_encode($tag_json); -curl_wrap("tags", $tag_json, "POST"); -``` -#### 8.2 To get tags related to contact - -```javascript -$json = array("email" => "phprest@contact.com"); - -$json = json_encode($json); -curl_wrap("tags", $json, "GET"); -``` -#### 8.3 To remove tags related to contact - -```javascript -$rm_tags_json = array( - "email" => "phprest@contact.com", - "tags" => "tag3, tag4" - ); - -$rm_tags_json = json_encode($rm_tags_json); -curl_wrap("tags", $rm_tags_json, "PUT"); +curl_wrap("milestone/pipelines/5659711005261824", null, "DELETE", "application/json"); ``` ---- diff --git a/Tester/contact_sample_test.php b/Tester/contact_sample_test.php new file mode 100644 index 0000000..ffd4438 --- /dev/null +++ b/Tester/contact_sample_test.php @@ -0,0 +1,202 @@ + + */ +include("../CurlLib/curlwrap_v2.php"); + +echo "

Reference taken from : https://github.com/agilecrm/php-api

"; +echo '
'; + +// **************************Get Contact By email id.******************** + +$contact1 = curl_wrap("contacts/search/email/test@gmail.com", null, "GET", NULL); +echo $contact1; + +// **************************Get Contact By contact id.******************** + +$contact2 = curl_wrap("contacts/5722721933590528", null, "GET", NULL); +echo $contact2; + +// **************************Get contact Id of a contact.****************** + +$contact3 = curl_wrap("contacts/search/email/test@gmail.com", null, "GET", NULL); +$result = json_decode($contact3, false, 512, JSON_BIGINT_AS_STRING); +$contact_id = $result->id; +print_r($contact_id); + +// **************************Create contact******************************** + +$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_input = json_encode($contact_json); +$contact4 = curl_wrap("contacts", $contact_json_input, "POST", "application/json"); +echo $contact4; + +// **************************Update contact******************************** +// Note : To use this method, you have to send all data related to this contact id +// Note : Otherwise you can lose other data, which is not sent. Better use partial update + +$contact_json_update = array( + "id" => 5722721933590528, //It is mandatory filed. Id of contact + "lead_score" => "80", + "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" + ) + ) +); + +$contact_json_update_input = json_encode($contact_json_update); +$contact5 = curl_wrap("contacts", $contact_json_update_input, "PUT", "application/json"); +echo $contact5; + + +// ***********Update properties of a contact (Partial update)************** +// Note : No need to send all the data of a contact only the properties want to update. + +$contact_json_partial_update = array( + "id" => 5722721933590528, //It is mandatory filed. Id of contact + "properties" => array( + array( + "name" => "first_name", + "value" => "php", + "type" => "SYSTEM" + ), + array( + "name" => "Total experience in field", + "value" => "10", + "type" => "CUSTOM" + ) + ) +); + +$contact_json_partial_update1 = json_encode($contact_json_partial_update); +$contact6 = curl_wrap("contacts/update/properties", $contact_json_partial_update1, "PUT", "application/json"); +echo $contact6; + +// **************************Edit star value ******************************** + +$contact_json_star = array( + "id" => 5722721933590528, //It is mandatory filed. Id of contact + "star_value" => "5" +); + +$contact_json_star_input = json_encode($contact_json_star); +curl_wrap("contacts/add-star", $contact_json_star_input, "PUT", "application/json"); + +// **************************Add score to a contact by email **************** + +$form_fields = array( + 'email' => urlencode("haka@gmail.com"), + 'score' => urlencode("30") +); +$fields_string = ''; +foreach ($form_fields as $key => $value) { + $fields_string .= $key . '=' . $value . '&'; +} + +$contac7 = curl_wrap("contacts/add-score", rtrim($fields_string, '&'), "POST", "application/x-www-form-urlencoded"); + +echo $contact7; + +// **************************Add tags to a contact by email ******************************** + +$form_fields1 = array( + 'email' => urlencode("haka@gmail.com"), + 'tags' => urlencode('["testing"]') +); +$fields_string1 = ''; +foreach ($form_fields1 as $key => $value) { + $fields_string1 .= $key . '=' . $value . '&'; +} + +$tags1 = curl_wrap("contacts/email/tags/add", rtrim($fields_string1, '&'), "POST", "application/x-www-form-urlencoded"); + +echo $tags1; + +// **************************Delete tags to a contact by email ******************************** + +$form_fields2 = array( + 'email' => urlencode("haka@gmail.com"), + 'tags' => urlencode('["testing"]') +); +$fields_string2 = ''; +foreach ($form_fields2 as $key => $value) { + $fields_string2 .= $key . '=' . $value . '&'; +} + +$tags2 = curl_wrap("contacts/email/tags/delete", rtrim($fields_string1, '&'), "POST", "application/x-www-form-urlencoded"); + +echo $tags2; + diff --git a/Tester/deal_sample_test.php b/Tester/deal_sample_test.php new file mode 100644 index 0000000..626ac2c --- /dev/null +++ b/Tester/deal_sample_test.php @@ -0,0 +1,38 @@ + + */ +include("../CurlLib/curlwrap_v2.php"); + +echo "

Reference taken from : https://github.com/agilecrm/php-api

"; +echo '
'; + +$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_input = json_encode($opportunity_json); +$deal = curl_wrap("opportunity", $opportunity_json_input, "POST", "application/json"); + +echo $deal; diff --git a/Tester/note_sample_test.php b/Tester/note_sample_test.php new file mode 100644 index 0000000..4ffda9f --- /dev/null +++ b/Tester/note_sample_test.php @@ -0,0 +1,25 @@ + + */ +include("../CurlLib/curlwrap_v2.php"); + +echo "

Reference taken from : https://github.com/agilecrm/php-api

"; +echo '
'; + +$note_json = array( + "subject" => "test note", + "description" => "this is a test note", + "contact_ids" => array("5641841626054656", "5756422495141888") +); + +$note_json_input = json_encode($note_json); +$note = curl_wrap("notes", $note_json_input, "POST", "application/json"); + +echo $note; + diff --git a/Tester/task_sample_test.php b/Tester/task_sample_test.php new file mode 100644 index 0000000..6143191 --- /dev/null +++ b/Tester/task_sample_test.php @@ -0,0 +1,25 @@ + + */ +include("../CurlLib/curlwrap_v2.php"); + +echo "

Reference taken from : https://github.com/agilecrm/php-api

"; +echo '
'; + +$task_json = array( + "type" => "MILESTONE", + "priority_type" => "HIGH", + "contacts" => array("5641841626054656", "5756422495141888"), + "subject" => "this is a test task", + "status" => "YET_TO_START", +); + +$task_json_input = json_encode($task_json); +$task = curl_wrap("tasks", $task_json_input, "POST", "application/json"); +echo $task; diff --git a/curlwrap_v1.php b/curlwrap_v1.php deleted file mode 100644 index b2375c7..0000000 --- a/curlwrap_v1.php +++ /dev/null @@ -1,46 +0,0 @@ -true, - CURLOPT_MAXREDIRS=>10, - )); - switch($action) - { - case "POST": - curl_setopt($ch,CURLOPT_URL,'https://'.domain.'.agilecrm.com/core/php/api/'.$subject.'?id='.apikey); - curl_setopt($ch,CURLOPT_CUSTOMREQUEST,"POST"); - curl_setopt($ch,CURLOPT_POSTFIELDS,$json); - break; - case "GET": - $json = json_decode($json); - curl_setopt($ch,CURLOPT_CUSTOMREQUEST,"GET"); - curl_setopt($ch,CURLOPT_URL,'https://'.domain.'.agilecrm.com/core/php/api/'.$subject.'?id='.apikey.'&email='.$json->{'email'}); - break; - case "PUT": - curl_setopt($ch,CURLOPT_URL,'https://'.domain.'.agilecrm.com/core/php/api/'.$subject.'?id='.apikey); - curl_setopt($ch,CURLOPT_CUSTOMREQUEST,"PUT"); - curl_setopt($ch,CURLOPT_POSTFIELDS,$json); - break; - case "DELETE": - $json = json_decode($json); - curl_setopt($ch,CURLOPT_URL,'https://'.domain.'.agilecrm.com/core/php/api/'.$subject.'?id='.apikey.'&email='.$json->{'email'}); - curl_setopt($ch,CURLOPT_CUSTOMREQUEST,"DELETE"); - break; - default: - break; - } - curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json;')); - curl_setopt_array($ch, array( - CURLOPT_RETURNTRANSFER=>true, - CURLOPT_TIMEOUT=>120 - )); - $output= curl_exec($ch); - curl_close($ch); - return $output; -} -?> diff --git a/index.php b/index.php new file mode 100644 index 0000000..6c1ded0 --- /dev/null +++ b/index.php @@ -0,0 +1,24 @@ + + + + + + + + + Reference taken from : https://github.com/agilecrm/php-api"; + echo '
'; + + $contact = curl_wrap("contacts/search/email/haka@gmail.com", null, "GET", NULL); + echo $contact; + ?> + + diff --git a/sample.php b/sample.php deleted file mode 100644 index 9be4acc..0000000 --- a/sample.php +++ /dev/null @@ -1,149 +0,0 @@ -true, - CURLOPT_MAXREDIRS=>10, - )); - switch($action) - { - case "POST": - curl_setopt($ch,CURLOPT_URL,'https://'.domain.'.agilecrm.com/core/php/api/'.$subject.'?id='.apikey); - curl_setopt($ch,CURLOPT_CUSTOMREQUEST,"POST"); - curl_setopt($ch,CURLOPT_POSTFIELDS,$json); - break; - case "GET": - $json = json_decode($json); - curl_setopt($ch,CURLOPT_CUSTOMREQUEST,"GET"); - curl_setopt($ch,CURLOPT_URL,'https://'.domain.'.agilecrm.com/core/php/api/'.$subject.'?id='.apikey.'&email='.$json->{'email'}); - break; - case "PUT": - curl_setopt($ch,CURLOPT_URL,'https://'.domain.'.agilecrm.com/core/php/api/'.$subject.'?id='.apikey); - curl_setopt($ch,CURLOPT_CUSTOMREQUEST,"PUT"); - curl_setopt($ch,CURLOPT_POSTFIELDS,$json); - break; - case "DELETE": - $json = json_decode($json); - curl_setopt($ch,CURLOPT_URL,'https://'.domain.'.agilecrm.com/core/php/api/'.$subject.'?id='.apikey.'&email='.$json->{'email'}); - curl_setopt($ch,CURLOPT_CUSTOMREQUEST,"DELETE"); - break; - default: - break; - } - curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset : UTF-8;')); - curl_setopt_array($ch, array( - CURLOPT_RETURNTRANSFER=>true, - CURLOPT_TIMEOUT=>120 - )); - $output= curl_exec($ch); - curl_close($ch); - return $output; -} - -# To add contact -$contact_json = array("email"=>"contact@test.com", "first_name"=>"test", "last_name"=>"contact", "tags"=>"tag1, tag2"); -$contact_json = json_encode($contact_json); -curl_wrap("contact", $contact_json, "POST"); - -# To update contact -$contact_json = array("email"=>"contact@test.com", "website"=>"http://example.com", "company"=>"ABC Corp"); -$contact_json = json_encode($contact_json); -curl_wrap("contact", $contact_json, "PUT"); - -# To delete contact -$json = array("email"=>"contact@test.com"); -$json = json_encode($json); -curl_wrap("contact", $json, "DELETE"); - -# To get contact details -$json = array("email"=>"contact@test.com"); -$json = json_encode($json); -curl_wrap("contact", $json, "GET"); - -# To add note -$note_json = array("email"=>"contact@test.com", "subject"=>"test", "description"=>"note"); -$note_json = json_encode($note_json); -curl_wrap("note", $note_json, "POST"); - -# To get notes related to contact -$json = array("email"=>"contact@test.com"); -$json = json_encode($json); -curl_wrap("note", $json, "GET"); - -# To add score to contact -$score_json = array("email"=>"contact@test.com", "score"=>"50"); -$score_json = json_encode($score_json); -curl_wrap("score", $score_json, "PUT"); - -# To subtract score -$subscore_json = array("email"=>"contact@test.com", "score"=>"-20"); -$subscore_json = json_encode($subscore_json); -curl_wrap("score", $subscore_json, "PUT"); - -# To get current score of contact -$json = array("email"=>"contact@test.com"); -$json = json_encode($json); -curl_wrap("score", $json, "GET"); - -# To add task -$task_json = array("type"=>"MEETING", "priority_type"=>"HIGH", "subject"=>"test", "email"=>"contact@test.com"); -$task_json = json_encode($task_json); -curl_wrap("task", $task_json, "POST"); - -# To get tasks related to a contact -$json = array("email"=>"contact@test.com"); -$json = json_encode($json); -curl_wrap("task", $json, "GET"); - -# To add a deal to contact -$deal_json = array("name"=>"Test Deal", "description"=>"testing deal", "expected_value"=>"100", "milestone"=>"won", - "probability"=>"5", "close_date"=>"1376047332", "email"=>"contact@test.com"); - # close date in epoch time -$deal_json = json_encode($deal_json); -curl_wrap("deal", $deal_json, "POST"); - -# To get deals associated with contact -$json = array("email"=>"contact@test.com"); -$json = json_encode($json); -curl_wrap("deal", $json, "GET"); - -# To add tags -$tag_json = array("email"=>"contact@test.com", "tags"=>"tag1, tag2, tag3, tag4, tag5"); -$tag_json = json_encode($tag_json); -curl_wrap("tags", $tag_json, "POST"); - -# To delete tags -$rm_tags_json = array("tags"=>"tag3, tag4", "email"=>"contact@test.com"); -$rm_tags_json = json_encode($rm_tags_json); -curl_wrap("tags", $rm_tags_json, "PUT"); - -# To get tags assigned to a contact -$json = array("email"=>"contact@test.com"); -$json = json_encode($json); -curl_wrap("tags", $json, "GET"); -?>