Example: Send Broadcast
Sample code for sending a broadcast via Groundhogg's API. Ensure you have an email set up and its corresponding ID before using this code.
<?php // Define your Groundhogg API credentials $api_url = 'https://smart-aardvark-5aecd5.instawp.xyz/wp-json/gh/v4/broadcasts/'; $gh_token = '1e6e0b29b8b4b478c0c3d2b1210f3a4c'; // Replace with your actual API token $gh_public_key = '3e4b5a7c593e194d7496a514ef22ffeb'; // Replace with your actual Public key // Data to send in the POST request $data = [ 'query' => [ 'filters' => [ [ [ 'type' => 'is_marketable', 'marketable' => 'yes', 'id' => '57d52d48-c140-4ed6-b989-5e21671be271' ] ] ] ], 'object_type' => 'email', 'object_id' => 1, // Replace with the Email ID 'date' => '2025-03-12', 'time' => '13:00:00', 'send_now' => false ]; // Initialize cURL session $ch = curl_init($api_url); // Set the request headers $headers = [ 'Content-Type: application/json', 'Gh-Token: ' . $gh_token, 'Gh-Public-Key: ' . $gh_public_key ]; // Set cURL options curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); // Execute the request $response = curl_exec($ch); // Check for errors if(curl_errno($ch)) { echo 'Error:' . curl_error($ch); exit; } // Close the cURL session curl_close($ch); // Decode the response $response_data = json_decode($response, true); // Check if the response contains an error or success if (isset($response_data['error'])) { echo "Error: " . $response_data['message']; } else { echo "Broadcast created successfully!"; //echo "<pre>"; //print_r($response_data); //echo "</pre>"; }