Skip to content

Instantly share code, notes, and snippets.

@HubSpotHanevold
Created April 16, 2025 16:33
Show Gist options
  • Save HubSpotHanevold/0bfe78917370f28278bcb16b5acd500f to your computer and use it in GitHub Desktop.
Save HubSpotHanevold/0bfe78917370f28278bcb16b5acd500f to your computer and use it in GitHub Desktop.
Sample PHP Curl Forms Submit API
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.hsforms.com/submissions/v3/integration/submit/portalId/formGuid',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'Example JSON body: {
"submittedAt": "1517927174000",
"fields": [
{
"objectTypeId": "0-1",
"name": "email",
"value": "[email protected]"
},
{
"objectTypeId": "0-1",
"name": "firstname",
"value": "Jeff"
}
],
"context": {
"hutk": ":hutk",
"pageUri": "www.example.com/page",
"pageName": "Example page"
},
"legalConsentOptions": {
"consent": {
"consentToProcess": true,
"text": "I agree to allow Example Company to store and process my personal data.",
"communications": [
{
"value": true,
"subscriptionTypeId": 999,
"text": "I agree to receive marketing communications from Example Company."
}
]
}
}
}
{
"fields": [...
],
"legalConsentOptions": {
"consent": {
"consentToProcess": true,
"text": "Text that gives consent to process",
"communications": [
{
"value": true,
"subscriptionTypeId": 999,
"text": "Consent to communicate text for subscription type ID 999"
},
{
"value": true,
"subscriptionTypeId": 777,
"text": "Consent to communicate text for subscription type ID 777"
}
]
}
}
}
{
"fields": [],
"legalConsentOptions": {
"legitimateInterest": {
"value": true,
"subscriptionTypeId": 999,
"legalBasis": "CUSTOMER",
"text": "Legitimate interest consent text"
}
}
}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment