forked from phikai/freshdesk-rest
-
Notifications
You must be signed in to change notification settings - Fork 7
/
example.php
82 lines (75 loc) · 2.01 KB
/
example.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/**
* File: example.php
* Project: freshdesk-solutions
*/
require 'vendor/autoload.php';
//use the classes
use Freshdesk\Config\Connection,
Freshdesk\Rest,
Freshdesk\Ticket,
Freshdesk\Model\Contact,
Freshdesk\Model\Ticket as TicketM,
Freshdesk\Tool\ModelGenerator;
$url = 'http://API-key:[email protected]';
$conf = new Connection($url);
$t = new Ticket(
$conf
);
$m = new Contact(
array(
'email' => '[email protected]'
)
);
//get an assoc array of tickets
//keys are statusName values
$tickets = $t->getGroupedTickets($m);
//same as before, status values (1,2,3...) are the keys now
$tickets = $t->getGroupedTickets('[email protected]', false);
//choose a ticket
$model = new TicketM(
array(
'display_id' => 12345
)
);
$t = new Ticket($conf);
//get all data associated with this id
$model = $t->getFullTicket($model);
//close a ticket
$ticket = $t->updateTicket(
$model->setStatus(4)
);
//fire up the generator
$gen = new ModelGenerator($conf);
//generate class, extending from the TicketM class
//will create properties, setters and getters for all
//properties not present in base class
echo $gen->generateTicketClass(
$model,
'YourTicket',
'/home/user/abs/path/to/YourTicket.php'
);
//basic/general rest calls
$fd = new Rest($conf);
//get ticket, this call will be removed from Rest class & moved to Ticket class
$json = $fd->getSingleTicket(1701);
print_r($json);
//for ticket-calls:
$t = new Ticket($conf);
//create new ticket
$model = new TicketM(
array(
'description' => 'Ignore this ticket, it is a test',
'subject' => 'API-test',
'email' => '[email protected]'
)
);
//create new ticket, basic example
$t->createNewTicket($model);
//Assign a ticket to an agent/responder:
$responderId = 123456;
$t->assignTicket($model, $responderId);
//delete a ticket:
$t->deleteTicket($model);//pass true as second argument to force a reload of the ticket
//restore a ticket that was deleted via the api:
$t->restoreTicket($model);