From 37baea529d4b3f40abab4924567a5ef103d6f006 Mon Sep 17 00:00:00 2001 From: ghanraut Date: Thu, 19 Nov 2015 17:33:46 +0530 Subject: [PATCH 01/15] delete delete --- README-v1.0.0.md | 257 ----------------------------------------------- 1 file changed, 257 deletions(-) delete mode 100644 README-v1.0.0.md 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). From edf7b57a0d05f40e0763b59784133afaca590961 Mon Sep 17 00:00:00 2001 From: ghanraut Date: Thu, 19 Nov 2015 17:34:18 +0530 Subject: [PATCH 02/15] delete delete --- curlwrap_v1.php | 46 ---------------------------------------------- 1 file changed, 46 deletions(-) delete mode 100644 curlwrap_v1.php 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; -} -?> From 4c7d23da9c926e9451c5e5cfa4f809c7cb50ab5b Mon Sep 17 00:00:00 2001 From: ghanraut Date: Thu, 19 Nov 2015 17:34:42 +0530 Subject: [PATCH 03/15] delete delete --- sample.php | 149 ----------------------------------------------------- 1 file changed, 149 deletions(-) delete mode 100644 sample.php 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"); -?> From 7261fb8f415a85cc567929bb99c5e94cb295785a Mon Sep 17 00:00:00 2001 From: graut Date: Thu, 19 Nov 2015 17:47:02 +0530 Subject: [PATCH 04/15] Test-API This is general test --- contact_sample_test.php | 8 ++++++++ curlwrap_v2.php | 38 +++++++++++++++++++++----------------- deal_sample_test.php | 8 ++++++++ index.php | 23 +++++++++++++++++++++++ note_sample_test.php | 8 ++++++++ task_sample_test.php | 8 ++++++++ 6 files changed, 76 insertions(+), 17 deletions(-) create mode 100644 contact_sample_test.php create mode 100644 deal_sample_test.php create mode 100644 index.php create mode 100644 note_sample_test.php create mode 100644 task_sample_test.php diff --git a/contact_sample_test.php b/contact_sample_test.php new file mode 100644 index 0000000..3ac00fa --- /dev/null +++ b/contact_sample_test.php @@ -0,0 +1,8 @@ +
'; + $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; - + //$agile_php_url = "https://" . AGILE_DOMAIN . ".agilecrm.com/core/php/api/" . $entity . "?id=" . AGILE_REST_API_KEY; $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/deal_sample_test.php b/deal_sample_test.php new file mode 100644 index 0000000..3ac00fa --- /dev/null +++ b/deal_sample_test.php @@ -0,0 +1,8 @@ + + + + + + + + + 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/note_sample_test.php b/note_sample_test.php new file mode 100644 index 0000000..3ac00fa --- /dev/null +++ b/note_sample_test.php @@ -0,0 +1,8 @@ + Date: Thu, 19 Nov 2015 17:57:06 +0530 Subject: [PATCH 05/15] New data from older Test --- README.md | 213 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 185 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 5597bd6..fb8439f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -#PHP API v2.0.0 +#PHP API v3.0.0 PHP Client to access Agile functionality #Intro @@ -67,23 +67,60 @@ $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" ) + ) ); @@ -112,11 +149,15 @@ curl_wrap("contacts/5722721933590528", null, "DELETE"); #### 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,7 +171,7 @@ $contact_json = array( ), array( "name"=>"email", - "value"=>"phprest@contact.com", + "value"=>"tester@agilecrm.com", "type"=>"SYSTEM" ) ) @@ -140,6 +181,103 @@ $contact_json = json_encode($contact_json); curl_wrap("contacts", $contact_json, "PUT"); ``` +#### 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/edit-properties", $contact_json, "PUT"); +``` + +#### 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"); +``` + +#### 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 #### 2.1 To create a company @@ -243,29 +381,48 @@ curl_wrap("opportunity/5739083074633728", null, "DELETE"); #### 3.4 To update 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" - ), - array( - "name"=>"data2", - "value"=>"xyz" - ) - ), - "probability"=>50, - "close_date"=>1414317504, - "contact_ids"=>array(5722721933590528) -); +//Get deal by deal id to update. +$deal = curl_wrap("opportunity/5712508065153024", null, "GET"); -$opportunity_json = json_encode($opportunity_json); +$result = json_decode($deal, false, 512, JSON_BIGINT_AS_STRING); + +$result->name="hello test deal"; // Set deal name with new data. +$result->expected_value="1000"; // Set deal expected_value with new data. Value should not be null. +$result->milestone="New"; // Milestone name should be exactly as in agilecrm website. http://snag.gy/xjAbc.jpg +$result->pipeline_id="5767790501822464"; + +// If you are updating milestone then pipeline_id is mandatory field. pipeline_id is the id of track, +// Otherwise comment milestone and pipeline_id to just change other field. + +setDealCustom("dealTester","this is text custom data",$result); // Set Custom filed dealTester with new data.This is example of text field type. +setDealCustom("dealAddedDate","11/25/2015",$result); // Set Custom filed dealAddedDate with new data.This is example of date filed type. + +if (sizeof($result->notes) > 0) { // This code checks deal has any notes or not, don't remove this if condition. + $result->notes=$result->note_ids; +} + +$opportunity_json = json_encode($result); curl_wrap("opportunity", $opportunity_json, "PUT"); + +function setDealCustom($name, $value,$result){ +$custom_datas = $result->custom_data; +foreach ($custom_datas as $custom_data1) { + + if (strcasecmp($name, $custom_data1->name) == 0) { + $custom_data1->value=$value; + return; + } +} + +$contactField = (object) array( + "name" => $name, + "value" => $value + ); + + $custom_datas[]=$contactField; + $result->custom_data=$custom_datas; + +} ``` # 4. Note From 21852d2a04ae3b630ebcadac1fbb3bab96265836 Mon Sep 17 00:00:00 2001 From: ghanraut Date: Thu, 19 Nov 2015 18:05:18 +0530 Subject: [PATCH 06/15] New Version All new updation --- README.md | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index fb8439f..883d204 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,11 @@ 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/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/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. @@ -51,6 +51,12 @@ $data = json_encode($data); DELETE to remove an entity. +- **$content-type** can be set to + + application/json. + + application/x-www-form-urlencoded (To valid form type data) + #Usage @@ -58,8 +64,9 @@ Response is stringified json, can use json_decode to change to json as below exa ```javascript $result = curl_wrap("contacts/search/email/test@email.com", null, "GET"); -$result = json_decode($result, true); -$contact_id = $result['id']; +$result = json_decode($result, false, 512, JSON_BIGINT_AS_STRING); +$contact_id = $result->id; +print_r($contact_id); ``` ## 1. Contact From f3614275fee1e69191feac5311019a39e60e1886 Mon Sep 17 00:00:00 2001 From: ghanraut Date: Thu, 19 Nov 2015 18:11:10 +0530 Subject: [PATCH 07/15] Not required This file is not required any more --- PHP_API_v2.0.0.php | 310 --------------------------------------------- 1 file changed, 310 deletions(-) delete mode 100644 PHP_API_v2.0.0.php 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 "
    "; - -/*================================================To create a contact ================================================*/ -$address = array( - "address"=>"Avenida Álvares Cabral 1777", - "city"=>"Belo Horizonte", - "state"=>"Minas Gerais", - "country"=>"Brazil" -); - -$contact_email = "ronaldo123@gmail.com"; - - - -$new_contact_json = array( - "lead_score"=>"24", - "star_value"=>"4", - "tags"=>array("test1","test2"), - "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"=>"the phenomenon", - "type"=>"SYSTEM" - ), - array( - "name"=>"image", - "value"=>"http://www.soccerticketsonline.com/wp-content/uploads/ronaldo9.jpg", //This image value is url of image. - "type"=>"SYSTEM" // As of now we are not supporting image from local system path - ), - array( - "name"=>"company", - "value"=>"ibm", - "type"=>"SYSTEM" - ), - array( - "name"=>"address", - "value"=>json_encode($address), - "type"=>"SYSTEM" - ), - array( - "name"=>"phone", - "value"=>"+1-541-754-3030", - "type"=>"SYSTEM" - ), - array( - "name"=>"website", - "value"=>"http://www.google.com", - "type"=>"SYSTEM" - ), - array( - "name"=>"experience in field", //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" - ) - - ) -); -$new_contact_json = json_encode($new_contact_json); - - -echo "
  • contact created with following data

  • "; -echo "
  • " . $new_contact_json . "

  • "; -$result = curl_wrap("contacts", $new_contact_json, "POST"); -echo "
  • created contact data is ...

  • "; -echo "
  • " . $result . "
  • "; -echo "


    "; - -/*================================================= create contact end ================================================*/ - -/*================================================= update contact ================================================*/ - -$contact = curl_wrap("contacts/search/email/ronaldo123@gmail.com", null, "GET"); -//Get contact by email and update it. -$result = json_decode($contact, false, 512, JSON_BIGINT_AS_STRING); - -$result->lead_score = "150"; -$address = array( - "address"=>"MIG-107", - "city"=>"Belo Horizonto", - "state"=>"Minas Gerais", - "country"=>"Brazil" -); -$address1=json_encode($address); -setContactField("address",$address1,$result); // Set contact address with new data -setContactField("last_name","de lama2",$result); -setContactField("DOP","1444718961",$result); // Set DOP custom data of date type. -setContactField("text sample test","hello text sample test",$result); // Set text sample test custom data of textfiled type - - -$new_contact_json1 = json_encode($result); -echo "
  • contact updated with following data

  • "; -echo "
  • " . $new_contact_json1 . "

  • "; -$result = curl_wrap("contacts", $new_contact_json1, "PUT"); -echo "
  • updated contact data is ...

  • "; -echo "
  • " . $result . "
  • "; -echo "


    "; - -/*===========================================update contact end================================================*/ - - -/* ------------------------------------get contact by email and get contact id also ---------------------------- */ - -echo "
  • get contact with email id, and find also get conatct id of this contact

  • "; -echo "
    "; -$result = curl_wrap("contacts/search/email/ronaldo123@gmail.com", null, "GET"); -echo "
  • contact data received is ...

  • "; -echo "
  • " . $result . "

  • "; - -echo "
  • contact id of contact received is ...

  • "; - -$result = json_decode($result, true); -$contact_id = $result['id']; -$contact_id1 = number_format($contact_id,0,'',''); -echo "
  • " . $contact_id1 . "
  • "; -echo "


    "; -/* ------------------------------------get contact by email END----------------------------------------- */ - -/* ------------------------------------get contact by contact_id ----------------------------------------- */ -echo "
  • get contact by conatct id

  • "; -echo "
    "; -$result = curl_wrap("contacts/5706163895140352", null, "GET"); // More info :https://github.com/agilecrm/php-api#by-id -echo "
  • contact data received is ...

  • "; -echo "
  • " . $result . "
  • "; - -echo "


    "; -/* ------------------------------------get contact by contact_id END----------------------------------------- */ - -/* ------------------------------------delete contact by contact_id ----------------------------------------- */ -echo "
  • get contact with email id and find also conatct id

  • "; -echo "
    "; -$result = curl_wrap("contacts/5632908932939776", null, "DELETE"); -echo "
  • deleted response received is ...

  • "; -echo "
  • " . $result . "
  • "; - -echo "


    "; -/* ------------------------------------delete contact by contact_id END----------------------------------------- */ - - -/*=================================================== create deal=======================================*/ - - $opportunity_json = array( - "name"=>"test deal1", - "description"=>"this is a test deal", - "expected_value"=>1000, - "milestone"=>"New", - "custom_data"=>array( //This is custom field which you should first define in custom field region. - //Example :http://snag.gy/OOuj8.jpg - array( - "name"=>"dataone", - "value"=>"xyz" - ), - array( - "name"=>"datatwo", - "value"=>"abc" - ) - ), - "probability"=>50, - "close_date"=>1438948949, - "contact_ids"=>array("5706163895140352") // Contact ID to which deal going to added -); -$opportunity_json = json_encode($opportunity_json); -echo "
  • create deal with below data

  • "; -echo "
  • " . $opportunity_json . "

  • "; -$result = curl_wrap("opportunity", $opportunity_json, "POST"); -echo "
  • created deal data is ...

  • "; -echo "
  • " . $result . "
  • "; -echo "


    "; - -/*===================================================== create deal end================================================*/ - -/*===================================================== update deal================================================*/ - -$deal = curl_wrap("opportunity/5649648836411392", null, "GET");//Get deal by deal id to update. -$result = json_decode($deal, false, 512, JSON_BIGINT_AS_STRING); - -$result->name="helo test"; -$result->expected_value="1000"; // Should not be null; -$result->milestone="Proposal"; // Milestone name should be exactly as in agilecrm website. http://snag.gy/xjAbc.jpg -$result->pipeline_id="5767790501822464"; - -// If you are updating milestone then pipeline_id is mandatory field. pipeline_id is the id of track, -// Otherwise comment milestone and pipeline_id to just change other field. - -setDealCustom("Message","this is text custom data",$result); // Setting custom message of text type. -setDealCustom("DOJ","11/30/2015",$result);// Setting custom message of date type. - -if (sizeof($result->notes) > 0) { // This code checking deal has any notes or not, don't remove this if-condition. - $result->notes=$result->note_ids; -} - -$opportunity_json = json_encode($result); -echo "
  • update deal with below data

  • "; -echo "
  • " . $opportunity_json . "

  • "; -$result = curl_wrap("opportunity", $opportunity_json, "PUT"); -echo "
  • updated deal data is ...

  • "; -echo "
  • " . $result . "
  • "; -echo "


    "; - -/*================================================= update deal end================================================*/ -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; - } -} -} -?> From a398d67d2dbaddb938c7c4ee36b7db011e0f327a Mon Sep 17 00:00:00 2001 From: ghanraut Date: Thu, 19 Nov 2015 18:21:10 +0530 Subject: [PATCH 08/15] added fourth parameter added fourth parameter --- README.md | 95 ++++++++++++++++++------------------------------------- 1 file changed, 31 insertions(+), 64 deletions(-) diff --git a/README.md b/README.md index 883d204..5d0fc1b 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ $data = json_encode($data); 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 = 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); @@ -132,7 +132,7 @@ $contact_json = array( ); $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 @@ -140,18 +140,18 @@ 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 @@ -185,7 +185,7 @@ $contact_json = array( ); $contact_json = json_encode($contact_json); -curl_wrap("contacts", $contact_json, "PUT"); +curl_wrap("contacts", $contact_json, "PUT", "application/json"); ``` #### 1.5 Update properties of a contact (Partial update) @@ -221,7 +221,7 @@ $contact_json = array( ); $contact_json = json_encode($contact_json); -curl_wrap("contacts/edit-properties", $contact_json, "PUT"); +curl_wrap("contacts/edit-properties", $contact_json, "PUT", "application/json"); ``` #### 1.6 Edit star value @@ -234,7 +234,7 @@ $contact_json = array( ); $contact_json = json_encode($contact_json); -curl_wrap("contacts/add-star", $contact_json, "PUT"); +curl_wrap("contacts/add-star", $contact_json, "PUT", "application/json"); ``` #### 1.7 Add Score to a Contact using Email-ID @@ -307,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 @@ -342,7 +342,7 @@ $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) @@ -371,25 +371,25 @@ $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 ```javascript //Get deal by deal id to update. -$deal = curl_wrap("opportunity/5712508065153024", null, "GET"); +$deal = curl_wrap("opportunity/5712508065153024", null, "GET", "application/json"); $result = json_decode($deal, false, 512, JSON_BIGINT_AS_STRING); @@ -409,7 +409,7 @@ if (sizeof($result->notes) > 0) { // This code checks deal has any notes or not, } $opportunity_json = json_encode($result); -curl_wrap("opportunity", $opportunity_json, "PUT"); +curl_wrap("opportunity", $opportunity_json, "PUT", "application/json"); function setDealCustom($name, $value,$result){ $custom_datas = $result->custom_data; @@ -445,13 +445,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 @@ -466,7 +466,7 @@ $note_json = array( ); $note_json = json_encode($note_json); -curl_wrap("notes", $note_json, "PUT"); +curl_wrap("notes", $note_json, "PUT", "application/json"); ``` @@ -486,19 +486,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 @@ -516,7 +516,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 @@ -532,13 +532,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 @@ -554,7 +554,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 @@ -568,13 +568,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 @@ -587,46 +587,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"); ``` ---- From bda7042f95b184103b0cf21b762dcf367b8dd6e2 Mon Sep 17 00:00:00 2001 From: ghanraut Date: Thu, 19 Nov 2015 18:38:00 +0530 Subject: [PATCH 09/15] Updated domain,api key Updated domain,api key and email with sample data --- curlwrap_v2.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/curlwrap_v2.php b/curlwrap_v2.php index f0e3e94..172ebbc 100644 --- a/curlwrap_v2.php +++ b/curlwrap_v2.php @@ -1,8 +1,8 @@ Date: Thu, 19 Nov 2015 20:16:11 +0530 Subject: [PATCH 10/15] New format for docs This is basic test --- curlwrap_v2.php => CurlLib/curlwrap_v2.php | 31 ++- PHP_API_v2.0.0.php | 310 --------------------- Tester/contact_sample_test.php | 202 ++++++++++++++ Tester/deal_sample_test.php | 38 +++ Tester/note_sample_test.php | 25 ++ Tester/task_sample_test.php | 25 ++ contact_sample_test.php | 8 - deal_sample_test.php | 8 - index.php | 11 +- note_sample_test.php | 8 - task_sample_test.php | 8 - 11 files changed, 315 insertions(+), 359 deletions(-) rename curlwrap_v2.php => CurlLib/curlwrap_v2.php (77%) delete mode 100644 PHP_API_v2.0.0.php create mode 100644 Tester/contact_sample_test.php create mode 100644 Tester/deal_sample_test.php create mode 100644 Tester/note_sample_test.php create mode 100644 Tester/task_sample_test.php delete mode 100644 contact_sample_test.php delete mode 100644 deal_sample_test.php delete mode 100644 note_sample_test.php delete mode 100644 task_sample_test.php diff --git a/curlwrap_v2.php b/CurlLib/curlwrap_v2.php similarity index 77% rename from curlwrap_v2.php rename to CurlLib/curlwrap_v2.php index f0e3e94..20dc3ab 100644 --- a/curlwrap_v2.php +++ b/CurlLib/curlwrap_v2.php @@ -1,18 +1,28 @@ + */ + + # Enter your domain name , agile email and agile api key define("AGILE_DOMAIN", "ghanshyam"); # Example : define("domain","jim"); -define("AGILE_USER_EMAIL", "ghanshyam.raut@agilecrm.com"); +define("AGILE_USER_EMAIL", "ghanshyam.raut@agilecrm.com"); define("AGILE_REST_API_KEY", "123456"); // Example : http://snag.gy/AEq23.jpg -function curl_wrap($entity, $data, $method, $content_type) -{ - if($content_type==NULL){ + +function curl_wrap($entity, $data, $method, $content_type) { + if ($content_type == NULL) { $content_type = "application/json"; } - echo 'Your content type'.$content_type; + echo 'Your content type' . $content_type; echo '

