This repository has been archived by the owner on Dec 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-zendesk-api.php
1736 lines (1456 loc) · 47.4 KB
/
wp-zendesk-api.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* WP Zendesk API class, for interacting with the Zendesk API.
*
* @package WPApiLibraries
*/
/* If access directly, exit. */
if ( ! defined( 'ABSPATH' ) ) {
exit; }
/* Confirm that not being included elsewhere. */
if ( ! class_exists( 'WpZendeskAPI' ) ) {
/**
* WP Zendesk API class.
*
* Extended off the WP API Libraries Base class.
*
* @link https://github.com/wp-api-libraries/wp-api-base
*/
class WpZendeskAPI extends ZendeskAPIBase {
/**
* The username through which to make all calls.
*
* @var string
*/
private $username;
/**
* The alternate username (should not be accessed frequently). Used for calls
* where you want to act as a different user.
*
* @var string
*/
private $backup_username = '';
/**
* Internal variable, whether to immediately reset authentication to original username
* (used with temporarily setting authentication).
*
* @var bool
*/
private $fast_rest = true;
/**
* Internal variable, whether to create a call without any authorization (for anonymous calls).
*
* @var bool
*/
private $no_auth = false;
/**
* The API key used for authentication.
*
* @var string
*/
private $api_key;
/**
* The extended URI to which requests are made.
*
* @var string
*/
protected $base_uri = '';
/**
* Arguments to be built upon.
*
* Contains header and body information.
*
* @var string
*/
protected $args;
/**
* Whether to wrap errors in a wp_error object, or to return the full object.
*
* @var bool
*/
protected $is_debug;
/**
* Constructorinatorino 9000
*
* @param string $domain The domain extension of zendesk (basically org name).
* @param string $username The username through which requests will be made
* under.
* @param string $api_key The API key used for authentication.
* @param bool $debug (Default: false) Whether to return calls even if error,
* or to wrap them in a wp_error object.
*/
public function __construct( $domain, $username, $api_key, $debug = false ) {
$this->base_uri = "https://$domain.zendesk.com/api/v2/";
$this->username = $username;
$this->api_key = $api_key;
$this->is_debug = $debug;
}
/**
* Get the current username.
*
* @return string The username.
*/
public function get_username() {
return $this->username;
}
/**
* Get the current API key.
*
* @return string The API key.
*/
public function get_api_key() {
return $this->api_key;
}
/**
* Set authentication.
*
* Used for changing the authentication methods.
* Note: the domain cannot be changed.
*
* @param string $username The new username.
* @param string $api_key The new API key.
*/
public function set_auth( $username, $api_key ) {
$this->username = $username;
$this->api_key = $api_key;
}
/**
* Set username for a single call.
*
* Useful for, as an example, fetching requests that an end user is authorized
* to view, by setting the username for the next call to be their email.
*
* After fetch() is run, the username is reset to the original (or most recently
* updated) username.
*
* @param string $username The temporary single call username.
* @param bool $fast_reset (Default: true) whether ot reset the username after
* the next fetch() call.
*/
public function set_temporary_username( $username, $fast_reset = true ) {
$this->backup_username = $this->username;
$this->username = $username;
$this->fast_reset = $fast_reset;
}
/**
* Temporarily make the next call not have any authentication headers.
*
* @param boolean $fast_reset (Default: true) Whether to reset after the next
* immediate fetch() call.
* @return WpZendeskAPI Self.
*/
public function set_temporary_noauth( $fast_reset = true ) {
$this->no_auth = true;
$this->fast_reset = $fast_reset;
return $this;
}
/**
* Resets the username to its original status.
*
* Designed to be used with set_temporary_username('<username>', false).
*
* @return WpZendeskAPI Self.
*/
public function reset_username() {
if ( '' !== $this->backup_username ) {
$this->username = $this->backup_username;
$this->backup_username = '';
}
return $this;
}
/**
* Perform the request, normally after build_request.
*
* @return mixed The body of the call.
*/
protected function fetch() {
$result = parent::fetch();
if ( '' !== $this->backup_username && $this->fast_reset ) {
$this->username = $this->backup_username;
$this->backup_username = '';
$this->no_auth = false;
}
return $result;
}
/**
* Abstract extended function that is used to set authorization before each
* call. $this->args['headers'] are wiped after every fetch call, hence this
* function is necessary.
*
* @return void
*/
protected function set_headers() {
$this->args['headers'] = array(
'Content-Type' => 'application/json',
);
if ( ! $this->no_auth ) {
// @codingStandardsIgnoreStart
$this->args['headers']['Authorization'] = 'Basic ' . base64_encode( $this->username . '/token:' . $this->api_key );
// @codingStandardsIgnoreEnd
}
}
/**
* Handle the build request and fetch methods, along with (optionally, but by
* default) adding the data type extension to the route.
*
* @param string $route The route to access.
* @param array $args (Default: array()) Optional arguments. If the request
* method is 'GET', then the arguments are appended to
* the route as query args. Otherwise, they are stored
* in the body of the request.
* @param string $method (Default: 'GET') The type of request to make.
* @param bool $add_data_type (Default: true) Whether to add the data type
* extension to the route or not.
* @return [type] [description]
*/
protected function run( $route, $args = array(), $method = 'GET', $add_data_type = true ) {
// K, screw caching.
return $this->build_request( $route . ( $add_data_type ? '.json' : '' ), $args, $method )->fetch();
}
/**
* Deletes all stored transients.
*
* More a helper function, should not be often routinely called.
*
* @return integer The number rows affected.
*/
public function clear_cache() {
global $wpdb;
$count = $wpdb->query(
$wpdb->prepare(
"DELETE FROM $wpdb->options
WHERE `option_name` LIKE '%s'",
'%hostops_zendeskapi_%'
)
);
// Divided by 2 because there's a row for both the value itself and its expiration.
return $count / 2;
}
/**
* Clear arguments.
*
* Extended just in case you don't want to wipe everything.
*
* Recommended at least clearing body.
*
* @return void
*/
protected function clear() {
$this->args = array();
}
private function parse_args( $args, $merge = array() ) {
$results = array();
foreach ( $args as $key => $val ) {
if ( $val !== null ) {
$results[ $key ] = $val;
} elseif ( is_array( $val ) && ! empty( $val ) ) {
$results[ $key ] = $val;
}
}
return array_merge( $merge, $results );
}
/**
* Function for building zendesk pagination.
*
* @param integer $per_page (Default: 100) Number of results to show per page.
* @param integer $page (Defualt: 1) Page to start on.
* @param string $sort_by (Default: '') What to sort by.
* @param string $sort_order (Default: 'desc') What order to display results in.
* @return array An array of arguments compliant with zendesk pagination.
*/
public function build_zendesk_pagination( $per_page = 100, $page = 1, $sort_by = '', $sort_order = 'desc' ) {
$args = array(
'per_page' => $per_page,
'page' => $page,
);
if ( '' !== $sort_by ) {
$args['sort_by'] = $sort_by;
$args['sort_order'] = $sort_order;
}
return $args;
}
/**
* Function for setting pagination prior to a call (should be a GET only!).
*
* Example usage:
*
* $hapi = new WpZendeskAPI( ... );
* $results = $hapi->set_pagination( 30, 2, array( 'sort_by' => 'updated_at') )->get_tasks();
*
* // Alternatively
* $hapi->set_pagination( 30, 2 );
* $results = $hapi->get_tasks();
*
* If 'sort_by' is set and 'sort_order' is not set, it will be automatically set to desc.
*
* p() is a wrapper function for set_pagination.
*
* TODO: move updated_since to here (since it appears in all other cases as well).
*
* @param integer $page (Default: 1) Page offset to get results from
* (multiplied by $per_page is the final page).
* @param integer $per_page (Default: 100) Number of results to display per page.
* @param string $args (Default: null) Only retrieve results that have
* been updated after this date.
* @return WpZendeskAPI $this.
*/
public function set_pagination( $per_page = 100, $page = 1, $args = array() ) {
$this->args['body'] = $this->parse_args(
array(
'per_page' => $per_page,
'page' => $page,
), $args
);
if ( isset( $this->args['body']['sort_by'] ) && ! isset( $this->args['body']['sort_order'] ) ) {
$this->args['body']['sort_order'] = 'desc';
}
return $this;
}
/**
* Wrapper function for set_pagination().
*
* @param integer $page (Default: 1) Page offset to get results from (multiplied
* by $per_page is the final page).
* @param integer $per_page (Default: 100) Number of results to display per page.
* @return HarvestAPI $this. [description]
*/
public function p( $per_page = 100, $page = 1, $args = array() ) {
return $this->set_pagination( $per_page, $page, $args );
}
/**
* Query the Zendesk search route.
*
* Can be paginated.
*
* @link https://developer.zendesk.com/rest_api/docs/core/search
*
* @param string $search_string The search query.
* @param integer $per_page (Default: 100) The number of results to return
* per page. Maxes out at 100.
* @param integer $page (Default: 1) The page off of results to start at.
* @param string $sort_by (Default: '') What to sort by.
* @param string $sort_order (Default: 'desc') What order to display results in
* either 'desc' or 'asc'.
* @return object A stdClass of the body from the response.
*/
public function search( $search_string ) {
return $this->run( 'search', array( 'query' => $search_string ) );
}
/* Useful search functions */
/**
* Get tickets associated with an email.
*
* @param string $email The email to look for.
* @return object The results of the search (Zendesk search results).
*/
public function get_tickets_by_email( $email ) {
return $this->run(
'search', array(
'query' => rawurlencode( 'type:ticket requester:' . $email ),
)
);
}
/**
* Get user by email.
*
* @param string $email The email to search by.
* @return object The results of the user serach.
*/
public function get_user_by_email( $email ) {
// or is it get user?
return $this->run(
'users/search', array(
'query' => $email,
)
);
}
/**
* Get requests associated with an email.
*
* @param string $email The email to search by.
* @return object Results of the search.
*/
public function get_requests_by_email( $email ) {
return $this->run(
'search', array(
'query' => urlencode( 'type:request requester:' . $email . ' status:all' ),
)
);
}
/**
* Get organizations by organization name.
*
* @param string $organization_name The organization name.
* @return object The search results.
*/
public function get_organizations_by_name( $organization_name ) {
return $this->run(
'search', array(
'query' => urlencode( 'type:organization ' . $organization_name ),
)
);
}
/* Tickets */
/**
* List tickets.
*
* Returns a maximum of 100 tickets per page. See Pagination.
*
* Tickets are ordered chronologically by created date, from oldest to newest.
* The first ticket listed may not be the absolute oldest ticket in your account
* due to ticket archiving. To get a list of all tickets in your account, use the
* Incremental Ticket Export endpoint.
*
* For more filter options, use the Search API.
*
* You can also sideload related records with the tickets. See Side-Loading.
*
* Can be paginated.
*
* @param integer $per_page (Default: 100) Number of results to display per page. Max 100.
* @param integer $page (Default: 1) What offset to start at.
* @param string $sort_by (Default: '') What to sort by.
* @param string $sort_order (Default: 'desc') Order of results to display.
* @return object List of tickets.
*/
public function list_tickets() {
return $this->run( 'tickets' );
}
/**
* Extention of list_tickets, except show tickets by user ID.
*
* Can be paginated.
*
* @param string $user_id The user ID. Can also be int.
* @return object A list of tickets requested by a specific user ID.
*/
public function list_tickets_by_user_id_requested( $user_id ) {
return $this->run( "users/$user_id/tickets/requested" );
}
/**
* Show a ticket.
*
* Returns a number of ticket properties, but not the ticket comments. To
* get the comments, use List Comments.
*
* @param string $ticket_id The ID of a ticket.
* @return object The ticket.
*/
public function show_ticket( $ticket_id ) {
return $this->run( "tickets/$ticket_id" );
}
/**
* Show multiple tickets
*
* Accepts a comma separated list of ticket ids to return.
*
* This endpoint will return up to 100 tickets records.
*
* TODO: rename to list_tickets.
*
* Can be paginated.
*
* @param mixed $ids Either an array of ticket IDs, or a comma separated list.
* @return object The multiple tickets requested.
*/
public function show_multiple_tickets( $ids ) {
if ( is_array( $ids ) ) {
$ids = implode( $ids, ',' );
}
return $this->run(
'tickets/show_many', array(
'ids' => $ids,
)
);
}
/**
* Extension of show_tickets, shows tickets by a request.
*
* @param [type] $user_id [description]
* @return [type] [description]
*/
public function get_requests_by_user( $user_id ) {
return $this->run( "users/$user_id/tickets/requested" );
}
/**
* Extension of show_tickets, shows tickets that are cc'd to a user.
*
* Can be paginated.
*
* @param [type] $user_id [description]
* @return [type] [description]
*/
public function get_ccd_by_user( $user_id, $pages = null ) {
return $this->run( "users/$user_id/tickets/ccd" );
}
/**
* Extension of show_tickets, shows tickets assigned to a user.
*
* Can be paginated.
*
* @param [type] $user_id [description]
* @param integer $per_page [description]
* @param integer $page [description]
* @return [type] [description]
*/
public function get_assigned_by_user( $user_id ) {
return $this->run( "users/$user_id/tickets/assigned" );
}
/**
* Build a zendesk ticket object, compliant with the zendesk api ticket format.
*
* @param string $subject (Default: '') The subject of the ticket.
* @param string $description (Default: '') The description of the ticket.
* @param string $comment (Default: '') The comment of the ticket.
* @param string $requester_id (Default: '') The requester for the ticket.
* @param string $tags (Default: '') The tags for the ticket (CSV).
* @param array $other (Default: array()) Other properties (as key => val).
* @param bool $raw (Default: false) Whether to return the array as
* array( 'ticket' => array( / * stuff * / ) ) or
* a raw array of properties.
* @return array A formatted zendesk API ticket object.
*/
public function build_zendesk_ticket( $subject = '', $description = '', $comment = '', $requester_id = '', $tags = '', $other = array(), $raw = false ) {
$ticket = array();
if ( '' !== $subject ) {
$ticket['subject'] = $subject;
}
if ( '' !== $description ) {
$ticket['description'] = $description;
}
if ( '' !== $comment ) {
$ticket['comment'] = $comment;
}
if ( '' !== $requester_id ) {
$ticket['requester_id'] = $requester_id;
}
if ( '' !== $tags ) {
if ( gettype( $tags ) == 'array' ) {
$ticket['tags'] = implode( ',', $tags );
} else {
$tickets['tags'] = $tags;
}
}
if ( ! empty( $other ) ) {
foreach ( $other as $key => $val ) {
$ticket[ $key ] = $val;
}
}
if ( $raw ) {
return $ticket;
}
return array(
'ticket' => $ticket,
);
}
/**
* Create a ticket.
*
* @param mixed $ticket If is an array, will ignore all other args and pass
* $ticket as the ticket object. If is a string, will
* assume it's the subject of the ticket.
* @param string $description (Default: '') The description.
* @param string $requester_id (Default: '') The requester ID.
* @param string $tags (Default: '') The tags for the ticket.
* @param array $other (Default: '') Other properties (key => value).
* @return object The created zendesk ticket.
*/
public function create_ticket( $ticket, $description = '', $requester_id = '', $tags = '', $other = array() ) {
if ( gettype( $ticket ) !== 'object' && gettype( $ticket ) !== 'array' ) {
$ticket = $this->build_zendesk_ticket( $ticket, $description, '', $requester_id, $tags, $other );
}
return $this->run( 'tickets', $ticket, 'POST' );
}
/**
* Create multiple tickets.
*
* Accepts an array of ticket objects (see build_zendesk_ticket).
*
* @param array $ticket_objs An array of ticket objects.
* @return object The created tickets.
*/
public function create_many_tickets( $ticket_objs ) {
return $this->run(
'tickets/create_many', array(
'tickets' => $ticket_objs,
), 'POST'
);
}
/**
* Update a ticket.
*
* @param string $ticket_id The ID of the ticket.
* @param array $ticket_obj The ticket object. Only properties present in this
* object will be updated, all else will be ignored.
* @return object The updated ticket.
*/
public function update_ticket( $ticket_id, $ticket_obj ) {
return $this->run( 'tickets/' . $ticket_id, $ticket_obj, 'PUT' );
}
/**
* @link https://developer.zendesk.com/rest_api/docs/core/tickets#update-many-tickets
*
* @param array $ticket_objs Accepts an array of up to 100 ticket objects.
* If ticket is set, then will require ids to be set.
* Otherwise, tickets should be set, and ids is not necessary
* to be set.
* @param array $ids A comma-separated list of up to 100 ticket ids.
* Use this for modifying many tickets with the same
* change.
* @return [type] [description]
*/
public function update_many_tickets( $ticket_obj, $ids = array() ) {
if ( empty( $ids ) ) {
return $this->run( 'tickets/update_many', $ticket_obj, 'PUT' );
} else {
return $this->run( 'tickets/update_many.json?ids=' . implode( ',', $ids ), $ticket_obj, 'PUT', false );
}
}
public function protect_ticket_update_collisions() {
}
/**
* Marks a ticket as spam, and blocks the requester.
*
* @param [type] $ticket_id [description]
* @return [type] [description]
*/
public function mark_ticket_spam_and_block_requester( $ticket_id ) {
return $this->run( "tickets/$ticket_id/mark_as_spam", array(), 'PUT' );
}
public function mark_many_tickets_as_spam( $ids ) {
return $this->run( 'tickets/mark_many_as_spam.json?ids=' . implode( ',', $ids ), array(), 'PUT', false );
}
public function merge_tickets_into_target() {
}
public function get_ticket_related_info( $ticket_id ) {
return $this->run( "tickets/$ticket_id/related" );
}
public function create_ticket_new_requester() {
}
public function set_ticket_fields() {
}
public function delete_ticket( $ticket_id ) {
return $this->run( "tickets/$ticket_id", array(), 'DELETE' );
}
public function bulk_delete_tickets( $ticket_ids = array() ) {
return $this->run( 'tickets/destroy_many.json?ids=' . implode( ',', $ticket_ids ), array(), 'DELETE', false );
}
public function show_delete_tickets() {
return $this->run( 'deleted_tickets' );
}
public function restore_deleted_ticket( $ticket_id ) {
return $this->run( "deleted_tickets/$ticket_id/restore", array(), 'PUT' );
}
public function restore_bulk_deleted_tickets( $ticket_ids = array() ) {
return $this->run( 'deleted_tickets/restore_many?ids=' . implode( ',', $ticket_ids ), array(), 'PUT', false );
}
public function delete_tickets_permanently() {
}
/**
* List collaborators for a ticket.
*
* Can be paginated.
*
* @param string $ticket_id The ID of the ticket (can also be numeric).
* @return array A list of collaborators on a ticket.
*/
public function get_collaborators_ticket( $ticket_id ) {
return $this->run( "tickets/$ticket_id/collaborators" );
}
/**
* List incidents for a ticket.
*
* @param [type] $ticket_id [description]
* @return array A list of incidents from a ticket.
*/
public function list_ticket_incidents( $ticket_id ) {
return $this->run( "tickets/$ticket_id/incidents" );
}
/**
* List ticket problems.
*
* The response is always ordered by updated_at, in desc order.
*
* @return [type] [description]
*/
public function list_ticket_problems() {
return $this->run( 'problems' );
}
/**
* Returns tickets whose type is "Problem" and whose subject contains the string
* specified in the <code>text</code> parameter.
*
* @return array A list of tickets that have been autocompleted.
*/
public function autocomplete_problems( $text ) {
return $this->run(
'autocomplete', array(
'text' => $text,
), 'POST'
);
}
/* Ticket import */
/**
* The endpoint takes a ticket object describing the ticket.
*
* @link https://developer.zendesk.com/rest_api/docs/core/ticket_import#ticket-import
* @param array $ticket A ZendeskAPI ticket object (see $this->build_zendesk_ticket()).
* @return object The successfully created ticket (hopefully).
*/
public function ticket_import( $ticket ) {
return $this->run( 'imports/tickets', $ticket, 'POST' );
}
/**
* The endpoint takes a tickets array of up to 100 ticket objects.
*
* Similar to single tickets, except they're single tickets.
*
* @link https://developer.zendesk.com/rest_api/docs/core/ticket_import#ticket-bulk-import
* @param [type] $tickets [description]
* @return [type] [description]
*/
public function bulk_ticket_import( $tickets ) {
return $this->run( 'imports/tickets/create_many', $tickets, 'POST' );
}
/* Requests */
/**
* List general requests.
*
* Can be paginated
*
* @return [type] [description]
*/
public function list_requests() {
return $this->run( 'requests' );
}
/**
* Can be paginated.
*
* @return [type] [description]
*/
public function list_open_requests() {
return $this->run( 'requests/open', $args );
}
/**
* Can be paginated.
*
* @return [type] [description]
*/
public function list_hold_requests() {
return $this->run( 'requests/hold', $args );
}
/**
* Format for statuses: comma separated list (string) of statuses to browse through.
*
* Can be paginated.
*
* @param [type] $statuses
* @param array $zendesk_pagination Zendesk pagination tool.
* @return [type] [description]
*/
public function list_requests_by_status( $statuses ) {
return $this->run( 'requests', array( 'status' => $statuses ) );
}
/**
* Can be paginated.
*
* @param [type] $user_id [description]
* @return [type] [description]
*/
public function list_requests_by_user( $user_id ) {
return $this->run( "users/$user_id/requests" );
}
/**
* Can be paginated.
*
* @return [type] [description]
*/
public function list_requests_by_organization() {
return $this->run( "organizations/$org_id/requests" );
}
/**
* Search requests.
*
* Can be paginated.
*
* GET /api/v2/requests/search.json?query=camera
* GET /api/v2/requests/search.json?query=camera&organization_id=1
* GET /api/v2/requests/search.json?query=camera&cc_id=true
* GET /api/v2/requests/search.json?query=camera&status=hold,open
*
* @param [type] $query [description]
* @param [type] $zendesk_pagination
* @return [type] [description]
*/
public function search_requests( $query ) {
return $this->run( 'requests/search', array( 'query' => $query ) );
}
/**
* Show a single request.
*
* @link https://developer.zendesk.com/rest_api/docs/core/requests#show-request
* @param [type] $request_id [description]
* @return [type] [description]
*/
public function show_request( $request_id ) {
return $this->run( 'requests/' . $request_id );
}
/**
* Build a request (following the zendesk API structure).
*
* @param string $subject [description]
* @param string $description [description]
* @param string $comment [description]
* @param array $other [description]
* @param bool $raw
* @return [type] [description]
*/
public function build_zendesk_request( $subject = '', $description = '', $comment = '', $other = array(), $raw = false ) {
$request = array();
if ( $subject != '' ) {
$request['subject'] = $subject;
}
if ( $description != '' ) {
$request['description'] = $description;
}
if ( $comment != '' ) {
$request['comment']['body'] = $comment;
}
if ( ! empty( $other ) ) {
foreach ( $other as $key => $val ) {
$request[ $key ] = $val;
}
}
if ( $raw ) {
return $request;
}
return array(
'request' => $request,
);
}
/**
* Call build request, must fill out subject and description, should fill out requester.
*
* If not defined and not admin, then will be set to whoever is authenticated.
*
* @link https://developer.zendesk.com/rest_api/docs/core/requests#create-request
* @param [type] $request [description]
* @return [type] [description]
*/
public function create_request( $request ) {
return $this->run( 'requests', $request, 'POST' );
}
/**
* Call build_request, recommended fill out comment, can fill out status
* This function is mostly used for adding a comment.
*
* @link https://developer.zendesk.com/rest_api/docs/core/requests#update-request
* @param [type] $request_id [description]
* @param [type] $request [description]
* @return [type] [description]
*/
public function update_request( $request_id, $request ) {
return $this->run( 'requests/' . $request_id, $request, 'PUT' );
}
/**
* Lists comments from a request.
*
* I BELIEVE it will not list private comments.
*
* Not totally sure.
*
* Please test.
*
* Can be paginated.
*
* @link https://developer.zendesk.com/rest_api/docs/core/requests#listing-comments
* @param [type] $request_id [description]
* @return [type] [description]
*/
public function list_comments_request( $request_id ) {
return $this->run( "requests/$request_id/comments", $zendesk_pagination );
}
/**
* Get a specific comment.
*
* @link https://developer.zendesk.com/rest_api/docs/core/requests#getting-comments
* @param [type] $request_id [description]
* @param [type] $comment_id [description]
* @return [type] [description]
*/
public function get_comment_request( $request_id, $comment_id ) {
return $this->run( "requests/$request_id/comments/$comment_id" );
}
/* Attachments */