Submit forms with GDPR options through API v3 using php

Highlighted
New Contributor

Hello. I'm trying to submit forms with GDPR options through API v3 using php. I use this code to submit my form

$data2 = array (
	'fields' =>
		array (
			0 =>
				array (
					'name' => 'email',
					'value' => 'example@example.com',
				),
		),
	'context' =>
		array (
			'hutk' => '6f453d92607b8108998dc213178ad214',
			'pageUri' => 'www.example.com/page',
			'pageName' => 'Example page',
		),
	'legalConsentOptions' =>
		array (
			'consent' =>
				array (
					'consentToProcess' => true,
					'text' => 'I agree to allow Example Company to store and process my personal data.',
					'communications' =>
						array (
							0 =>
								array (
									'value' => true,
									'subscriptionTypeId' => 999,
									'text' => 'I agree to receive marketing communications from Example Company.',
								),
						),
				),
		),
);

$dataEncoded = json_encode($data2);

$endpoint = 'https://api.hsforms.com/submissions/v3/integration/submit/' . $portalId . '/' . $currentFormId;

$ch = @curl_init();
@curl_setopt($ch, CURLOPT_POST, true);
@curl_setopt($ch, CURLOPT_POSTFIELDS, $dataEncoded);
@curl_setopt($ch, CURLOPT_URL, $endpoint);
@curl_setopt($ch, CURLOPT_HTTPHEADER, array(
	'Content-Type: application/json'
));

(https://gist.github.com/umkasanki/57bd8801f717cb94170cd42ec40f2c5f)

It's working good with "Consent checkboxes for communications and processing" option. (option 2 inGDPR dropdown)

option2.jpg

 

I receive the subission with 2 GDPR options

submission2.jpg

 

which is fully consistent with the result obtained from the native hubspot form. native-hs-form2.jpgCould somebody explain, how I should modify my code to use option 1 and option 3?

Option 1.

option1.jpg

 

Option3

option3.jpg

 

I tried to use these code

$data3 = array (
	'fields' =>
		array (
			0 =>
				array (
					'name' => 'email',
					'value' => 'example@example.com',
				),
		),
	'context' =>
		array (
			'hutk' => '6f453d92607b8108998dc213178ad214',
			'pageUri' => 'www.example.com/page',
			'pageName' => 'Example page',
		),
	'legalConsentOptions' =>
		array (
			'legitimateInterest' =>
				array (
					'value' => true,
					'subscriptionTypeId' => 999,
					'legalBasis' => 'LEAD',
					'text' => 'Legitimate interest consent text',
				),
		),
);

$dataEncoded = json_encode($data3);

$endpoint = 'https://api.hsforms.com/submissions/v3/integration/submit/' . $portalId . '/' . $currentFormId;

$ch = @curl_init();
@curl_setopt($ch, CURLOPT_POST, true);
@curl_setopt($ch, CURLOPT_POSTFIELDS, $dataEncoded);
@curl_setopt($ch, CURLOPT_URL, $endpoint);
@curl_setopt($ch, CURLOPT_HTTPHEADER, array(
	'Content-Type: application/json'
));

(https://gist.github.com/umkasanki/ee3bf87dcd7d73586ff829b20adeb76c) for option3, but result submission exists extra field

submission3-from-custom-form.jpg

 

which should not be present, if use native hubspot form for test...

Thanks.

Reply
0 Upvotes
6 Replies 6
Community Manager

Hi @OlegTishkin,

 

Thank you for the clear description of your use case. 

 

When looking to use GDPR Option 1, you would need to include the following code:

{
  "fields": [],
  "legalConsentOptions": {
    "legitimateInterest": {
      "value": true,
      // This must be true when using the 'legitimateInterest' option, as it reflects the consent indicated by the visitor when submitting the form
      "subscriptionTypeId": 999,
      // Integer; The ID of the specific subscription type that this forms indicates interest to.
      "legalBasis": "CUSTOMER",
      // String, one of CUSTOMER or LEAD; Whether this form indicates legitimate interest from a prospect/lead or from a client.
      "text": "Legitimate interest consent text"
      // String; The privacy text displayed to the visitor.
    }
  }
}
=

For GDPR Option 3, you do not have to pass any data into HubSpot using the form API but you're required to add the privacy text on the form. An example of the privacy text:

 

APAC Support needs the contact information you provide to us to contact you about our products and services. You may unsubscribe from these communications at any time. For information on how to unsubscribe, as well as our privacy practices and commitment to protecting your privacy, please review our Privacy Policy.
Reply
0 Upvotes
New Contributor

Hello Wendy, Thank you for answer.

We have 3 GDPR options

image.png

 

I tried using the example you provided  in my custom form to send data to a form with option 1.

$data2 = array (
	'fields' => $fields,
	'context' => $hsContext,
	'legalConsentOptions' =>
		array (
			'legitimateInterest' =>
				array (
					'value' => true,
					'subscriptionTypeId' => 7168164,
					'legalBasis' => 'CUSTOMER',
					'text' => 'Custom text'
				),
		),
);

As a result I have got a contact:

image.png

For testing I tried native Hubspot form with same settings (option1) and I have got different reault:

image.png

 

How I can fix this error?

 

Thanks for help!

Reply
0 Upvotes
Community Manager

Hi @OlegTishkin,

 

Pardon for the confusion. 

 

For GDPR Option 1, you can use the following code:

      "legalConsentOptions":{ // Include this object when GDPR options are enabled
        "consent":{
          "consentToProcess":true,
          "text":"I agree to allow Example Company to store and process my personal data.",
          "communications":[
            {
              "value":true,
              "subscriptionTypeId":{{subscriptionId}},
              "text":"I agree to receive marketing communications from Example Company."
            }
          ]
        }
      }

The contact record would reflect 'Freely given consent from contact' when using this.

Reply
0 Upvotes
New Contributor

Sorry, but I'm bit confused. Which code I should use for option 2 in this case? 

Reply
0 Upvotes
Community Manager

Hi @OlegTishkin,

 

Pardon for the confusion earlier on. 

 

For both GDPR option 1 and 2, the code that you would use is the following:

      "legalConsentOptions":{ // Include this object when GDPR options are enabled
        "consent":{
          "consentToProcess":true,
          "text":"I agree to allow Example Company to store and process my personal data.",
          "communications":[
            {
              "value":true,
              "subscriptionTypeId":{{subscriptionId}},
              "text":"I agree to receive marketing communications from Example Company."
            }
          ]
        }

For option 3, the code that you would use is the following:

                 "legalConsentOptions": {
    "legitimateInterest": {
      "value": true,
      // This must be true when using the 'legitimateInterest' option, as it reflects the consent indicated by the visitor when submitting the form
      "subscriptionTypeId": {{subscriptionId}},
      // Integer; The ID of the specific subscription type that this forms indicates interest to.
      "legalBasis": "CUSTOMER",
      // String, one of CUSTOMER or LEAD; Whether this form indicates legitimate interest from a prospect/lead or from a client.
      "text": "Legitimate interest consent text"
      // String; The privacy text displayed to the visitor.
    }
  }

 

Hope this helps to shed some lights!

Reply
0 Upvotes
New Contributor

Thanks.

.and in what way can I change the value of "Legal basis for processing contact's data" for GDPR Option 1?

 

Аннотация 2019-11-13 103143.jpg

Reply
0 Upvotes