• makesitechanges

    (@makesitechanges)


    Hello! I’m sorry if this is a stupid post, but I am new to Webhooks and could use some help. I have a raw JSON payload that is being POSTED and I would like it, as is, to be emailed to specific people. I have a 3’rd party website/app that is sending a JSON payload.

    I have:
    -Created a webhook in WP Webhooks
    -I installed the Email Integration webhook for WP Webhooks and enabled its use.
    -I gave the Webhook URL to the sending website/app
    -I complete an action on the 3rd party website/app and it sends a JSON Payload via POST.

    I guess my question is: “Then what?” I can’t see any place to enter the email info (address, subject, etc.), or even where to view the payload that was sent.

    Am I just missing a piece? If so, can you recommend one?

    Thank you so much!

Viewing 1 replies (of 1 total)
  • Plugin Contributor Ironikus

    (@ironikus)

    Hey @makesitechanges – Thank you for reaching out, as well as for using our plugin.
    As you want to directly connect a fixed payload to sending an email, you would have to do certain steps to convert the payload into a data structure that our plugin can work with (e.g. you would need to define the action argument, emails, etc within the payload).
    Since you want to send the payload in an unformatted way, the best way would be to use the custom_action webhook action instead.
    It allows you to fire custom PHP code once a URL hits the page.

    To make it work, I prepared a script for you which you can add to your functions.php file. Here are all steps to guide you through the process

    1. Activate the custom_action webhook action
    2. Add the following PHP code to your functions.php file:
      add_filter( 'wpwhpro/run/actions/custom_action/return_args', 'wpwh_fire_my_custom_logic', 10, 3 );
      function wpwh_fire_my_custom_logic( $return_args, $identifier, $response_body ){
      
      	$ident = 'sendfullpayload';
      	$to = '[email protected],[email protected]';
      	$subject = 'The subject';
      	$headers = array('Content-Type: text/html; charset=UTF-8');
      
      	//If the identifier doesn't match, do nothing
      	if( $identifier !== $ident ){
      		return $return_args;
      	}
      
      	$body = file_get_contents('php://input');
      
      	$check = wp_mail( $to, $subject, $body, $headers );
      
      	if( $check ){
      		$return_args['success'] = true;
      	}
      	
      	return $return_args;
      
      }
    3. Once added, please adjust the emails within the $to variable (comma-separate multiple ones)
    4. Also adjust the title if necessary.
    5. As for the webbhook URL you added to your external service (the service that sends the data), please add another query parameter at the end of the URL: &wpwh_identifier=sendfullpayload
    6. Please add another parameter at the end of the URL that defines the webhook action: &action=custom_action
    7. Please give it another try (The emails should now be directly sent once the data arrives)

    I hope this helps you so far. Do let me know in case you have any questions. ??

Viewing 1 replies (of 1 total)
  • The topic ‘Email – Raw JSON Payload – Getting Started’ is closed to new replies.