Hi All,
I am creating a php webhook to collect the data from an HTML form and submit them into HubSpot CRM.
I have already created a private app for that.
Can anyone tell me what I am missing:
<?php
if ($_SERVER[‘REQUEST_METHOD’] === ‘POST’) {
// Replace with your HubSpot Private App credentials
$clientId = ‘here_I_added_the_PrivateApp_AccessToken’;
$clientSecret = ‘here_I_added_the_PrivateApp_ClientSecret’;
$hubspotApiBaseUrl = ‘https://api.hubapi.com’;
// form data
$formData = $_POST;
// HubSpot CRM API endpoint for creating a contact
$endpoint = “/crm/v3/objects/contacts”;
// HubSpot CRM API URL
$url = $hubspotApiBaseUrl . $endpoint;
// HubSpot CRM API request headers
$headers = [
‘Content-Type: application/json’,
];
// HubSpot CRM API request data
$data = [
‘properties’ => [
[‘property’ => ‘firstname’,‘value’ => $formData[‘Full-Name’],],
[‘property’ => ‘company’,‘value’ => $formData[‘Company-Name’],],
[‘property’ => ‘email’,‘value’ => $formData[‘email’],]
]
];
// Initialize cURL session
$ch = curl_init($url);
// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, ‘POST’);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// Execute cURL session
$response = curl_exec($ch);
// Check for errors
if (curl_errno($ch)) {
echo 'Curl error: ’ . curl_error($ch);
}
// Close cURL session
curl_close($ch);
// Log response (for debugging)
file_put_contents(‘hubspot_response.log’, $response . PHP_EOL, FILE_APPEND | LOCK_EX);
} else {
http_response_code(405); // Method Not Allowed
echo ‘Method Not Allowed’;
}
?>
========END PHP Code=========================
And I am getting this error in the hubspot_response.log file:
{“status”:“error”,“message”:“Authentication credentials not found. This API supports OAuth 2.0 authentication and you can find more details at Accounts Dashboard | HubSpot”}