简体   繁体   中英

How do you send back data when you get a webhook?

I have a quick question. I am new to webhooks and the service I am using requires a response. I am doing this in php and here are their instructions:

We require you to verify the ownership of the server you are making WebHook calls to by adding the following object parameters to your JSON response.

{ "details": { "zippy_token":"xxxxxxxxxxxxxxxx" }}

After adding the JSON response code to your WebHook endpoint, come back here and click the green Add Webhook button. Zippykind will verify your WebHook by making a POST call to your WebHook URL with the handshake within the parameters, afterwhich will add the verified WebHook to your active list of WebHooks. You only need to do this once, after the WebHook has been verified, you can remove the zippy_token parameter from your JSON response.

I see how to get the data but how do I send the info needed (the token) back?

This will be done in PHP.

Thanks

If your site, or what you're developing is located at abc.com , you'd essentially need to create a php script for your webhook callback. abc.com/testwebhook.php .

Inside of the testwebhook.php , you'll output a JSON response with the data formatted as they expect to receive it { "details": { "zippy_token":"xxxxxxxxxxxxxxxx" }}

In case the service you're interacting with (Zippy) is checking the header output of your response, you may need to set the header via PHP within your testwebhook.php script: header('Content-Type: application/json');

Example - testwebhook.php

`<?php 
   $output = '{ "details" : { "zippy_token":"xxxxxxxxxxxxxxxx" }}';
   header('Content-Type: application/json');
   echo $output;
   exit;
 ?>

You'll need to ensure that your json is properly formatted and the endpoint doesn't expect more data returned.

Then the rest is explained ini your initial question. Create the webhook by entering the URL at the Zippy service that gave you those instructions and add the url to the script you setup abc.com/testwebhook.php .

That should be all you need to do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM