# Hubspot form Invalid input JSON using Hubspot example JSON

**URL:** <https://community.hubspot.com/t/hubspot-form-invalid-input-json-using-hubspot-example-json/37580>\
**Category:** APIs & Integrations\
**Tags:** forms, starter\
**Created:** [May 19, 2021, 11:08am UTC](https://community.hubspot.com/t/hubspot-form-invalid-input-json-using-hubspot-example-json/37580 "2021-05-19T11:08:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Reseaux](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/reseaux/32/25270_2.png) [@Reseaux](https://community.hubspot.com/u/Reseaux)\
**Post date:** [May 19, 2021, 11:08am UTC](https://community.hubspot.com/t/hubspot-form-invalid-input-json-using-hubspot-example-json/37580/1 "2021-05-19T11:08:21Z")

</div>

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](mailto: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:

```lia-code-sample
<?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

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [May 19, 2021, 8:10pm UTC](https://community.hubspot.com/t/hubspot-form-invalid-input-json-using-hubspot-example-json/37580/2 "2021-05-19T20:10:26Z")

</div>

[@webdew](https://community.hubspot.com/t5/user/viewprofilepage/user-id/131510) , @prosa are you all seeing anything amiss?

---

<div class="post-metadata">

**Author:** ![MichaelC](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/michaelc/32/9055_2.png) [@MichaelC](https://community.hubspot.com/u/MichaelC)\
**Post date:** [May 20, 2021, 7:23am UTC](https://community.hubspot.com/t/hubspot-form-invalid-input-json-using-hubspot-example-json/37580/3 "2021-05-20T07:23:06Z")

</div>

@Reseaux

It looks like you are encoding json - (make php to json) instead of decoding json (from json to php).

Your $data string is already setup in json format and should not be converted to json from json.

I have used this function I found online to help med convert json to a php object.

`function json_to_php($data) {if (is_object($data)) {$data = get_object_vars($data);}if (is_array($data)) {return array_map( __FUNCTION__ , $data);}else {return $data;}}`

Then I used Guzzle PHP to do my calls - but guzzle is based on CURL so mixing it up some how should make it work for you.

I might have done this more messy than it needs to be - but it works.

```lia-code-sample
$json_content = json_to_php( array(json_decode($json_content))); 
$client = new \GuzzleHttp\Client(['http_errors' => false]);
$response = $client->request($method, $url, $json_content[0]);
$encrypted = $response->getBody();
$result = json_decode($encrypted, true);

```

But I think the issue in your case is your encoding.

Michael

---

<div class="post-metadata">

**Author:** ![Reseaux](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/reseaux/32/25270_2.png) [@Reseaux](https://community.hubspot.com/u/Reseaux)\
**Post date:** [May 20, 2021, 10:23pm UTC](https://community.hubspot.com/t/hubspot-form-invalid-input-json-using-hubspot-example-json/37580/4 "2021-05-20T22:23:05Z")

</div>

Thanks Michael - much appreciated - will give that a go.

---

<div class="post-metadata">

**Author:** ![Reseaux](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/reseaux/32/25270_2.png) [@Reseaux](https://community.hubspot.com/u/Reseaux)\
**Post date:** [May 21, 2021, 11:36am UTC](https://community.hubspot.com/t/hubspot-form-invalid-input-json-using-hubspot-example-json/37580/5 "2021-05-21T11:36:45Z")

</div>

Hi Michael,

As you correctly pointed out my $data variable was already encoded so there was no need to re-encode it using json\_encode($data).

I’m not familiar with Guzzle but by simply running my original code and changing the following it worked perfectly:

$postdata = json\_encode($data);

to

$postdata = $data;

or more streamlined:

// $postdata = json\_encode($data);  
// $postdata = $data;  
curl\_setopt($ch, CURLOPT\_POSTFIELDS, $data);

I hope this helps out fellow newbies!

Many thanks,  
Greg
