For anyone that want’s to know, I fixed it myself:
function send_form_data_to_hubspot_pipeline($form_data, $form_id) {
// Set the API key and pipeline ID
$api_key = 'YOUR-HS-API-KEY';
$pipeline_id = 'YOUR-PIPELINE-ID';
// Create the contact data array
$contact_data = array(
'properties' => array(
array(
'property' => 'email',
'value' => $form_data['email-1']
),
array(
'property' => 'firstname',
'value' => $form_data['name-1']
),
//add any other fields here
)
);
// Convert the data to JSON format
$json_data = json_encode($contact_data);
// Set the API endpoint URL
$endpoint_url = "https://api.hubapi.com/deals/v1/deal?hapikey={$api_key}";
// Set the request parameters
$request_args = array(
'headers' => array(
'Content-Type' => 'application/json'
),
'body' => $json_data
);
// Send the request to the API endpoint
$response = wp_remote_post($endpoint_url, $request_args);
// Check for errors
if(is_wp_error($response)) {
return false;
}
// Check the status code
$status_code = wp_remote_retrieve_response_code($response);
if($status_code != 200) {
return false;
}
// Get the deal ID from the response
$response_body = wp_remote_retrieve_body($response);
$response_data = json_decode($response_body, true);
$deal_id = $response_data['dealId'];
// Add the deal to the pipeline
$pipeline_url = "https://api.hubapi.com/deals/v1/pipelines/{$pipeline_id}/deals/{$deal_id}?hapikey={$api_key}";
$pipeline_args = array(
'headers' => array(
'Content-Type' => 'application/json'
),
'body' => '{}'
);
wp_remote_put($pipeline_url, $pipeline_args);
// Return true on success
return true;
}
function handle_form_submission($form_data) {
send_form_data_to_hubspot_pipeline($form_data);
}