I need to send Forminator form data to a Hubspot workflow for a client. This doesn't seem to be working
function send_form_data_to_hubspot($form_data) {
$hubspot_api_key = 'MY_API_KEY';
$hubspot_workflow_id = 'WORKFLOW_ID_HERE';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.hubapi.com/automation/v3/workflows/{$hubspot_workflow_id}/enrollments/contacts",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($form_data),
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json",
"Authorization: Bearer {$hubspot_api_key}"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
error_log("cURL Error #:" . $err);
return false;
} else {
return true;
}
}
add_action('forminator_custom_form_after_submission', function($entry, $form) {
$form_data = array(
'email' => $entry['email-1'],
'first_name' => $entry['name-1'],
'last_name' => $entry['name-2'],
// add any additional fields you want to send to the Hubspot workflow
);
send_form_data_to_hubspot($form_data);
}, 10, 2);
No contact is being added in Hubspot, and the workflow isn't triggered
Anyone have an ideas at all?