APIs & Integrations

spaceshade
Member

Forms API not linking data to Form fields

Hi,

I am submitting a form via the API, but when I submit the data, the form fields are no longer linking up. After April 2nd (this could not mean a thing, but the date I noticed of last successful post), I am getting a new response in the "view submission" area of the form.

Here is my API response.
I am using node.js & axios as the http client.

axios({
method: 'POST',
url: https://forms.hubspot.com/uploads/form/v2/${accountId}/${formVersion},
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
params: JSON.stringify({
email: data.email,
firstname: data.firstName,
lastname: data.lastName,
company: data.company,
state: data.state,
city: data.city,
phone: data.phone,
inquiry: data.inquiry,
hs_context: data.hsContext,
}),
})

When I view the submission, the data is sent and Hubspot receives the request, but it now looks like this.

Here is a response in prod where I am also adding the required hs_context values.

{"firstName":"dev","lastName":"","email":"dev-test-email@dev-test.com","company":"","state":"","city":"","phone":"","inquiry":"Hi! My company or team would love some help moving to the cloud!","hsContext":{"hutk":"42b9...187939e","pageName":"page title","pageUrl":"https://domain.com/"},"env":"production"}

When it used to look like this.

This issue happened when we deployed it out, with the Hubspot tracking cookie enabled, as the cookie is only added on production. The issue I saw was that the tracking cookie was also submitting the form, which had a value of "SCRAPED". I have since went into the form and disabled Cookie tracking but turning this on/off doesn't have any change besides duplicate submitting of the form. I am not sure why the field values are not being linked anymore.

Any help or paths that I am missing would be extremely grateful.

0 Upvotes
3 Replies 3
spaceshade
Member

Forms API not linking data to Form fields

The issue I am seeing now, is that the hs_context values are not registering page information.

Is there anything in particular needed to make these values line up, or does this mean they are linked?

The icon displays:
This value wasn't passed to the contact record. 'hs_context_pageurl_' isn't a contact property

0 Upvotes
spaceshade
Member

Forms API not linking data to Form fields

Hi @Robert_Ainslie I appreciate the help, it ended up being a bug in axios.

For future googlers. Solution is here: https://github.com/axios/axios/issues/362#issuecomment-335072651

0 Upvotes
robertainslie
HubSpot Employee
HubSpot Employee

Forms API not linking data to Form fields

@spaceshade - The HubSpot Forms API is expecting a URL encoded body, not JSON. I'd recommend checking if axios has a way to pass this url encoded data

You can see this expectation in the docs: https://developers.hubspot.com/docs/methods/forms/submit_form - an example body is:
firstname=TestContact&lastname=FormSub&email=formsub@hubspot.com&newcustomproperty=testing&hs_context=%7B%22hutk%22%3A%2260c2ccdfe4892f0fa0593940b12c11aa%22%2C%22ipAddress%22%3A%22192.168.1.12%22%2C%22pageUrl%22%3A%22http%3A%2F%2Fdemo.hubapi.com%2Fcontact%2F%22%2C%22pageName%22%3A%22Contact%2BUs%22%2C%22redirectUrl%22%3A%22http%3A%2F%2Fdemo.hubapi.com%2Fthank-you%2F%22%7D

0 Upvotes