As a digital marketer, I was looking for a way to send leads from custom opt-in forms on my website directly into my BeeHiiv account. BeeHiiv's built-in opt-in forms are rather limited, so I wanted more control over the lead capture process on my site without using Make or Zapier.
After some research, I discovered BeeHiiv has an API that allows you to integrate custom forms. However, the documentation was technical, and implementing it seemed complicated.
Rather than go down the plugin route or try to build something from scratch, I decided to take a simpler approach, using AI to generate the code for a custom webhook. This way, I could create a PHP script to handle the form submissions from my site and automatically send the data to my BeeHiiv account.
Power of AI for Custom Marketing Integrations
Getting custom integrations like this BeeHiiv webhook setup can be a headache. I was reading through the API doc and I was lost!
You either have to rely on dev teams and pay high fees or jerry-rig solutions with other automation tools and plugins.
But with the power of AI, I was able to quickly and easily create exactly the integration I needed—no coding expertise required!
- Cost Savings - No need to pay developers or monthly fees for automation platforms. The AI did the work for free.
- Customization - I got a solution tailored to my specific needs, not a one-size-fits-all tool. The code was generated for my exact use case.
- Simplicity - Rather than cobble together workarounds, the AI provided a simple, elegant solution with clear documentation.
- Speed - I went from idea to working solution in less than an hour. No long development or testing process.
- Flexibility - I can easily tweak the code as needed for other projects and integrations in the future.
Now let's get to the Beehiiv php script to start posting data to your BeeHiiv account.
Getting Your BeeHiiv Credentials
The first step is to get your Publication ID and API key from within your BeeHiiv account:
- Publication ID: This is found in Settings > Integrations. You'll need to insert this into the API endpoint URL.
- API Key: You'll need to generate a new key specifically for this webhook script. This is also in the Integrations section of your BeeHiiv account.
The Custom Webhook PHP Script
With those credentials, I used Claude to generate a simple PHP script to handle the form POST data and integrate it with the BeeHiiv API.
It handles:
- Retrieving the form data (email) from the POST request
- Constructing the API URL with the Publication ID
- Sending the data to BeeHiiv API with the API key
Now I can use this on any custom form by pointing the form action to this PHP file. Whenever someone submits the form, it will automatically send their information to my BeeHiiv account as a new lead!
Here is the simple PHP webhook code that Claude generated for me.
<?php
// API endpoint
$url = 'https://api.beehiiv.com/v2/publications/pub_ID/subscriptions/';
// Subscription data
$data = [
'email' => $_GET['email']
];
// Initialize cURL
$ch = curl_init($url);
// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
// Set headers
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Authorization: Bearer YOUR_API_KEY'
]);
// Execute request and get response
$response = curl_exec($ch);
// Close handle
curl_close($ch);
// Print response
echo $response;
?>
Now that we have the PHP webhook script, we need to connect it to our Avada form. You will simply upload this PHP file on your hosting provider and then copy that URL.
Implementing BeeHiiv Integration Script
But first here are two important steps:
- Insert Your Credentials (BOLD)
The first thing is to create the PHP file on your hosting server and enter your actual BeeHiiv credentials inside the script:
- Publication ID - This comes from your BeeHiiv Integrations page.
- API Key - Use the API key you generated for this script.
This allows the script to access your BeeHiiv account.
- Set the Form Action to the Webhook URL (Get)
Now you can either remove the last 2 lines, print response section. It is good to just leave it here for testing. Once it is finalized, you can remove it.
Next, let us implement this into your Avada form. Essentially, you can use this script now in any form. I needed this code for my Avada themed website, but this is a very simple PHP integration code and can be used on any form.
Implementing this Code into Avada Forms
If you're using the Avada WordPress theme as I am, you can easily connect your Avada forms to the BeeHiiv webhook for processing submissions with the PHP code I just provided.
Here's how to set it up:
- In Avada > Form > Settings, go to the "Submission" tab.
- Set the "Submission URL" to the URL of the BeeHiiv PHP webhook file you created earlier.
- Use the GET method for submission rather than POST.
- Enable AJAX form submission. This displays a loading icon while the form is processed.
- The PHP webhook code doesn't include error handling. So you'll need to add your own redirect in case of errors.
The Avada form has its own basic validation (like required fields, email format, etc.). But any errors from the PHP code won't show up.
And that's it! Now your Avada form will process through the webhook to add leads to your BeeHiiv account automatically.
You can create opt-in forms, contact forms, surveys, and more this way without being limited to BeeHiiv's default options.
AI is the shit!!