'; - - $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; + + $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); @@ -44,7 +54,7 @@ function curl_wrap($entity, $data, $method, $content_type) break; } curl_setopt($ch, CURLOPT_HTTPHEADER, array( - "Content-type : $content_type;",'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); @@ -54,6 +64,3 @@ function curl_wrap($entity, $data, $method, $content_type) 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 "
    "; - -/*================================================To create a contact ================================================*/ -$address = array( - "address"=>"Avenida Álvares Cabral 1777", - "city"=>"Belo Horizonte", - "state"=>"Minas Gerais", - "country"=>"Brazil" -); - -$contact_email = "ronaldo123@gmail.com"; - - - -$new_contact_json = array( - "lead_score"=>"24", - "star_value"=>"4", - "tags"=>array("test1","test2"), - "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"=>"the phenomenon", - "type"=>"SYSTEM" - ), - array( - "name"=>"image", - "value"=>"http://www.soccerticketsonline.com/wp-content/uploads/ronaldo9.jpg", //This image value is url of image. - "type"=>"SYSTEM" // As of now we are not supporting image from local system path - ), - array( - "name"=>"company", - "value"=>"ibm", - "type"=>"SYSTEM" - ), - array( - "name"=>"address", - "value"=>json_encode($address), - "type"=>"SYSTEM" - ), - array( - "name"=>"phone", - "value"=>"+1-541-754-3030", - "type"=>"SYSTEM" - ), - array( - "name"=>"website", - "value"=>"http://www.google.com", - "type"=>"SYSTEM" - ), - array( - "name"=>"experience in field", //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" - ) - - ) -); -$new_contact_json = json_encode($new_contact_json); - - -echo "
  • contact created with following data

  • "; -echo "
  • " . $new_contact_json . "

  • "; -$result = curl_wrap("contacts", $new_contact_json, "POST"); -echo "
  • created contact data is ...

  • "; -echo "
  • " . $result . "
  • "; -echo "


    "; - -/*================================================= create contact end ================================================*/ - -/*================================================= update contact ================================================*/ - -$contact = curl_wrap("contacts/search/email/ronaldo123@gmail.com", null, "GET"); -//Get contact by email and update it. -$result = json_decode($contact, false, 512, JSON_BIGINT_AS_STRING); - -$result->lead_score = "150"; -$address = array( - "address"=>"MIG-107", - "city"=>"Belo Horizonto", - "state"=>"Minas Gerais", - "country"=>"Brazil" -); -$address1=json_encode($address); -setContactField("address",$address1,$result); // Set contact address with new data -setContactField("last_name","de lama2",$result); -setContactField("DOP","1444718961",$result); // Set DOP custom data of date type. -setContactField("text sample test","hello text sample test",$result); // Set text sample test custom data of textfiled type - - -$new_contact_json1 = json_encode($result); -echo "
  • contact updated with following data

  • "; -echo "
  • " . $new_contact_json1 . "

  • "; -$result = curl_wrap("contacts", $new_contact_json1, "PUT"); -echo "
  • updated contact data is ...

  • "; -echo "
  • " . $result . "
  • "; -echo "


    "; - -/*===========================================update contact end================================================*/ - - -/* ------------------------------------get contact by email and get contact id also ---------------------------- */ - -echo "
  • get contact with email id, and find also get conatct id of this contact

  • "; -echo "
    "; -$result = curl_wrap("contacts/search/email/ronaldo123@gmail.com", null, "GET"); -echo "
  • contact data received is ...

  • "; -echo "
  • " . $result . "

  • "; - -echo "
  • contact id of contact received is ...

  • "; - -$result = json_decode($result, true); -$contact_id = $result['id']; -$contact_id1 = number_format($contact_id,0,'',''); -echo "
  • " . $contact_id1 . "
  • "; -echo "


    "; -/* ------------------------------------get contact by email END----------------------------------------- */ - -/* ------------------------------------get contact by contact_id ----------------------------------------- */ -echo "
  • get contact by conatct id

  • "; -echo "
    "; -$result = curl_wrap("contacts/5706163895140352", null, "GET"); // More info :https://github.com/agilecrm/php-api#by-id -echo "
  • contact data received is ...

  • "; -echo "
  • " . $result . "
  • "; - -echo "


    "; -/* ------------------------------------get contact by contact_id END----------------------------------------- */ - -/* ------------------------------------delete contact by contact_id ----------------------------------------- */ -echo "
  • get contact with email id and find also conatct id

  • "; -echo "
    "; -$result = curl_wrap("contacts/5632908932939776", null, "DELETE"); -echo "
  • deleted response received is ...

  • "; -echo "
  • " . $result . "
  • "; - -echo "


    "; -/* ------------------------------------delete contact by contact_id END----------------------------------------- */ - - -/*=================================================== create deal=======================================*/ - - $opportunity_json = array( - "name"=>"test deal1", - "description"=>"this is a test deal", - "expected_value"=>1000, - "milestone"=>"New", - "custom_data"=>array( //This is custom field which you should first define in custom field region. - //Example :http://snag.gy/OOuj8.jpg - array( - "name"=>"dataone", - "value"=>"xyz" - ), - array( - "name"=>"datatwo", - "value"=>"abc" - ) - ), - "probability"=>50, - "close_date"=>1438948949, - "contact_ids"=>array("5706163895140352") // Contact ID to which deal going to added -); -$opportunity_json = json_encode($opportunity_json); -echo "
  • create deal with below data

  • "; -echo "
  • " . $opportunity_json . "

  • "; -$result = curl_wrap("opportunity", $opportunity_json, "POST"); -echo "
  • created deal data is ...

  • "; -echo "
  • " . $result . "
  • "; -echo "


    "; - -/*===================================================== create deal end================================================*/ - -/*===================================================== update deal================================================*/ - -$deal = curl_wrap("opportunity/5649648836411392", null, "GET");//Get deal by deal id to update. -$result = json_decode($deal, false, 512, JSON_BIGINT_AS_STRING); - -$result->name="helo test"; -$result->expected_value="1000"; // Should not be null; -$result->milestone="Proposal"; // Milestone name should be exactly as in agilecrm website. http://snag.gy/xjAbc.jpg -$result->pipeline_id="5767790501822464"; - -// If you are updating milestone then pipeline_id is mandatory field. pipeline_id is the id of track, -// Otherwise comment milestone and pipeline_id to just change other field. - -setDealCustom("Message","this is text custom data",$result); // Setting custom message of text type. -setDealCustom("DOJ","11/30/2015",$result);// Setting custom message of date type. - -if (sizeof($result->notes) > 0) { // This code checking deal has any notes or not, don't remove this if-condition. - $result->notes=$result->note_ids; -} - -$opportunity_json = json_encode($result); -echo "
  • update deal with below data

  • "; -echo "
  • " . $opportunity_json . "

  • "; -$result = curl_wrap("opportunity", $opportunity_json, "PUT"); -echo "
  • updated deal data is ...

  • "; -echo "
  • " . $result . "
  • "; -echo "


    "; - -/*================================================= update deal end================================================*/ -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/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/contact_sample_test.php b/contact_sample_test.php deleted file mode 100644 index 3ac00fa..0000000 --- a/contact_sample_test.php +++ /dev/null @@ -1,8 +0,0 @@ - @@ -11,12 +12,12 @@ Reference taken from : https://github.com/agilecrm/php-api"; echo '
