forked from agilecrm/php-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcurlwrap_v1.php
More file actions
46 lines (45 loc) · 1.42 KB
/
curlwrap_v1.php
File metadata and controls
46 lines (45 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
define("apikey", "your_agile_api_key");
define("domain", "your_agile_subdomain");
function curl_wrap ($subject, $json, $action)
{
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_FOLLOWLOCATION=>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;
}
?>