Hi,
I’ve created a form in Hubspot and I’m trying to push form data to Hubspot form API using PHP CURL but I’m getting JSON error.
{“status”:“error”,“message”:“Invalid input JSON on line 1, column 1: Cannot construct instance of `com.hubspot.formsubmission.core.models.PublicApiFormSubmissionRequest$Json` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value (‘{\“fields\”:[{\“name\”:\“email\”,\“value\”:\“example@example.com\”},{\“name\”:\“firstname\”,\“value\”:\“GS\”},{\“name\”:\“lastname\”,\“value\”:\“Test\”},{\“name\”:\“company\”,\“value\”:\“GS Test Co\”},{\“name\”:\“phone\”,\“value\”:\“44123456789\”}]}’)”,“correlationId”:“78010c5b-dc3f-45ba-a93e-9c3ab5da3622”}
I’ve tried posting using Hubspot’s example JSON data but that displays the same error. Also different configurations of quotes/apostrophes. I’m assuming $data is incorrectly set up but I’ve run out of options.
This is the code I’m using:
<?php
$url = 'https://api.hsforms.com/submissions/v3/integration/submit/[MyPortalID]/[TheFormGUID]';
$data = '{"fields":[{"name":"email","value":"example@example.com"},{"name":"firstname","value":"GS"},{"name":"lastname","value":"Test"},{"name":"company","value":"GS Test Co"},{"name":"phone","value":"44123456789"}]}';
$postdata = json_encode($data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$result = curl_exec($ch);
curl_close($ch);
print_r ($result);
?>
I hope you can help.
Many thanks