'; - $contact = curl_wrap("contacts/search/email/haka@gmail.com", null, "GET",NULL); + $contact = curl_wrap("contacts/search/email/haka@gmail.com", null, "GET", NULL); echo $contact; ?> diff --git a/note_sample_test.php b/note_sample_test.php deleted file mode 100644 index 3ac00fa..0000000 --- a/note_sample_test.php +++ /dev/null @@ -1,8 +0,0 @@ - Date: Mon, 23 Nov 2015 14:34:34 +0530 Subject: [PATCH 11/15] Deal Modification Deal issue fix by adding partial update method --- README.md | 90 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 54 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 5d0fc1b..37483a7 100644 --- a/README.md +++ b/README.md @@ -347,6 +347,8 @@ 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 @@ -387,49 +389,65 @@ curl_wrap("opportunity/5739083074633728", null, "DELETE", "application/json"); #### 3.4 To update deal -```javascript -//Get deal by deal id to update. -$deal = curl_wrap("opportunity/5712508065153024", null, "GET", "application/json"); - -$result = json_decode($deal, false, 512, JSON_BIGINT_AS_STRING); - -$result->name="hello test deal"; // Set deal name with new data. -$result->expected_value="1000"; // Set deal expected_value with new data. Value should not be null. -$result->milestone="New"; // Milestone name should be exactly as in agilecrm website. http://snag.gy/xjAbc.jpg -$result->pipeline_id="5767790501822464"; - -// If you are updating milestone then pipeline_id is mandatory field. pipeline_id is the id of track, -// Otherwise comment milestone and pipeline_id to just change other field. - -setDealCustom("dealTester","this is text custom data",$result); // Set Custom filed dealTester with new data.This is example of text field type. -setDealCustom("dealAddedDate","11/25/2015",$result); // Set Custom filed dealAddedDate with new data.This is example of date filed type. +- **Note** Please send all data related to deal. -if (sizeof($result->notes) > 0) { // This code checks deal has any notes or not, don't remove this if condition. - $result->notes=$result->note_ids; -} +```javascript +$opportunity_json = array( + "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" + ) + ), + "probability" => 50, + "close_date" => 1414317504, + "contact_ids" => array("5641841626054656", "5756422495141888") +); -$opportunity_json = json_encode($result); +$opportunity_json = json_encode($opportunity_json); curl_wrap("opportunity", $opportunity_json, "PUT", "application/json"); +``` -function setDealCustom($name, $value,$result){ -$custom_datas = $result->custom_data; -foreach ($custom_datas as $custom_data1) { - - if (strcasecmp($name, $custom_data1->name) == 0) { - $custom_data1->value=$value; - return; - } -} +#### 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") +); -$contactField = (object) array( - "name" => $name, - "value" => $value - ); +$opportunity_json = json_encode($opportunity_json); +curl_wrap("opportunity/partial-update", $opportunity_json, "PUT", "application/json"); +``` - $custom_datas[]=$contactField; - $result->custom_data=$custom_datas; +#### 3.6 Get deals related to specific contact by contact id -} +```javascript +curl_wrap("contacts/5739083074633728/deals", null, "GET", "application/json"); ``` # 4. Note From 4ebe91dc214d6559a49c1e55558a92026f16ad38 Mon Sep 17 00:00:00 2001 From: ghanraut Date: Mon, 23 Nov 2015 15:41:56 +0530 Subject: [PATCH 12/15] Remove credential from curl wrap Remove credential from curl wrap --- CurlLib/curlwrap_v2.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CurlLib/curlwrap_v2.php b/CurlLib/curlwrap_v2.php index 20dc3ab..801cb0b 100644 --- a/CurlLib/curlwrap_v2.php +++ b/CurlLib/curlwrap_v2.php @@ -10,11 +10,13 @@ # Enter your domain name , agile email and agile api key -define("AGILE_DOMAIN", "ghanshyam"); # Example : define("domain","jim"); -define("AGILE_USER_EMAIL", "ghanshyam.raut@agilecrm.com"); -define("AGILE_REST_API_KEY", "123456"); // Example : http://snag.gy/AEq23.jpg + +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, $content_type) { + if ($content_type == NULL) { $content_type = "application/json"; } From 87c777245b1d09d558687a57848042396fbb619e Mon Sep 17 00:00:00 2001 From: ghanraut Date: Mon, 23 Nov 2015 15:43:20 +0530 Subject: [PATCH 13/15] Remove print file Removed some echo commands. --- CurlLib/curlwrap_v2.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CurlLib/curlwrap_v2.php b/CurlLib/curlwrap_v2.php index 801cb0b..2e68b84 100644 --- a/CurlLib/curlwrap_v2.php +++ b/CurlLib/curlwrap_v2.php @@ -20,9 +20,7 @@ function curl_wrap($entity, $data, $method, $content_type) { if ($content_type == NULL) { $content_type = "application/json"; } - echo 'Your content type' . $content_type; - echo '

'; - + $agile_url = "https://" . AGILE_DOMAIN . ".agilecrm.com/dev/api/" . $entity; $ch = curl_init(); From 28c7493f589176191219ef0e37063e8e205a4a6e Mon Sep 17 00:00:00 2001 From: ghanraut Date: Mon, 23 Nov 2015 15:45:57 +0530 Subject: [PATCH 14/15] Placed correct URL for curl wrap Placed correct URL for curl wrap in git hub --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 37483a7..2b52a46 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,9 @@ PHP Client to access Agile functionality #Intro -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/curlwrap_v2.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 [**curlwrap_v2.php**](https://github.com/ghanraut/php-api/blob/master/curlwrap_v2.php) in your php code. +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 4 paramaters to the curl_wrap function. They are **$entity**, **$data**, **$method**, **$content-type**. @@ -47,7 +47,7 @@ $data = json_encode($data); GET to fetch an entity. - PUT to update entity. + PUT to update an entity. DELETE to remove an entity. From bed08665ea32f8ba748e85cff3aa754784eafea1 Mon Sep 17 00:00:00 2001 From: ghanraut Date: Tue, 24 Nov 2015 19:36:26 +0530 Subject: [PATCH 15/15] Update id with string Update contact modification --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2b52a46..d2bb023 100644 --- a/README.md +++ b/README.md @@ -161,7 +161,7 @@ curl_wrap("contacts/5722721933590528", null, "DELETE", "application/json"); ```javascript $contact_json = array( - "id"=>5722721933590528,//It is mandatory filed. Id of contact + "id"=>"5722721933590528",//It is mandatory filed. Id of contact "lead_score"=>"80", "star_value"=>"5", "tags"=>array("Player","Winner"),