forked from agilecrm/php-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcurlwrap_v2.php
More file actions
55 lines (50 loc) · 2.04 KB
/
curlwrap_v2.php
File metadata and controls
55 lines (50 loc) · 2.04 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
47
48
49
50
51
52
53
54
55
<?php
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;
$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);
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);
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; charset : UTF-8;',
'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);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
?>