-
Notifications
You must be signed in to change notification settings - Fork 3
/
zendesk.php
60 lines (54 loc) · 1.57 KB
/
zendesk.php
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
56
57
58
59
60
<?php
define("ZDAPIKEY", "API_KEY");
define("ZDUSER", "email@yourdomain.com");
define("ZDURL", "https://yourdomain.zendesk.com/api/v2");
function curlWrap($url, $json)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt($ch, CURLOPT_MAXREDIRS, 10 );
curl_setopt($ch, CURLOPT_URL, ZDURL.$url);
curl_setopt($ch, CURLOPT_USERPWD, ZDUSER."/token:".ZDAPIKEY);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$output = curl_exec($ch);
curl_close($ch);
$decoded = json_decode($output);
return $decoded;
}
if(isset($_POST))
{
foreach($_POST as $key => $value)
{
if(preg_match('/^z_/i',$key))
{
$arr[strip_tags($key)] = strip_tags($value);
}
}
//Don't Remove the following two Line Breaks, it adds line breaks to the textarea.
$arr['z_description'] .= '
Submitted From: ' . $_POST['z_page'];
//Finish Don't Remove
$create = json_encode(
array(
'ticket' => array(
'subject' => substr($arr['z_description'], 0, 50),
'comment' => array(
"body" => $arr['z_description']
),
'requester' => array(
'name' => $arr['z_name'],
'email' => $arr['z_requester']
),
'tags' => json_encode(array($arr['z_tag']))
),
),
JSON_FORCE_OBJECT);
$return = curlWrap("/tickets.json", $create);
}
?>