-
Notifications
You must be signed in to change notification settings - Fork 181
/
create_ticket_with_attachment.php
49 lines (41 loc) · 1.31 KB
/
create_ticket_with_attachment.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
<?php
$api_key = "API_KEY";
$password = "x";
$yourdomain = "YOUR_DOMAIN";
$ticket_payload = array(
'email' => 'test@example.com',
'subject' => 'test',
'description' => 'testing description content',
'priority' => 2,
'status' => 2,
'attachments[]' => curl_file_create("data/x.png", "image/png", "x.png")
);
$url = "https://$yourdomain.freshdesk.com/api/v2/tickets";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_USERPWD, "$api_key:$password");
curl_setopt($ch, CURLOPT_POSTFIELDS, $ticket_payload);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
$info = curl_getinfo($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$headers = substr($server_output, 0, $header_size);
$response = substr($server_output, $header_size);
if($info['http_code'] == 201) {
echo "Ticket created successfully, the response is given below \n";
echo "Response Headers are \n";
echo $headers."\n";
echo "Response Body \n";
echo "$response \n";
} else {
if($info['http_code'] == 404) {
echo "Error, Please check the end point \n";
} else {
echo "Error, HTTP Status Code : " . $info['http_code'] . "\n";
echo "Headers are ".$headers;
echo "Response are ".$response;
}
}
curl_close($ch);
?>