How to send form data to HubSpot using POST method

I’m working on a registration form and need help with posting the data to HubSpot. I have a working form but I want to add functionality to submit it directly to HubSpot’s API endpoint using POST request.

Here’s my current form structure:

@model CompanyPortal.Models.ViewModels.UserRegistrationViewModel
@using CompanyPortal.Models.ViewModels;

@using (Html.BeginForm("ProcessRegistration", "Registration", new { area = "CompanyPortal.Users" }, FormMethod.Post)) {
    <div class="container">
        <div class="col-md-12">
            <h2>@T("Sign up for free access")</h2>
            <p>@T("Complete the registration form below or ") <a href="/contact/support">@T("reach out to our team")</a>.</p>
            <p class="form-note"><i class="fa fa-asterisk text-danger"></i> Indicates required information</p>
        </div>
        
        <div class="form-group">
            <div class="input-wrapper">
                @Html.LabelFor(m => m.GivenName)
            </div>
            <div class="field-container">
                @Html.TextBoxFor(m => m.GivenName, new { @class = "form-control" })
                <i class="fa fa-asterisk text-danger" title="This field is required"></i>
            </div>
        </div>
        
        <div class="form-group">
            <div class="input-wrapper">
                @Html.LabelFor(m => m.FamilyName)
            </div>
            <div class="field-container">
                @Html.TextBoxFor(m => m.FamilyName, new { @class = "form-control" })
                <i class="fa fa-asterisk text-danger" title="This field is required"></i>
            </div>
        </div>
        
        <div class="form-actions">
            <div class="col-md-8">
                <input type="submit" name="submitBtn" value="@T("Submit")" class="btn btn-primary" />
            </div>
        </div>
    </div>
}

What’s the best approach to modify this so it posts to HubSpot’s form endpoint? Any suggestions would be helpful.

you gotta use hubspot’s forms api at https://api.hsforms.com/submissions/v3/integration/submit/portal-id/form-guid. just match your form fields with their names and set the content-type to application/json. oh and make sure to handle responses, just in case it errors.

I’ve done this integration before and hit some gotchas. First - grab your Portal ID from HubSpot settings and create a form there to get the form GUID. Bob’s endpoint is right, but handle the API call server-side instead of posting directly from the client. In your ProcessRegistration action, use HttpClient to send data to HubSpot’s API. Structure your payload with a fields array containing objects with ‘name’ and ‘value’ properties that match HubSpot’s field names (firstname, lastname, email, etc). Add proper error handling - HubSpot throws validation errors if field mapping is wrong. Also consider adding the hutk cookie value if you’re tracking visitors for better analytics.