Skip to content
KenCox edited this page Nov 6, 2017 · 39 revisions

Creating a HubSpot Contact and Company from an ASP.NET MVC Site

HubSpot is a popular customer relations management (CRM) platform that offers a REST API for third-party integrations. Trouble is, HubSpot hasn't done a good job of guiding developers through a simple setup and integration scenario. This document provides the simplest steps to get a HubSpot account, create your API key and set up a barebones MVC/HubSpot integration.

Create Your Developer Account and Test Hub

You can sign up for a free developer account on HubSpot. The developer account is limited in that you can work with the API to add Contacts to HubSpot but you don't get the Marketing dashboard to see a list of those contacts with the HubSpot UI. This was a very confusing waste of time. What you need is the full-featured trial version of HubSpot.

Creating a Developer Account

  1. Navigate to https://developers.hubspot.com/
  2. In the upper right area, click Create an Account.
  3. Fill in the developer account details (as shown in the image below) and click Start Building Apps:

HubSpot Developer Account

HubSpot announces that your account is ready and then shifts to the Development screen.

Creating a HubSpot Test Hub

  1. While still logged in to HubSpot with your developer account, click the Testing menu item at the top left area of the screen as shown in the following image:

Testing Menu

  1. On the Testing page, near the bottom, click Start testing.
  2. On the Create Test Hub ID pop-up, provide a test hub name (for example, hubspotmvc) and click Create as shown in the image below:

Create Test Hub ID

The Testing page displays a grid with the Test Hub you just created, as shown in the following image:

Test Hub Created

  1. Click the name of the Test Hub to enter the Marketing Dashboard.

Generate Your HubSpot API Key

  1. Click the Profile and Preferences area in the top right of the screen:

Profile and Preferences

  1. Click Integrations.
  2. On the Integrations screen click HubSpot API Key and then click Generate New Key:

HubSpot API Key

The new HAPIkey appears along with the API Key History as shown below:

HubSport HAPIKey

  1. Copy the HAPIKey to a file and save it for use in a following step. Do not publish your API key publicly.

Create an ASP.NET MVC Integration for HubSpot

Once you have a HubSpot Test Hub and API key, you can create an ASP.NET MVC application that inserts a contact and a company into the Test Hub. This topic uses a simple REST client to provide .NET bindings for the HubSpot CRM from https://github.com/dmitrybakaev/hubspot-rest-client

Create an ASP.NET MVC Web Site

  1. In Visual Studio 2015 or later, create a new ASP.NET Web Application named HubSpotIntegrationExample (File > New Project > ASP.NET Web Application) choosing the MVC template.

Visual Studio MVC Web Application

  1. From GitHub, download the archive of the Visual Studio project from dmitrybakaev/hubspot-rest-client
  2. Unarchive the hubspot-rest-client to your local machine, retaining the folder structure.
  3. In the Visual Studio HubSpotIntegrationExample solution, add the HubSpotRestClient project (Add > Existing Project).
  4. In the Visual Studio HubSpotIntegrationExample project, add a reference to the HubSpotRestClient project.

Add Reference

  1. Ensure that the solution builds. (You may need to use the Nuget Package Manager to adjust versions of some components.)
  2. In the Visual Studio HubSpotIntegrationExample project, from the Controllers folder, open HomeController.cs in the editor.
  3. Replace the existing Index() method with the following code and substitute the unique HAPIKey (captured previously) in the highlighted area:

Controller Index

  1. Run the Web page.

Confirming the Contact and Company Insertion in HubSpot

  1. In HubSpot, navigate to your trial account as shown in the image below:

Navigate to Account

  1. From the upper left area, click Contacts > Contacts. Note that the contact has been inserted as shown below:

Added Contact

  1. From the upper left area, click Contacts, Companies. Confirm that the company has been inserted as shown below:

Added Company

Alternative to Using the HubSpotRestClient project

Rather than importing a library to insert the contact and company, you can create the required payload and post it using .NET code in your project.

This example shows a simplified use of the REST API where you manually build a JSON string containing the properties that you then post to the REST API as a byte array.

Post Content to HubSpot