This guide will help you understand how to configure your PHP application to receive webhook payloads from Salespanel.io.
Step 1: Setup Your PHP Endpoint
First, you will need to set up a PHP endpoint to receive the incoming POST requests. This will be a URL on your server where the webhook data will be sent.
Here's an example of a basic PHP script that could act as an endpoint:
// This is a simple PHP script that handles incoming webhook data
// Retrieve the request's body
$body = @file_get_contents('php://input');
// Decode the JSON body to an associative array
$data = json_decode($body, true);
// You can now use the $data array
// For example, to print the entire array, you can use:
Step 2: Configure Webhook on Salespanel.io
Configure your webhook on Salespanel.io to send data to the URL where you set up your PHP script.
Step 3: Test Your Webhook
To test your webhook, you can trigger an event on Salespanel.io that will send data to your webhook.
Check your server logs or however you decided to handle the data in your PHP script to see if the webhook data was received correctly.
$_POST won't work here
$_POST is a superglobal variable that is used to collect form data after submitting an HTML form with method="post".
$_POST is also used to pass variables.
In the case of a JSON payload sent via a POST request, like in the webhooks from Salespanel.io,
$_POST will not work because this data is not form data, but rather raw JSON in the request body. Therefore, you need to use
php://input to read the raw POST data.
Keep in mind that your PHP script should be prepared to handle errors appropriately. For example, if there is a problem with decoding the JSON data or the request's body is empty, your script should handle these cases in a way that is appropriate for your application.
That's it! This simple guide should help you to start receiving webhook payloads from Salespanel.io in your PHP application. Please adjust the PHP code to suit your specific needs.