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-helpcenter-api.php
1747 lines (1492 loc) · 51.6 KB
/
wp-zendesk-helpcenter-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 HelpCenter API (https://developer.zendesk.com/rest_api/docs/help_center/introduction)
*
* @package WP-ZD-HelpCenter-API
*/
/* Exit if accessed directly */
if ( ! defined( 'ABSPATH' ) ) {
exit; }
if ( ! class_exists( 'WPZendeskHelpCenterAPI' ) ) {
/**
* Seny API Class.
*/
class WPZendeskHelpCenterAPI extends ZendeskAPIBase {
private $username;
/**
* Install Name.
*
* @var string
*/
protected $base_uri;
/**
* API Key.
*
* @var string
*/
private $api_key;
protected $args;
protected $is_debug;
/**
* __construct function.
*
* @access public
* @param mixed $install_name Install Name.
* @param mixed $api_key API Key.
* @return void
*/
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;
}
protected function set_headers() {
$this->args['headers'] = array(
'Content-Type' => 'application/json',
'Authorization' => 'Basic ' . base64_encode( $this->username . '/token:' . $this->api_key ),
);
}
protected function run( $route, $args = array(), $method = 'GET', $add_data_type = true ) {
return $this->build_request( $route . ($add_data_type ? '.json' : ''), $args, $method )->fetch();
}
protected function clear() {
$this->args = array();
}
/**
* Function for building zendesk pagination.
*
* @param integer $per_page [description]
* @param integer $page [description]
* @param string $sort_by [description]
* @param string $sort_order [description]
* @return [type] [description]
*/
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;
}
/* CATEGORIES. */
/**
* List categories function.
*
* The {locale} is required only for end users and anomynous users.
* Admins and agents can omit it.
*
* The response will list only the categories that the agent, end user, or
* anonymous user can view in Help Center.
*
* AS LONG AS THE API IS RUNNING OFF THEIR AUTHENTICATION.
* You can sort the results with the sort_by and sort_order query string parameters.
*
* @access public
* @link https://developer.zendesk.com/rest_api/docs/help_center/categories#list-categories
* @param string $locale (default: '')
* @param string $sort_by (default: '') Can be position, created_at, or updated_at
* @param string $sort_order (default: '') Can be asc or desc
* @return void
*/
public function list_categories( $locale = 'en-us', $sort_by = 'position', $sort_order = 'desc', $page = 1 ) {
$args = array(
'sort_by' => $sort_by,
'sort_order' => $sort_order,
'page' => $page,
);
return $this->run( "help_center/$locale/categories", $args );
}
/**
* The {locale} is required only for end users and anomynous users. Admins and agents can omit it.
*
* @link https://developer.zendesk.com/rest_api/docs/help_center/categories#show-category
* @param [type] $category_id [description]
* @param string $locale [description]
* @return [type] [description]
*/
public function show_category( $category_id, $locale = 'en-us' ) {
return $this->run( "help_center/$locale/categories/$category_id" );
}
public function build_zendesk_category( $name = '', $locale = '', $description = '', $position = '', $other = array(), $raw = false ) {
$cat = array();
if ( '' !== $name ) {
$cat['name'] = $name;
}
if ( '' !== $locale ) {
$cat['locale'] = $locale;
}
if ( '' !== $description ) {
$cat['description'] = $description;
}
if ( '' !== $position && is_int( $position ) ) {
$cat['position'] = $position;
}
if ( ! empty( $other ) ) {
foreach ( $other as $key => $val ) {
$cat[ $key ] = $val;
}
}
if ( $raw ) {
return $cat;
}
return array(
'category' => $cat,
);
}
/**
* See build_zendesk_category.
*
* @param [type] $category [description]
* @param string $locale [description]
* @return [type] [description]
*/
public function create_category( $category, $locale = 'en-us' ) {
if ( isset( $category['locale'] ) ) {
return $this->run( 'categories', $category, 'POST' );
} else {
return $this->run( "help_center/$locale/categories", $category, 'POST' );
}
}
/**
* These endpoints only update category-level metadata such as the sorting
* position. They don't update category translations.
*
* @link https://developer.zendesk.com/rest_api/docs/help_center/categories#update-category
* @param [type] $category_id [description]
* @param [type] $category [description]
* @param string $locale [description]
* @return [type] [description]
*/
public function update_category( $category_id, $category, $locale = '' ) {
if ( '' !== $locale ) {
return $this->run( "help_center/$locale/categories/$category_id", $category, 'PUT' );
} else {
return $this->run( "help_center/categories/$category_id", $category, 'PUT' );
}
}
/**
* Update category source locale.
* The endpoint updates category source_locale property.
*
* @link https://developer.zendesk.com/rest_api/docs/help_center/categories#update-category-source-locale
* @param [type] $category_id [description]
* @return [type] [description]
*/
public function update_category_locale( $category_id, $updated_source_locale ) {
return $this->run(
"help_center/categories/$category_id/source_locale", array(
'category_locale' => $updated_source_locale,
), 'PUT'
);
}
/**
* Delete category.
*
* WARNING::
* EVERY SECTION AND ALL ARTICLES IN THE CATEGORY WILL ALSO BE DELETED.
*
* @param [type] $category_id [description]
* @return [type] [description]
*/
public function delete_category( $category_id ) {
return $this->run( "help_center/categories/$category_id", array(), 'DELETE' );
}
/* SECTIONS. */
/**
* List sections.
*
* Lists all the sections in Help Center or in a specific category.
*
* The {locale} is required only for end users and anomynous users. Admins and
* agents can omit it.
*
* @link https://developer.zendesk.com/rest_api/docs/help_center/sections#list-sections
* @param [type] $section_id [description]
* @param string $category_id [description]
* @param string $locale [description]
* @return [type] [description]
*/
public function list_sections( $section_id, $category_id = '', $locale = 'en-us' ) {
if ( '' !== $category_id ) {
return $this->run( "help_center/$locale/categories/$category_id/sections" );
} else {
return $this->run( "help_center/$locale/sections" );
}
}
/**
* Show section.
*
* Locale is only needed for end users and anonymouses.
*
* @link https://developer.zendesk.com/rest_api/docs/help_center/sections#show-section
* @param [type] $section_id [description]
* @param string $locale [description]
* @return [type] [description]
*/
public function show_section( $section_id, $locale = 'en-us' ) {
return $this->run( "help_center/$locale/sections/$section_id" );
}
public function build_zendesk_section( $name = '', $description = '', $locale = '', $position = '', $other = array(), $raw = false ) {
$sect = array();
if ( '' !== $name ) {
$sect['name'] = $name;
}
if ( '' !== $description ) {
$sect['description'] = $description;
}
if ( '' !== $locale ) {
$sect['locale'] = $locale;
}
if ( '' !== $position ) {
$sect['position'] = $position;
}
if ( ! empty( $other ) ) {
foreach ( $other as $key => $val ) {
$sect[ $key ] = $val;
}
}
if ( $raw ) {
return $sect;
}
return array(
'section' => $sect,
);
}
/**
* See build_zendesk_section for $section.
*
* Creates a section in a given category. You must specify a section name and
* locale. The locale can be omitted if it's specified in the URL. Optionally,
* you can specify multiple translations for the section. The specified locales
* must be enabled for the current Help Center.
*
* @link https://developer.zendesk.com/rest_api/docs/help_center/sections#create-section
* @param [type] $category_id [description]
* @param [type] $section [description]
* @param string $locale (Default: 'en-us') if blank, must be admin (but acceptable).
* @return [type] [description]
*/
public function create_section( $category_id, $section, $locale = 'en-us' ) {
if ( $locale == '' ) {
return $this->run( "help_center/categories/$category_id/sections", $section, 'POST' );
} else {
return $this->run( "help_center/$locale/categories/$category_id/sections", 'POST' );
}
}
/**
* Update section.
*
* These endpoints only update section-level metadata such as the sorting position.
* They don't update section translations.
*
* @link https://developer.zendesk.com/rest_api/docs/help_center/sections#update-section
* @param [type] $section_id [description]
* @param [type] $section [description]
* @param string $locale [description]
* @return [type] [description]
*/
public function update_section( $section_id, $section, $locale = 'en-us' ) {
if ( $locale == '' ) {
return $this->run( "help_center/sections/$section_id", $section, 'PUT' );
} else {
return $this->run( "help_center/$locale/sections/$setion_id", $section, 'PUT' );
}
}
/**
* Update section source locale.
*
* This endpoint lets you set a section's source language to something other
* than the default language of your Help Center. For example, if the default
* language of your Help Center is English but your KB has a section only for
* Japanese customers, you can set the section's source locale to 'ja'.
*
* @param [type] $section_id [description]
* @param [type] $locale [description]
* @return [type] [description]
*/
public function update_source_locale( $section_id, $locale ) {
return $this->run( "help_center/sections/$section_id/source_locale", array( 'section_locale', $locale ), 'PUT' );
}
/**
* Delete section.
* <b>WARNING: All articles in the section will also be deleted.</b>
*
* @link https://developer.zendesk.com/rest_api/docs/help_center/sections#delete-section
* @param [type] $section_id [description]
* @return [type] [description]
*/
public function delete_section( $section_id ) {
return $this->run( "help_center/sections/$section_id", array(), 'DELETE' );
}
/* ARTICLES. */
/**
* These endpoints let you list all articles in Help Center, all articles in
* a given category or section, or all the articles authored by a specific agent.
* You can also list all articles with metadata that changed since a specified
* start time.
*
* To list articles by content changes, not metadata changes, filter the articles
* by the updated_at timestamp of the articles' translations.
*
* The {locale} is required only for end users or anonymous users. Admins and
* agents can omit it.
*
* You can also use the Search API to list articles. See Search.
*
* @link https://developer.zendesk.com/rest_api/docs/help_center/articles#list-articles
* @param string $locale [description]
* @param [type] $pages [description]
* @return [type] [description]
*/
public function list_articles( $locale = 'en-us', $label_names = '', $pages = null ) {
if ( null === $pages ) {
$pages = $this->build_zendesk_pagination();
}
if ( '' !== $label_names ) {
$pages['label_names'] = $label_names;
}
return $this->run( "help_center/$locale/articles", $pages );
}
public function list_articles_by_category( $category_id, $locale = 'en-us', $label_names = '', $pages = null ) {
if ( null === $pages ) {
$pages = $this->build_zendesk_pagination();
}
if ( '' !== $label_names ) {
$pages['label_names'] = $label_names;
}
return $this->run( "help_center/$locale/categories/$category_id/articles", $pages );
}
public function list_articles_by_section( $section_id, $locale = 'en-us', $label_names = '', $pages = null ) {
if ( null === $pages ) {
$pages = $this->build_zendesk_pagination();
}
if ( '' !== $label_names ) {
$pages['label_names'] = $label_names;
}
return $this->run( "help_center/$locale/sections/$section_id/articles", $pages );
}
public function list_articles_by_user( $user_id, $label_names = '', $pages = null ) {
if ( null === $pages ) {
$pages = $this->build_zendesk_pagination();
}
if ( '' !== $label_names ) {
$pages['label_names'] = $label_names;
}
return $this->run( "help_center/users/$user_id/articles", $pages );
}
public function list_articles_by_incremental( $start_time, $label_names = '', $pages = null ) {
if ( null === $pages ) {
$pages = $this->build_zendesk_pagination();
}
if ( '' !== $label_names ) {
$pages['label_names'] = $label_names;
}
return $this->run( 'help_center/incremental/articles', $pages );
}
/**
* Shows the properties of an article.
*
* The {locale} is required only for end users. Admins and agents can omit it.
*
* @link https://developer.zendesk.com/rest_api/docs/help_center/articles#show-article
* @param [type] $article_id [description]
* @param string $locale [description]
* @return [type] [description]
*/
public function show_article( $article_id, $locale = 'en-us' ) {
return $this->run( "help_center/$locale/articles/$article_id" );
}
public function build_zendesk_article( $title = '', $body = '', $locale = '', $position = '', $other = array(), $raw = false ) {
$art = array();
if ( '' !== $title ) {
$art['title'] = $title;
}
if ( '' !== $body ) {
$art['body'] = $body;
}
if ( '' !== $locale ) {
$art['locale'] = $locale;
}
if ( '' !== $position ) {
$art['position'] = $position;
}
if ( ! empty( $other ) ) {
foreach ( $other as $key => $val ) {
$art[ $key ] = $val;
}
}
if ( $raw ) {
return $art;
}
return array(
'article' => $art,
);
}
/**
* Create article.
*
* Creates an article in the specified section. You must specify an article title
* and locale. The locale can be omitted if it's specified in the URL. Optionally,
* you can specify multiple translations for the article. The specified locales
* must be enabled for the current Help Center.
*
* The current user is automatically subscribed to the article and will receive
* notifications when it changes.
*
* @link https://developer.zendesk.com/rest_api/docs/help_center/articles#create-article
* @param [type] $section_id [description]
* @param array $article See $this->build_zendesk_article.
* @param string $locale [description]
* @return [type] [description]
*/
public function create_article( $section_id, $article, $locale = 'en-us' ) {
if ( isset( $article['locale'] ) ) {
return $this->run( "help_center/sections/$section_id/articles", $article, 'POST' );
} else {
return $this->run( "help_center/$locale/sections/$section_id/articles", $article, 'POST' );
}
}
/**
* Update article.
*
* These endpoints update article-level metadata such as its promotion status
* or sorting position. The endpoints do not update translation properties such
* as the article's title, body, locale, or draft. See Translations.
*
* @param [type] $article_id [description]
* @param [type] $article [description]
* @param string $locale [description]
* @return [type] [description]
*/
public function update_article( $article_id, $article, $locale = 'en-us' ) {
if ( isset( $article['locale'] ) ) {
return $this->run( "help_center/articles/$article_id", $article, 'PUT' );
} else {
return $this->run( "help_center/$locale/articles/$article_id", $article, 'PUT' );
}
}
/**
* Archives the article. You can restore the article using the Help Center user
* interface. See <a href="https://support.zendesk.com/hc/en-us/articles/235721587">
* Viewing and restoring archived articles</a>.
*
* @param [type] $article_id [description]
* @return [type] [description]
*/
public function archive_article( $article_id ) {
return $this->run( "help_center/articles/$article_id", array(), 'DELETE' );
}
/**
* Update article source locale.
*
* The endpoint updates article source_locale property
*
* @param [type] $article_id [description]
* @param [type] $source_locale [description]
* @return [type] [description]
*/
public function update_article_source_locale( $article_id, $source_locale ) {
return $this->run( "help_center/articles/$article_id/source_locale", array( 'article_locale', $source_locale ), 'PUT' );
}
/**
* Associate attachments in bulk to article.
*
* You can associate attachments in bulk to only one article at a time, with
* a maximum of 20 attachments per request.
*
* To create the attachments, see <a href="https://developer.zendesk.com/rest_api/docs/help_center/article_attachments#create-unassociated-attachment">
* Create Unassociated Attachment</a>.
*
* @param [type] $article_id [description]
* @param [type] $attachment_ids Array of attachment IDs (unassociated).
* @return [type] [description]
*/
public function associate_attachments_to_article( $article_id, $attachment_ids ) {
return $this->run(
"help_center/articles/$article_id/bulk_attachments", array(
'attachment_ids' => $attachment_ids,
), 'POST'
);
}
/* ARTICLE COMMENTS. */
/**
* List comments.
*
* Lists the comments created by a specific user, or all comments made by all
* users on a specific article.
*
* The {locale} for the article comments is required only for end users. Admins
* and agents can omit it.
*
* @param [type] $article_id [description]
* @param string $locale [description]
* @return [type] [description]
*/
public function get_comments( $article_id, $locale = 'en-us' ) {
return $this->run( "help_center/$locale/articles/$article_id/comments" );
}
public function get_comments_by_user( $user_id ) {
return $this->run( "help_center/users/$user_id/comments" );
}
/**
* Show comment
*
* Shows the properties of the specified comment.
*
* The {locale} is required only for end users and anomynous users. Admins
* and agents can omit it.
*
* @param [type] $comment_id [description]
* @param [type] $article_id [description]
* @param string $locale [description]
* @return [type] [description]
*/
public function show_comment( $article_id, $comment_id, $locale = 'en-us' ) {
return $this->run( "help_center/$locale/articles/$article_id/comments/$comment_id" );
}
public function build_zendesk_comment( $body = '', $created_at = '', $notify_subscribers = '', $other = array(), $raw = false ) {
$com = array();
if ( '' !== $body ) {
$com['body'] = $body;
}
if ( '' !== $created_at ) {
$com['created_at'] = $created_at;
}
if ( '' !== $notify_subscribers ) {
$com['notify_subscribers'] = $notify_subscribers;
}
if ( ! empty( $other ) ) {
foreach ( $other as $key => $val ) {
$com[ $key ] = $val;
}
}
if ( $raw ) {
return $com;
}
return array(
'comment' => $com,
);
}
/**
* Create comment.
*
* Adds a comment to the specified article. Because comments are associated
* with a specific article translation, or locale, you must specify a locale.
*
* Agents with the Help Center manager role can optionally supply a created_at
* as part of the comment object. If it is not provided created_at is set to
* the current time.
*
* Supplying a notify_subscribers parameter with a value of false will prevent
* subscribers to the comment's article from receiving a comment creation email
* notification. This can be helpful when bulk importing comments.
*
* See $this->build_zendesk_comment
*
* @link https://developer.zendesk.com/rest_api/docs/help_center/comments#create-comment
* @param [type] $article_id [description]
* @param [type] $comment If string, will be the comment as the current user.
* If array, passed in directly.
* @return [type] [description]
*/
public function create_article_comment( $article_id, $comment ) {
if ( gettype( $comment ) === 'string' ) {
$comment = $this->build_zendesk_comment( $comment );
}
return $this->run( "help_center/articles/$article_id/comments", $comment, 'POST' );
}
public function update_comment( $article_id, $comment_id, $comment ) {
return $this->run( "help_center/articles/$article_id/comments/$comment_id", $comment, 'PUT' );
}
public function delete_comment( $article_id, $comment_id ) {
return $this->run( "help_center/articles/$article_id/comments/$comment_id", array(), 'DELETE' );
}
/* ARTICLE LABELS. */
/**
* List article labels
*
* You can set $locale to '' to get generic labels
*
* @param string $locale [description]
* @return [type] [description]
*/
public function list_labels( $locale = 'en-us', $pages = null ) {
if ( null === $pages ) {
$pages = $this->build_zendesk_pagination();
}
return $this->run( "help_center/$locale/articles/labels", $page );
}
/**
* Show label.
*
* Shows the properties of the specified label.
*
* @link https://developer.zendesk.com/rest_api/docs/help_center/labels#show-label
* @param [type] $label_id [description]
* @return [type] [description]
*/
public function show_label( $label_id ) {
return $this->run( "help_center/articles/labels/$label_id" );
}
/**
* List article labels.
*
* Lists all the labels in a given article.
*
* @link https://developer.zendesk.com/rest_api/docs/help_center/labels#list-article-labels
* @param [type] $article_id [description]
* @param [type] $pages [description]
* @return [type] [description]
*/
public function list_article_labels( $article_id, $pages = null ) {
if ( null === $pages ) {
$pages = $this->build_zendesk_pagination();
}
return $this->run( "help_center/articles/$article_id/labels", $pages );
}
/**
* Create label
*
* @param [type] $label_id [description]
* @param [type] $name [description]
* @return [type] [description]
*/
public function create_label( $label_id, $name ) {
return $this->run(
"help_center/articles/$label_id/labels", array(
'label' => array(
'name' => $name,
),
), 'POST'
);
}
public function delete_label_from_article( $article_id, $label_id ) {
return $this->run( "help_center/articles/$article_id/labels/$label_id", array(), 'DELETE' );
}
/**
* Search for articles by label
*
* The <a href="https://developer.zendesk.com/rest_api/docs/help_center/articles.html#search-articles">
* search articles endpoint</a> takes labels into account, but if you want to
* search for articles with specific labels, you can use the
* <a href="https://developer.zendesk.com/rest_api/docs/help_center/articles.html#list-articles">
* list articles</a> endpoint and filter by label names.
*
* @param [type] $label_names [description]
* @return [type] [description]
*/
public function get_articles_by_label( $label_names ) {
return $this->run(
'help_center/articles', array(
'label_names' => $label_names,
)
);
}
// TODO:
/* ARTICLE ATTACHMENTS. */
/* TRANSLATIONS. */
/* SEARCH. */
/**
* Search articles function.
*
* Returns an array of articles.
*
* Articles returned by the search endpoint contain two additional properties:
*
* result_type (string, read only), for articles always "article".
*
* snippet (string, read only), the portion that is relevant to the query.
*
* You must specific at least one of:
* query
* category
* section
* label_names
*
* Honestly just see the link below.
*
* @access public
* @link https://developer.zendesk.com/rest_api/docs/help_center/search#search-articles
* @param string $query The query string.
* @return void
*/
public function search_articles( $query, $pages = null ) {
if ( null === $pages ) {
$pages = $this->build_zendesk_pagination();
}
return $this->run(
'help_center/articles/search', array_merge(
array(
'query' => $query,
), $pages
)
);
}
/* TOPICS. */
/**
* List topics.
*
* Lists all topics.
*
* @param [type] $pages [description]
* @return [type] [description]
*/
public function list_topics( $pages = null ) {
if ( null === $pages ) {
$pages = $this->build_zendesk_pagination();
}
return $this->run( 'community/topics', $pages );
}
/**
* Show topic
*
* Shows information about a single topic.
*
* @link https://developer.zendesk.com/rest_api/docs/help_center/topics#show-topic
* @param [type] $topic_id [description]
* @return [type] [description]
*/
public function show_topics( $topic_id ) {
return $this->run( "community/topics/$topic_id" );
}
/**
* Helper function for building a zendesk topic.
*
* @link https://developer.zendesk.com/rest_api/docs/help_center/topics#content
* @param string $name [description]
* @param string $description [description]
* @param string $position [description]
* @param array $other [description]
* @return [type] [description]
*/
public function build_zendesk_topic( $name = '', $description = '', $position = '', $other = array(), $raw = false ) {
$topic = array();
if ( '' !== $name ) {
$topic['name'] = $name;
}
if ( '' !== $description ) {
$topic['description'] = $description;
}
if ( '' !== $position ) {
$topic['position'] = $position;
}
if ( ! empty( $other ) ) {
foreach ( $other as $key => $val ) {
$topic[ $key ] = $val;
}
}
if ( $raw ) {
return $topic;
}
return array(
'topic' => $topic,
);
}
/**
* Create topic.
*
* Agents with the Help Center Manager role can optionally supply a created_at
* as part of the topic object. If it is not provided created_at is set to the
* current time.
*
* @link https://developer.zendesk.com/rest_api/docs/help_center/topics#create-topic
* @param [type] $topic If a string, will be the name of the topic. Otherwise,
* see $this->build_zendesk_topic.
* @return [type] [description]
*/
public function create_topic( $topic ) {
if ( gettype( $topic ) === 'string' ) {
$topic = $this->build_zendesk_topic( $topic );
}
return $this->run( 'community/topics', $topic, 'POST' );
}
/**
* Update a topic
*
* See $this->build_zendesk_topic.
*
* @param [type] $topic_id [description]
* @param [type] $topic [description]
* @return [type] [description]
*/
public function update_topic( $topic_id, $topic ) {
return $this->run( "community/topics/$topic_id", $topic, 'PUT' );
}
public function delete_topic( $topic_id ) {
return $this->run( "community/topics/$topic_id", array(), 'DELETE' );
}
/* POSTS. */
/**
* List posts.
*
* Lists all posts, all posts in a given topic, or all posts by a specific user.
* When listing by specific user, the posts of the user making the request
* can be listed by specifying me as the id.
*
* @param [type] $pages [description]
* @return [type] [description]
*/
public function list_posts( $pages = null ) {
if ( null === $pages ) {
$pages = $this->build_zendesk_pagination();
}
return $this->run( 'community/posts', $pages );
}
public function list_posts_by_topic( $topic_id, $pages = null ) {
if ( null === $pages ) {
$pages = $this->build_zendesk_pagination();
}
return $this->run( "community/$topic_id/posts", $pages );
}
public function list_posts_by_user( $user_id, $pages = null ) {
if ( null === $pages ) {
$pages = $this->build_zendesk_pagination();
}
return $this->run( "community/$user_id/posts", $pages );
}
/**
* Show post
*
* Gets information about a given post.
*
* @param [type] $post_id [description]
* @return [type] [description]
*/
public function show_post( $post_id ) {
return $this->run( "community/posts/$post_id" );
}
/**
* Helper function for building a zendesk post.
*
* @link https://developer.zendesk.com/rest_api/docs/help_center/posts#posts
* @param string $title [description]
* @param string $details [description]
* @param array $other [description]
* @return [type] [description]
*/
public function build_zendesk_post( $topic_id = '', $title = '', $details = '', $other = array(), $raw = false ) {
$post = array();
if ( '' !== $title ) {