APIs & Integrations

nazlobudnya
Member

v3 Form submit returns Bad Request

Good time of the day. I'm currently using the test account for future integration with HubSpot.
I'm trying to submit v3 Form using hubspot-php lib and provided guidelines on how to construct the json for the request.

PHP

 $hubspot = Factory::create(config('integration-hubspot.key'));

        $formBody = [
            'fields' => [
                [
                    'name' => 'email',
                    'value' => $user['email']
                ],
                [
                    'name' => 'firstname',
                    'value' => $person['first_name']
                ],
                [
                    'name' => 'lastname',
                    'value' => $person['last_name']
                ],
                [
                    'name' => 'phone',
                    'value' => $person['mobile_phone']
                ],
                [
                    'name' => 'company',
                    'value' => $entity['name']
                ]
            ],
            'legalConsentOptions' => (object)[
                'consent' => true,
                'text' => 'I agree to allow Example Company to store and process my personal data.',
                'communications' => [
                    (object)[
                        'value' => true,
                        'subscriptionTypeId' => 999,
                        'text' => 'I agree to receive marketing communications from Example Company.'
                    ]
                ]
            ]

        ];

        $hubspot->forms()->submit(7663747, 'redacted', $formBody);

Json constructed by Guzzle 

{"fields":[{"name":"email","value":"test@email.cc"},{"name":"firstname","value":"Don"},{"name":"lastname","value":"Joe"},{"name":"phone","value":"555-1232"},{"name":"company","value":"MyCompanyName"}],"legalConsentOptions":{"consent":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."}]}}


I tried with and without optional parameters but I keep getting 400 Bad Request

Edit 1: the hapikey is present and is appended to the request. 

0 Upvotes
1 Reply 1
WendyGoh
HubSpot Employee
HubSpot Employee

v3 Form submit returns Bad Request

Hey @nazlobudnya,

 

This is a public forum, so you should refrain from posting any sensitive data, particularly authorization keys (e.g. API keys, OAuth tokens, etc.). I've removed your hapikey from the post, but I would strongly recommend deactivating it and generating a new one since it was visible on the forums for a while.

 

In this case, the HubSpot Forms API doesn't require any form of authentication. As such, could you try remove the authentication and try POSTing the form submission and see if it works?

0 Upvotes