# Connecting WPForms to HubSpot Forms API

**URL:** <https://community.hubspot.com/t/connecting-wpforms-to-hubspot-forms-api/100902>\
**Category:** APIs & Integrations\
**Tags:** forms\
**Created:** [February 23, 2024, 11:25am UTC](https://community.hubspot.com/t/connecting-wpforms-to-hubspot-forms-api/100902 "2024-02-23T11:25:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JGlasspool](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jglasspool/32/201738_2.png) [@JGlasspool](https://community.hubspot.com/u/JGlasspool)\
**Post date:** [February 23, 2024, 11:25am UTC](https://community.hubspot.com/t/connecting-wpforms-to-hubspot-forms-api/100902/1 "2024-02-23T11:25:50Z")

</div>

Hi

I am trying send form submissions through a Wordpress site to HubSpot forms API but nothing is getting through.

Here is my code. Can you see any obvious errors in it:

```lia-code-sample
add_action( 'wpforms_process_complete', 'send_to_hubspot', 5, 4 );
/**
 * Integrate WPForms with CRM
 *
 * @author Bill Erickson
 * @link https://www.billerickson.net/contact-form-integration/
 * 
 * @param array $fields
 * @param array $entry
 * @param array $form_data
 * @param int $entry_id
 */

function send_to_hubspot($fields, $form_data) {

	$hubspot_api_key = 'XXXXXXXXXXXXXXXXXXX';
 $hubspot_portal_id = 'XXXXXXXX';	

	// Keep In Touch form (WPForms ID = 105)
	if( $form_data['id'] == '105' ) {

		$hubspot_form_guid = '{FORM_ID}';	

		$hubspot_data = array(
			'firstname' => $fields['6']['value'],
			'lastname' => $fields['14']['value'],
			'email' => $fields['1']['value'],
			'zip' => $fields['12']['value'],		
		);

	}

	// Finance Offer Contact Form (WPForms ID = 5617)
	if( $form_data['id'] == '5617' ) {

	$hubspot_form_guid = '{FORM_ID}';

		$hubspot_data = array(
			'firstname' => $fields['3']['value'],
			'lastname' => $fields['9']['value'],
			'phone' => $fields['12']['value'],
			'email' => $fields['4']['value'],
			'Postal_code' => $fields['5']['value'],
			'dealer_id' => $fields['8']['value_raw'],
			'message' => $fields['16']['value']
		);

	}

	// Test Drive Form (WPForms ID = 2951)
	if( $form_data['id'] == '2951' ) {

		$hubspot_form_guid = '{FORM_ID}';	

		$hubspot_data = array(
			'firstname' => $fields['3']['value'],
			'lastname' => $fields['9']['value'],
			'phone' => $fields['12']['value'],
			'email' => $fields['4']['value'],
			'location' => $fields['28']['value'],
			'dealer_id' => $fields['29']['value'],
			'extra_info' => $fields['30']['value'],		
		);

	}

	$api_url = "https://api.hsforms.com/submissions/v3/integration/secure/submit/{$hubspot_portal_id}/{$hubspot_form_guid}";	

	$response = wp_remote_post( 
		$api_url,		
		array( 
			'headers' => array(
 'Content-Type' => 'application/json',
 'Authorization' => 'Bearer ' . $hubspot_api_key,
 ),
			'body' => wp_json_encode($hubspot_data),
		) 
	);

	// Check for errors
 if ( is_wp_error( $response ) ) {
 error_log( 'HubSpot API error: ' . $response->get_error_message() );
 } else {
 $body = wp_remote_retrieve_body( $response );
 $data = json_decode( $body );

 // Log the response for debugging purposes
 error_log( 'HubSpot API response: ' . print_r( $data, true ) );
 }

}

```

---

<div class="post-metadata">

**Author:** ![dsmarion](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dsmarion/32/7509_2.png) [@dsmarion](https://community.hubspot.com/u/dsmarion)\
**Post date:** [February 23, 2024, 3:23pm UTC](https://community.hubspot.com/t/connecting-wpforms-to-hubspot-forms-api/100902/2 "2024-02-23T15:23:23Z")

</div>

Do you have the HubSpot tracking code installed on your WP site?

---

<div class="post-metadata">

**Author:** ![RobertYoung](https://avatars.discourse-cdn.com/v4/letter/r/6f9a4e/32.png) [@RobertYoung](https://community.hubspot.com/u/RobertYoung)\
**Post date:** [March 31, 2025, 9:26am UTC](https://community.hubspot.com/t/connecting-wpforms-to-hubspot-forms-api/100902/3 "2025-03-31T09:26:25Z")

</div>

Hey, the easiest way I’ve found is using WPForms’ own HubSpot add-on—it syncs your forms directly without needing custom API code. If you prefer using your current setup, double-check your API key, portal ID, and data formatting—usually, one of those is causing the hiccup.
