Get the delivery logs for this webhook.
public get_delivery_logs ( ) : array | ||
return | array |
/** * Get all webhook deliveries. * * @param WP_REST_Request $request * @return array */ public function get_items($request) { $webhook = new WC_Webhook((int) $request['webhook_id']); if (empty($webhook->post_data->post_type) || 'shop_webhook' !== $webhook->post_data->post_type) { return new WP_Error('woocommerce_rest_webhook_invalid_id', __('Invalid webhook id.', 'woocommerce'), array('status' => 404)); } $logs = $webhook->get_delivery_logs(); $data = array(); foreach ($logs as $log) { $delivery = $this->prepare_item_for_response((object) $log, $request); $delivery = $this->prepare_response_for_collection($delivery); $data[] = $delivery; } return rest_ensure_response($data); }
/** * Get deliveries for a webhook * * @since 2.2 * @param string $webhook_id webhook ID * @param string|null $fields fields to include in response * @return array */ public function get_webhook_deliveries($webhook_id, $fields = null) { // Ensure ID is valid webhook ID $webhook_id = $this->validate_request($webhook_id, 'shop_webhook', 'read'); if (is_wp_error($webhook_id)) { return $webhook_id; } $webhook = new WC_Webhook($webhook_id); $logs = $webhook->get_delivery_logs(); $delivery_logs = array(); foreach ($logs as $log) { // Add timestamp $log['created_at'] = $this->server->format_datetime($log['comment']->comment_date_gmt); // Remove comment object unset($log['comment']); $delivery_logs[] = $log; } return array('webhook_deliveries' => $delivery_logs); }