hubspot-php form submit responds: "The request is not valid"

After updating hubspot-php library the form-submit function does not work anymore.

Response:

Client error: `POST https://forms.hubspot.com/submissions/v3/integration/submit/.../...` resulted in a `400 Bad Request` response:
{"status":"error","message":"The request is not valid","correlationId":"4768e363-cc2f-469f-b935-bf70023d5cfd","errors":[ (truncated...)

code that was used before update and worked:

$hubspot->forms()->submit($this->hubspot_portal, $this->hubspot_form, [ 'hs_context' => json_encode([ 'hutk' => @$_COOKIE['hubspotutk'], 'ipAddress' => $_SERVER['REMOTE_ADDR'], 'pageUrl' => ($_SERVER['HTTP_REFERER'] ? $_SERVER['HTTP_REFERER'] : ($_SERVER['HTTPS'] ? 'https' : 'http') . '://' . $_SERVER['SERVER_NAME'] . '/register'), 'pageName' => 'Register' ]), "email" => $user->email, "firstname" => $user->name, "lastname" => $user->surname, "jobtitle" => $user->position, "company" => $customer->name, "company_type" => strtoupper($type ? $type->name : ''), "phone" => $user->phone, "source" => ($user->registered_by ? "Inbound" : "Outbound"), "utm_campaign" => $user->campaign, "utm_source" => $user->source, "utm_medium" => $user->medium]);

also tried this format of data instead:

$data = [ "fields" => [ ["name" => "email", "value" => "abc@xyz.com"], ["name" => "hs_context", "value" => ""], ["name" => "firstname", "value" => ""], ["name" => "lastname", "value" => ""], ["name" => "jobtitle", "value" => ""], ["name" => "company", "value" => ""], ["name" => "company_type", "value" => ""], ["name" => "phone", "value" => ""], ["name" => "source", "value" => ""], ["name" => "utm_campaign", "value" => ""], ["name" => "utm_source", "value" => ""], ["name" => "utm_medium", "value" => ""], ]];

Do you have any clue how to fix this?

There is no working documentation or detailed error message - just “the request is not valid”

Hey @philx,

Looking at the form POST request URL, I noticed that it is different from the POST request url documented here: Submit data for a form | Forms API.

The supported Form POST request url should look something like this:

POST https://api.hsforms.com/submissions/v3/integration/submit/:portalId/:formGuid

Could you change the request url to match the documented request url and see if it works?

changed it but still getting the same response

resolved: after managing to get a look at a detailed error message it turned out that the required data structure changed (2nd one in original posting), some fields are validated stricter (required / no empty values) and email validation needed to be deactivated by a skip parameter