Most tutorials for sending an HTML form to HubSpot tell you to open Integrations → Private Apps and generate an access token. HubSpot stopped allowing new legacy private apps in October 2026, so those steps hit a dead end on new setups.
Current HubSpot accounts use a Service Key instead, and the form still cannot call HubSpot's API from the browser. This guide builds it two ways: a small Cloudflare Worker that upserts contacts by email, and a form backend that maps your contact properties and keeps spam out of your CRM.
Why the browser can't call HubSpot directly
HubSpot's CRM API authenticates with a bearer token (a Service Key or an older private app token). Anything in your page's JavaScript is public, so putting that token in browser code lets anyone create or overwrite contacts in your CRM, and read records if the key has read scopes. HubSpot's API also does not return CORS headers for cross-origin browser requests.
So your form posts to a server you control, and only that server holds the key.
Option A: a Cloudflare Worker
Create a HubSpot Service Key
You need Super Admin or Developer Tools access in HubSpot:
- In HubSpot, open Development → Keys → Service keys (also under Settings → Integrations → Service Keys)
- Click Create service key and name it (for example,
website-contact-form) - Add the
crm.objects.contacts.writescope - Copy the key right away (HubSpot hides it after creation)
If you already created a legacy private app before October 2026 with crm.objects.contacts.write, its access token uses the same Bearer header and still works.
Create a contact or update it by email
The Worker first tries POST /crm/v3/objects/contacts. If HubSpot returns 409 Conflict because the email already exists, it updates that contact with PATCH /crm/v3/objects/contacts/{email}?idProperty=email.
The update sends only the fields the visitor filled in, so blank fields leave existing values alone. HubSpot requires a custom unique property for partial updates through its batch upsert endpoint. HubSpot contacts API
The Worker
// Form field name → HubSpot internal contact property name
const PROPERTIES = {
firstname: "firstname",
lastname: "lastname",
company: "company",
message: "message",
};
const ALLOWED_ORIGIN = "https://example.com";
const CONTACTS_URL = "https://api.hubapi.com/crm/v3/objects/contacts";
export default {
async fetch(request, env) {
const headers = { "Access-Control-Allow-Origin": ALLOWED_ORIGIN };
if (request.method !== "POST") return new Response("Method not allowed", { status: 405 });
const form = await request.formData();
// Honeypot filled in: answer OK so the bot learns nothing.
if (form.get("_gotcha")) return Response.json({ ok: true }, { headers });
const email = String(form.get("email") ?? "").trim().toLowerCase();
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
return Response.json({ ok: false }, { status: 400, headers });
}
const properties = {};
for (const [field, prop] of Object.entries(PROPERTIES)) {
const value = String(form.get(field) ?? "").trim().slice(0, 5000);
if (value) properties[prop] = value;
}
const hubspotHeaders = {
Authorization: `Bearer ${env.HUBSPOT_TOKEN}`,
"Content-Type": "application/json",
};
let res = await fetch(CONTACTS_URL, {
method: "POST",
headers: hubspotHeaders,
body: JSON.stringify({ properties: { email, ...properties } }),
});
if (res.status === 409) {
if (Object.keys(properties).length === 0) return Response.json({ ok: true }, { headers });
res = await fetch(`${CONTACTS_URL}/${encodeURIComponent(email)}?idProperty=email`, {
method: "PATCH",
headers: hubspotHeaders,
body: JSON.stringify({ properties }),
});
}
if (!res.ok) {
console.error("HubSpot error", res.status, await res.text());
return Response.json({ ok: false }, { status: 502, headers });
}
return Response.json({ ok: true }, { headers });
},
};
Change ALLOWED_ORIGIN to your site, deploy the Worker, and store the Service Key as a secret so it never lives in your code:
npx wrangler deploy
npx wrangler secret put HUBSPOT_TOKEN
The form
The Worker returns JSON, so submit with fetch() and replace the form with a confirmation message. Posting FormData avoids a CORS preflight request.
<form id="contact">
<input name="firstname" placeholder="First name" required>
<input name="lastname" placeholder="Last name">
<input name="email" type="email" placeholder="Email" required>
<input name="company" placeholder="Company">
<textarea name="message" placeholder="Message" required></textarea>
<!-- Honeypot: hidden from people, bots fill it in -->
<div aria-hidden="true" style="position:absolute; left:-9999px">
<input type="text" name="_gotcha" tabindex="-1" autocomplete="off">
</div>
<button type="submit">Send</button>
<p id="status" role="status"></p>
</form>
<script>
const form = document.getElementById("contact");
const status = document.getElementById("status");
form.addEventListener("submit", async (event) => {
event.preventDefault();
status.textContent = "";
try {
const res = await fetch("https://your-worker.your-subdomain.workers.dev", {
method: "POST",
body: new FormData(form),
});
if (res.ok) {
form.replaceWith("Thanks, we got your message.");
return;
}
} catch {}
status.textContent = "Something went wrong. Please try again.";
});
</script>
Submit it once and the contact should appear in HubSpot under CRM → Contacts. Submit it a second time with the same email and the existing contact updates instead of failing.
Where it breaks
-
Internal names and option values. HubSpot properties use internal names (
firstname,jobtitle), not labels ("First name"). Dropdown and multi-checkbox properties require internal option values (with multiple checkboxes joined by;), or HubSpot rejects the record. -
207 multi-status responses. If you switch to
batch/upsert, a207response can contain failed records even whenres.okis true.numErrorsis the count anderrorshas the details. -
Overwritten messages. Upserting updates the contact's properties, so a second submission from the same person overwrites
messageunless you store submissions separately too. -
Rate limits. HubSpot enforces per-10-second burst limits and returns
429under traffic spikes. The Worker does not retry, so bursts drop leads. - No second copy. If HubSpot is down or refuses a custom property, the Worker logs the status and the submission is gone.
- Spam contacts in your CRM. A honeypot stops simple bots, not written sales pitches. Every spam submission creates a real contact in HubSpot, skewing lead counts and firing any contact-created workflows.
For a small personal site, the Worker is plenty. Past that, most of the work is keeping spam out of your CRM and retrying failed API calls.
Option B: a form backend that maps the properties
With Formkove, the form posts to a Formkove endpoint. Each submission is saved in your dashboard, checked for spam, emailed to you and upserted as a HubSpot contact matched by email.
Point the form at Formkove. Create a form at app.formkove.com and use its endpoint as the action. No Worker and no JavaScript required, and the _gotcha honeypot is on by default.
<form action="https://app.formkove.com/api/forms/YOUR_FORM_ID/submissions" method="POST">
Connect HubSpot. Create a HubSpot Service Key under Development → Keys → Service keys with crm.objects.contacts.write and crm.schemas.contacts.read (existing private app tokens with those scopes work too). In your form's Integrations, click Connect HubSpot and paste the key. It is stored encrypted and never shown again.
Map the properties. Formkove reads your HubSpot contact properties and lists the writable ones, putting common fields like email, firstname, lastname, phone, company and message first. Email is required (saved in lowercase); for every other property you pick a form field, a Formkove value (Submitted at, Submission ID, Form name, Sentiment, Tags, Spam score, File links) or a fixed text. Comma-separated values for multi-checkbox properties are formatted for HubSpot automatically, and Send test verifies the key can reach your contacts without adding a fake record.
Send only qualified leads to HubSpot. Define tags in plain words on the form's AI & Spam page (for example, sales-lead: asks for pricing, a quote or a demo), then add a routing rule to the HubSpot connection:
-
Tag has any of
sales-lead
Now support questions and vendor pitches still reach your email and dashboard without creating HubSpot contacts. Rules can also check any form field, such as budget is greater than 5000. Email is not routed, so you still get every real submission in your inbox.
What comes with it:
- Spam held back before it reaches HubSpot, so bots and cold pitches do not become CRM contacts. Held spam stays in your dashboard for 30 days in case a real message needs releasing.
- Every submission saved in Formkove's dashboard, including full messages when someone submits again with the same email. Failed HubSpot deliveries are retried automatically and shown in Delivery history with the reason.
- Rate limits on every form: 10 a minute and 30 an hour per IP address.
HubSpot, tags and routing are on the Pro and Agency plans, and Free accounts get them on their first 50 submissions (pricing). Setup details and troubleshooting are in the HubSpot docs.
Originally published on formkove.com.
Top comments (0)