Title: webhook filter
Last modified: May 20, 2023

---

# webhook filter

 *  Resolved [Alex](https://wordpress.org/support/users/alexandronalin/)
 * (@alexandronalin)
 * [3 years ago](https://wordpress.org/support/topic/webhook-filter/)
 * Hi,
 * I’m trying to use this filter to add an array to webhook output:
 * [https://vikwp.com/support/knowledge-base/vik-appointments/hooks/web-hooks/before-dispatch](https://vikwp.com/support/knowledge-base/vik-appointments/hooks/web-hooks/before-dispatch)
 * but it seems I’m wrong to code.
 * If I use the code below, it works, adding [somekey] => true:
 *     ```wp-block-code
       add_filter('vikappointments_before_dispatch_webhook', function($status, &$payload, &$headers, $hook, $job)
       {
          	$payload = array(
       	"somekey" => true
       	);
       	return $status;
       }, 10, 5);
       ```
   
 * but it replaces completely the output payload.
 * If I use the code below instead:
 *     ```wp-block-code
       add_filter('vikappointments_before_dispatch_webhook', function($status, &$payload, &$headers, $hook, $job)
       {
            $payload['somekey'] = 'true' );
   
            return $status;
       }, 10, 5);
       ```
   
 * no webhook output comes from plugin.
 * Have you an idea where I’m wrong?
 * Many thanks

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Thread Starter [Alex](https://wordpress.org/support/users/alexandronalin/)
 * (@alexandronalin)
 * [3 years ago](https://wordpress.org/support/topic/webhook-filter/#post-16753593)
 * Sorry. The 2nd code I pasted before was wrong. This is the right one, but as 
   I said it doesn’t work
 *     ```wp-block-code
       add_filter('vikappointments_before_dispatch_webhook', function($status, &$payload, &$headers, $hook, $job)
       {
            $payload['somekey'] = 'true' ;
   
            return $status;
       }, 10, 5);
       ```
   
 *  Plugin Author [e4jvikwp](https://wordpress.org/support/users/e4jvikwp/)
 * (@e4jvikwp)
 * [3 years ago](https://wordpress.org/support/topic/webhook-filter/#post-16757717)
 * Hi Alex,
 * as you can see from our documentation, the type of the `$payload` argument is
   flagged as `mixed`. This means that it may vary depending on the webhook that
   is going to be dispatched.
 * According to your example, if you try to assign an attribute by considering the`
   $payload` as an array, the system will throw an error in case the latter is actually
   an object. That’s why the webhook never reaches the end-point you specified.
 * I think that you have just to modify a bit your code in order to make sure that
   you are properly treating the `$payload` argument according to the provided type.
   Something like:
 *     ```wp-block-code
       add_filter('vikappointments_before_dispatch_webhook', function($status, &$payload, &$headers, $hook, $job)
       {
            if (is_array($payload))
            {
                 $payload['somekey'] = true;
            }
            else if (is_object($payload))
            {
                 $payload->somekey = true;
            }
   
            return $status;
       }, 10, 5);
       ```
   
 *  Thread Starter [Alex](https://wordpress.org/support/users/alexandronalin/)
 * (@alexandronalin)
 * [3 years ago](https://wordpress.org/support/topic/webhook-filter/#post-16758334)
 * Great!
 * Many thanks

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘webhook filter’ is closed to new replies.

 * ![](https://ps.w.org/vikappointments/assets/icon-256x256.png?rev=2127296)
 * [VikAppointments Services Booking Calendar](https://wordpress.org/plugins/vikappointments/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/vikappointments/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/vikappointments/)
 * [Active Topics](https://wordpress.org/support/plugin/vikappointments/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/vikappointments/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/vikappointments/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Alex](https://wordpress.org/support/users/alexandronalin/)
 * Last activity: [3 years ago](https://wordpress.org/support/topic/webhook-filter/#post-16758334)
 * Status: resolved