400 error when submit form with an empty hutk

Hi!

I need submit data to a form.

I get the value hutk from cookies.

Sometimes this value is not included in cookies.
If the request comes with an empty hutk, then we get a 400 error.
The documentation says that the hutk value is optional, but without it, the request does not pass.

I will be grateful for help.

Where is my code:

hutk = document.cookie.replace(
 /(?:(?:^|.*;\s*)hubspotutk\s*\=\s*([^;]*).*$)|^.*$/,
 "$1"
 );

var data = {
 fields: [
 {
 name: "firstname",
 value: firstname,
 },
 {
 name: "email",
 value: email,
 },
 {
 name: "phone",
 value: phone,
 }
 ],
 context: {
 hutk: hutk,
 pageUri: pageUri,
 pageName: page_name,
 ipAddress: ipAddress,
 },
 };

data = JSON.stringify(data);

$.ajax({
 contentType: "application/json",
 type: "POST",
 url:
 "https://api.hsforms.com/submissions/v3/integration/submit/9334399/" +
 hubspot_form_id,
 data: data,
});

@leshapol ,

I would not include it at all in your json body if there is no value for it.

It works. Thanks a lot!