How to switch form data submission from InfusionSoft to HubSpot integration

I’m working on a web application using Orchar CMS and I need some help with changing how my forms work. Right now I have a contact form that sends data to InfusionSoft but I need to change it so it sends everything to HubSpot instead.

I’ve been looking through the HubSpot API docs but I can’t find clear examples of how to do this. Does anyone have experience with this kind of migration or know where I can find good examples?

Here’s what my current form model looks like:

public class TrialRegistrationHubspotModel {

    [StringLength(40), Required, Display(Name = "Given Name")]
    public string GivenName { get; set; }

    [StringLength(40), Required, Display(Name = "Family Name")]
    public string FamilyName { get; set; }

    [StringLength(40), Required, Display(Name = "Position")]
    public string Position { get; set; }

    [Display(Name = "hub_option_reports")]
    public bool Regional_Reports { get; set; }

    [Display(Name = "hub_option_analytics")]
    public bool Market_Analytics { get; set; }
}

And here’s part of my controller that processes the form data:

[HttpPost, Themed]
public ActionResult ProcessRegistration(TrialRegistrationModel userModel) {    
    //Prepare form data for submission
    NameValueCollection submissionData = new NameValueCollection();
    submissionData["inf_xid"] = formXid;
    submissionData["inf_name"] = formName;
    submissionData["inf_version"] = versionNumber;
}

Any help would be great!

The Problem:

You’re migrating a contact form from InfusionSoft to HubSpot and need help adapting your code. Your current code uses InfusionSoft’s form submission method, and you need to update it to integrate with HubSpot’s API. You’ve provided your existing TrialRegistrationHubspotModel and parts of your controller that process form data, which currently send data to InfusionSoft.

:thinking: Understanding the “Why” (The Root Cause):

InfusionSoft and HubSpot utilize different methods for form submission. InfusionSoft often employs a simpler, often form-based approach, while HubSpot leverages its REST API for more robust and flexible data management. Directly translating your existing code won’t work because HubSpot requires a different data structure, authentication mechanism, and HTTP request format.

:gear: Step-by-Step Guide:

  1. Create a HubSpot Form and Obtain Credentials:

    • First, create the equivalent form in your HubSpot account. This will define the fields for your data. Note the field names – HubSpot uses internal names, different from what you might display to the user.
    • Obtain your HubSpot API key or set up OAuth 2.0 for authentication. OAuth 2.0 is the recommended approach for improved security. Find this information in your HubSpot developer settings. This replaces your previous inf_xid authentication method.
  2. Update Your Model:

    • Modify your TrialRegistrationHubspotModel to match HubSpot’s expected field names. For example, GivenName should likely become firstName, FamilyName should become lastName, etc. Refer to HubSpot’s API documentation for exact field names. Add [JsonPropertyName] attributes to align your C# properties with HubSpot’s field names:
    using System.ComponentModel.DataAnnotations;
    using System.Text.Json.Serialization;
    
    public class TrialRegistrationHubspotModel {
    
        [StringLength(40), Required, Display(Name = "Given Name"), JsonPropertyName("firstName")]
        public string GivenName { get; set; }
    
        [StringLength(40), Required, Display(Name = "Family Name"), JsonPropertyName("lastName")]
        public string FamilyName { get; set; }
    
        [StringLength(40), Required, Display(Name = "Position"), JsonPropertyName("position")]
        public string Position { get; set; }
    
        [Display(Name = "hub_option_reports"), JsonPropertyName("regionalReports")]
        public bool Regional_Reports { get; set; }
    
        [Display(Name = "hub_option_analytics"), JsonPropertyName("marketAnalytics")]
        public bool Market_Analytics { get; set; }
    }
    
  3. Implement the HubSpot API Call:

    • Replace your existing ProcessRegistration controller action with code that uses an HTTP client (like HttpClient in .NET) to send a POST request to the HubSpot Forms API ( api.hsforms.com or a similar endpoint; check HubSpot’s documentation for the most up-to-date endpoint). The request body should be a JSON representation of your TrialRegistrationHubspotModel. Be sure to include the correct HTTP headers, notably Content-Type: application/json and your authorization token (obtained in Step 1).
    [HttpPost, Themed]
    public async Task<ActionResult> ProcessRegistration(TrialRegistrationHubspotModel userModel)
    {
        using var client = new HttpClient();
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "YOUR_HUBSPOT_ACCESS_TOKEN");
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
    
        var json = JsonSerializer.Serialize(userModel);
        var content = new StringContent(json, Encoding.UTF8, "application/json");
    
        var response = await client.PostAsync("YOUR_HUBSPOT_FORMS_API_ENDPOINT", content); //Replace with actual endpoint
    
        if (response.IsSuccessStatusCode)
        {
            // Form submission successful
            return RedirectToAction("Success");
        }
        else
        {
            // Handle errors (log the response, display a user-friendly message, etc.)
            return View("Error"); // Or appropriate error handling
        }
    }
    
  4. Handle Asynchronous Responses:

    • Remember that HubSpot’s API responses are asynchronous, unlike InfusionSoft’s synchronous posting. Your code must handle the asynchronous nature of the API call using async and await.

:mag: Common Pitfalls & What to Check Next:

  • HubSpot Field Mapping: Double-check the exact names of your fields in HubSpot against the properties in your C# model. Even small discrepancies will cause submission failures.
  • HTTP Headers: Ensure your HTTP headers are precisely formatted, including the Content-Type and the correct authorization token.
  • Error Handling: Implement comprehensive error handling to catch potential problems (network issues, invalid data, API rate limits, etc.) and provide informative error messages to the user.
  • HubSpot API Documentation: Consult the official HubSpot API documentation for the most up-to-date information on endpoints, data structures, and authentication.

:speech_balloon: Still running into issues? Share your (sanitized) config files, the exact command you ran, and any other relevant details. The community is here to help!

just switched from infusionsoft last month. biggest thing that tripped me up - hubspot’s picky about http headers. you need Content-Type set to application/json and your bearer token has to be formatted right. also, add [JsonPropertyName] attributes to your model properties so they map to hubspot’s field names. and heads up - their responses are async, not like infusionsoft’s sync posting.

You’ll need to ditch InfusionSoft’s form posting and switch to HubSpot’s REST API instead. Drop the NameValueCollection approach completely - you’re moving to HTTP client requests now. Grab a private app access token from HubSpot’s developer settings (this replaces your inf_xid auth). Your controller needs to convert form data to JSON and POST it to api.hubapi.com/crm/v3/objects/contacts. Watch the field mapping - GivenName becomes firstname, FamilyName becomes lastname in HubSpot. For boolean fields like Regional_Reports, create custom contact properties in HubSpot first. Use HttpClient with solid error handling since HubSpot gives you detailed error responses. It’s pretty different from InfusionSoft’s form setup, but way more flexible once you get it working.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.