Posting form data to hubspot

Hi,

We need to post our contact form to hubspot and so have created a database collection and hooked it up to our form. We are then using the afterInsert hook to post the data. The issue we have is that we need to post the data as form fields but we not sure how to in the Wix code.

We currently have this:

import { fetch } from ‘wix-fetch’;
import wixData from ‘wix-data’;

export function ContactFormsv2_afterInsert(item, context) {
fetch(‘myhubspot_url’, {
method: ‘POST’,
body: {“email”:item.email,“firstname”:item.firstName,“lastname”:item.lastName},
})
.catch((err) => {
console.log("Error: ");
console.log(err);
});
return item;
}

It hits our hubspot form but i think the body data in in JSON format which hubspot doesn’t accept. So we thought about using the JS FormData() functions like this:

var data = new FormData();
data.append(“email”, “my@emailaddress.com”);

and use data as the body content above. But FormData() isn’t recognised in the Wix Code editor.

Can anyone suggest how we can post the data as form fields to hubspot?

Many thanks!

Hey Dan,

You might want to start here to get information from a specific Dataset:
Then reading here to insert data into the Collections:

Hope that leads you to the solution you want.

GoodLuck.

Mustafa