@@ -32,6 +32,29 @@ public function register_rest_route() {
3232 'methods ' => \WP_REST_Server::READABLE ,
3333 'callback ' => array ( $ this , 'get_support_interactions ' ),
3434 'permission_callback ' => 'is_user_logged_in ' ,
35+ 'args ' => array (
36+ 'status ' => array (
37+ 'type ' => 'string ' ,
38+ 'required ' => false ,
39+ 'enum ' => array (
40+ 'open ' ,
41+ 'resolved ' ,
42+ ),
43+ ),
44+ 'page ' => array (
45+ 'type ' => 'integer ' ,
46+ 'required ' => false ,
47+ 'default ' => 1 ,
48+ 'minimum ' => 1 ,
49+ ),
50+ 'per_page ' => array (
51+ 'type ' => 'integer ' ,
52+ 'required ' => false ,
53+ 'default ' => 10 ,
54+ 'minimum ' => 1 ,
55+ 'maximum ' => 100 ,
56+ ),
57+ ),
3558 )
3659 );
3760
@@ -54,7 +77,7 @@ public function register_rest_route() {
5477 'permission_callback ' => 'is_user_logged_in ' ,
5578 'args ' => array (
5679 'event_external_id ' => array (
57- 'type ' => 'int ' ,
80+ 'type ' => 'string ' ,
5881 'required ' => true ,
5982 ),
6083 'event_source ' => array (
@@ -78,7 +101,7 @@ public function register_rest_route() {
78101 'permission_callback ' => 'is_user_logged_in ' ,
79102 'args ' => array (
80103 'event_external_id ' => array (
81- 'type ' => 'int ' ,
104+ 'type ' => 'string ' ,
82105 'required ' => true ,
83106 ),
84107 'event_source ' => array (
@@ -92,6 +115,26 @@ public function register_rest_route() {
92115 ),
93116 )
94117 );
118+
119+ register_rest_route (
120+ $ this ->namespace ,
121+ '/ ' . $ this ->rest_base . '/(?P<support_interaction_id>[a-zA-Z0-9-]+)/status ' ,
122+ array (
123+ 'methods ' => \WP_REST_Server::EDITABLE ,
124+ 'callback ' => array ( $ this , 'update_support_interaction_status ' ),
125+ 'permission_callback ' => 'is_user_logged_in ' ,
126+ 'args ' => array (
127+ 'status ' => array (
128+ 'type ' => 'string ' ,
129+ 'required ' => true ,
130+ 'enum ' => array (
131+ 'open ' ,
132+ 'resolved ' ,
133+ ),
134+ ),
135+ ),
136+ )
137+ );
95138 }
96139
97140 /**
@@ -173,4 +216,25 @@ public function create_support_interaction_event( \WP_REST_Request $request ) {
173216
174217 return rest_ensure_response ( $ response );
175218 }
219+
220+ /**
221+ * Update support interaction status.
222+ *
223+ * @param \WP_REST_Request $request The request sent to the API.
224+ */
225+ public function update_support_interaction_status ( \WP_REST_Request $ request ) {
226+ $ support_interaction_id = isset ( $ request ['support_interaction_id ' ] ) ? (int ) $ request ['support_interaction_id ' ] : null ;
227+
228+ $ status = $ request ['status ' ];
229+
230+ $ body = Client::wpcom_json_api_request_as_user ( "/support-interactions/ $ support_interaction_id/status?status= {$ status }" );
231+
232+ if ( is_wp_error ( $ body ) ) {
233+ return $ body ;
234+ }
235+
236+ $ response = json_decode ( wp_remote_retrieve_body ( $ body ) );
237+
238+ return rest_ensure_response ( $ response );
239+ }
176240}
0 commit comments