Title: Webhooks returning null
Last modified: August 30, 2020

---

# Webhooks returning null

 *  Resolved [johnrichardarmstrong](https://wordpress.org/support/users/johnrichardarmstrong/)
 * (@johnrichardarmstrong)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/webhooks-returning-null/)
 * I am wanting to run code contained within a plugin I have created when a webhook
   is triggered by a POST request on a webofrm. All of my code works except “null”
   is always returned, or rather, some blank space and newline characters followed
   by null. My abridged code is as follows:
 * `
    add_filter(‘wpwhpro/run/actions/custom_action/return_args’, ‘CreateInvoice’,
   10, 3);
 * function CreateInvoice($return_args, $identifier, $response_body){
 * //Some code to perform the task I want (which does work)
 * if( $identifier === ‘student-invoice’ ){
 * $return_args = array(
    ‘success’ => true, ‘msg’ => ‘The call was successful’,‘
   data’ => array() );
 * return $return_args;
 * }
    } }
 * When implemented as a code snippet the response is fine but not when implemented
   as a plugin. For my code to function, it must be implemented as a plugin and 
   not a snippet. I was wondering if you know any reason why the response would 
   be null when I use your custom_action webhooks within a plugin?
 * Many thanks,
 * John
    -  This topic was modified 5 years, 8 months ago by [johnrichardarmstrong](https://wordpress.org/support/users/johnrichardarmstrong/).
    -  This topic was modified 5 years, 8 months ago by [johnrichardarmstrong](https://wordpress.org/support/users/johnrichardarmstrong/).
    -  This topic was modified 5 years, 8 months ago by [johnrichardarmstrong](https://wordpress.org/support/users/johnrichardarmstrong/).

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

 *  Plugin Contributor [Ironikus](https://wordpress.org/support/users/ironikus/)
 * (@ironikus)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/webhooks-returning-null/#post-13335878)
 * Hey [@johnrichardarmstrong](https://wordpress.org/support/users/johnrichardarmstrong/)–
   thank you for your message, as well as for using our plugin.
 * Apart from the fact that your code above is wrongly formatted and contains invalid
   code, the issue you are facing is that you return the arguments only within the
   if clause.
    Please use the properly formatted code down below.
 *     ```
       add_filter( 'wpwhpro/run/actions/custom_action/return_args', 'CreateInvoice', 10, 3 );
       function CreateInvoice($return_args, $identifier, $response_body){
   
       	//Some code to perform the task I want (which does work)
   
       	if( $identifier === 'student-invoice' ){
   
       		$return_args = array(
       		'success' => true,
       		'msg' => 'The call was successful',
       		'data' => array()
       		);
   
       	}
   
       	return $return_args;
       }
       ```
   
 * Feel free to let me know in case you have any further questions. 🙂
 *  Thread Starter [johnrichardarmstrong](https://wordpress.org/support/users/johnrichardarmstrong/)
 * (@johnrichardarmstrong)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/webhooks-returning-null/#post-13336011)
 * Thanks for your very prompt response. I’m not sure that it solves the issue I
   am having though. I have tried to simplify my problem to help illustrate it better:
 * I have taken on board your points about formatting and where the return statement
   is placed but I am still getting the response (some whitespace followed by null).
 * “null”
 * My code looks like this:
 *     ```
       add_filter('wpwhpro/run/actions/custom_action/return_args', 'SimpleFunction', 10, 3);
   
       function SimpleFunction($return_args, $identifier, $response_body){
   
           if( $identifier === 'test-webhook-as-plugin' ){
   
               $return_args = array(
                   'success' => true,
                   'msg' => 'The call was successful',
                   'data' => array()
               );
   
               //wp_mail(myEmailAddress, 'function fired successfully', 'see subject');
           }
   
           return $return_args;
       }
       ```
   
 * As you can see, to test that the code was actually being run I had the wp_mail(
   now commented out) function send me an email which did arrive, showing that the
   code did run. I was wondering if there is something obvious I am missing. The
   webhook can be triggered using the following GET request:
 * `https://findmytutoronline.com/?wpwhpro_action=receive-invoice-data&wpwhpro_api_key
   =xxxxxxxxxxxx&action=custom_action&wpwh_identifier=test-webhook-as-plugin`
 * Many thanks again; I do appreciate you efforts.
 * John
    -  This reply was modified 5 years, 8 months ago by [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/).
    -  This reply was modified 5 years, 8 months ago by [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/).
 *  Plugin Contributor [Ironikus](https://wordpress.org/support/users/ironikus/)
 * (@ironikus)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/webhooks-returning-null/#post-13336039)
 * Hi [@johnrichardarmstrong](https://wordpress.org/support/users/johnrichardarmstrong/)–
   Thank you for your answer.
 * The most important thing up front: Please NEVER post your webhook URL within 
   a public place and keep it ONLY for yourself. This is critical for security in
   case you do not work with access tokens or whitelists or special permissions.
 * The code looks correct now, but the issue I can see is most likely not caused
   by our plugin.
    Since the output looks very odd to me (from the link you posted),
   the issue might appear from some other malfunctioned PHP code. From experience,
   I know that poorly coded plugins contain some empty space or characters in front
   of the `<?php` tag of PHP files, which is outputted as content. This should be
   fixed in any way since it can break the functionality of a lot of different plugins.
 * Please also make sure that you do not use a similar code on another position 
   within your plugin that is malfunctioned like the previous one you posted.
 * For further debugging, I suggest you deactivate your plugins and activate it 
   one by one to see if the error persists.
 * If you have any further questions, feel free to let me know.

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

The topic ‘Webhooks returning null’ is closed to new replies.

 * ![](https://ps.w.org/wp-webhooks/assets/icon-256x256.jpg?rev=2656397)
 * [WP Webhooks - Automate repetitive tasks by creating powerful automation workflows directly within WordPress](https://wordpress.org/plugins/wp-webhooks/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-webhooks/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-webhooks/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-webhooks/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-webhooks/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-webhooks/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Ironikus](https://wordpress.org/support/users/ironikus/)
 * Last activity: [5 years, 8 months ago](https://wordpress.org/support/topic/webhooks-returning-null/#post-13336039)
 * Status: resolved