Forms API submit issue


#1

I’ve trying to send the post to the forms action to subscribe to a form I have. This form only takes an email, but when I check the submissions in the forms dashboard , all request show as “No Contact”.
This is the request im sending to the server
Im getting the hutk from the cookie named “hubspotutk”

“{“email”:“luis@email.co”,
“hs_context”:{
“hutk”:“d811744cf45d676710490167xxxxaxxc”,
“ipAddress”:”",
“pageUrl”:“http://localhost:3000/#”,
“pageName”:“Newsletter footer”
}
}"

and this request is sent as a Post to this url

this.http
.post(‘https://forms.hubspot.com/uploads/form/v2/450637/28e6eaa5-dde6-4f81-a498-11986870xxxx’, JSON.stringify({ postData }), { headers })
.map(res => {
console.log(res);
return res
})

Im also appending the required header of content-type and length.

headers.append(‘Content-Type’, ‘application/x-www-form-urlencoded’);

Any ideas why this request shows a submission of “No Contact”

Note: hubstop cookie with “x’s” at the end to not show the entire id there

Thanks


#2

Hi @luisfoundation

The value of the hs_context field will need to be stringified, but the data itself needs to be passed as form encoded data, and not JSON.

email=luis@email.co&hs_context=%7B%22hutk%22%3A%22d811744cf45d676710490167xxxxaxxc%22%2C%22ipAddress%22%3A%22%22%2C%22pageUrl%22%3A%22http%3A%2F%2Flocalhost%3A3000%2F%23%22%2C%22pageName%22%3A%22Newsletter%20footer%22%7D


#3

@dadams
I tried encoding and still getting no contact on the submissions. This are the steps im following

Stringify the body data which turns into this :

“{“email”:“luis@email.co”,“hs_context”:{“hutk”:“d811744cf45d676710490167d249a70c”,“ipAddress”:”",“pageUrl”:“http://localhost:3000/#/",“pageName”:"Footer newsletter”}}"

Then im encoding that result with encodeURIComponent which return this :

“%7B%22email%22%3A%22luis%40email.co%22%2C%22hs_context%22%3A%7B%22hutk%22%3A%22d811744cf45d676710490167d249a70c%22%2C%22ipAddress%22%3A%22%22%2C%22pageUrl%22%3A%22http%3A%2F%2Flocalhost%3A3000%2F%23%2F%22%2C%22pageName%22%3A%22Footer%20newsletter%22%7D%7D”

Is there anything wrong with the encoding or should I encode each of the values individually ?

Thanks


#4

The format of the data needs to be form-encoded, not JSON, and each value would need to be encoded separately. The general format would need to be:

field1=x&field2=y

Only the value of the hs_context field would be stringified JSON, that also needs to be URL encoded:

hs_context=%7B%22hutk%22%3A%22d811744cf45d676710490167xxxxaxxc%22%2C%22ipAddress%22%3A%22%22%2C%22pageUrl%22%3A%22http%3A%2F%2Flocalhost%3A3000%2F%23%22%2C%22pageName%22%3A%22Newsletter%20footer%22%7D


#5

@dadams

Thanks it seems to work now