hs-form-submission
v1.0.1
Published
A simple Node.js wrapper for submitting forms to HubSpot using the [HubSpot Forms API](https://developers.hubspot.com/docs/api/marketing/forms).
Readme
hs-form-submission
A simple Node.js wrapper for submitting forms to HubSpot using the HubSpot Forms API.
This package makes it easy to submit form data to HubSpot from any backend using Node.js.
🚀 Installation
npm install hs-form-submission📦 Usage
JavaScript
const submitHubspotForm = require('hs-form-submission');
const portalId = 'YOUR_PORTAL_ID';
const formId = 'YOUR_FORM_ID';
const payload = {
fields: [
{ name: 'email', value: '[email protected]' },
{ name: 'firstname', value: 'John' }
],
context: {
pageUri: 'https://example.com/contact',
pageName: 'Contact Page'
}
};
submitHubspotForm(portalId, formId, payload)
.then(response => {
console.log('Form submitted successfully:', response);
})
.catch(error => {
console.error('Submission failed:', error.message);
});📤 Payload Format
fields: Required — An array of objects withnameandvalue- Example:
{ name: 'email', value: '[email protected]' }
- Example:
context: Optional — Additional metadatapageUri: The URI where the form was submitted frompageName: The name of the pagehutk: HubSpot tracking cookie, if available
📘 Example
const payload = {
fields: [
{ name: 'email', value: '[email protected]' },
{ name: 'firstname', value: 'Test' }
],
context: {
pageUri: 'https://your-site.com',
pageName: 'Landing Page',
hutk: '1234567890abcdef' // optional
}
};🔗 HubSpot Forms API Reference
More info here:
👉 https://developers.hubspot.com/docs/api/marketing/forms
🛠️ Contributing
Pull requests are welcome! For major changes, please open an issue first to discuss what you’d like to change.
