Skip to content

Instantly share code, notes, and snippets.

@graut
Created September 15, 2016 06:42
Show Gist options
  • Save graut/20eaeb81a609912d80518cfc3a5e55de to your computer and use it in GitHub Desktop.
Save graut/20eaeb81a609912d80518cfc3a5e55de to your computer and use it in GitHub Desktop.
<?php
/**
* Agile CRM \ Curl Wrap
*
* The Curl Wrap is the entry point to all services and actions.
*
* @author Agile CRM developers <Ghanshyam>
*/
# Enter your domain name , agile email and agile api key
define("AGILE_DOMAIN", "your_domain"); # Example : define("domain","jim");
define("AGILE_USER_EMAIL", "your_email");
define("AGILE_REST_API_KEY", "your_password");
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 = $agile_url;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
break;
case "GET":
$url = $agile_url;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
break;
case "PUT":
$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 = $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 : $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;
}
$opportunity_json_input = array(
"subject" => "note subject test",
"description" => "note subject description.\r\nThanks",
"deal_ids" => array("5658450247811072")
);
$opportunity_json = json_encode($opportunity_json_input);
echo curl_wrap("opportunity/deals/notes", $opportunity_json, "POST", "application/json");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment