SDKs overview

HubSpot provides Software Development Kits (SDKs) to facilitate interaction with its comprehensive suite of APIs, covering areas such as CRM, marketing automation, sales, and content management. These SDKs abstract the underlying HTTP requests, JSON parsing, and authentication mechanisms, allowing developers to integrate HubSpot functionalities into their applications using familiar programming language constructs. The primary objective of these SDKs is to reduce development time and complexity when building applications that need to create, read, update, or delete data within the HubSpot ecosystem, such as managing contacts, companies, deals, or blog posts.

The SDKs handle common tasks like OAuth 2.0 authorization flows, retry mechanisms for transient errors, and pagination for large data sets, which are critical for building robust integrations. By using an SDK, developers can focus on the business logic of their application rather than the intricacies of the HubSpot API's RESTful design principles, including specific endpoint paths and HTTP methods for different operations. This approach aligns with common practices in API development, where SDKs are provided to enhance the developer experience and accelerate the adoption of an API. For more details on the overall HubSpot API capabilities, consult the HubSpot API overview documentation.

Official SDKs by language

HubSpot maintains official SDKs for several popular programming languages, ensuring direct support and compatibility with the latest API versions and features. These SDKs are developed and maintained by HubSpot, offering stability, consistent updates, and direct access to support resources. The official SDKs are the recommended approach for most integrations, providing fully tested and documented interfaces for interacting with HubSpot's various hubs.

The following table outlines the officially supported SDKs, including their package names, installation commands, and general maturity level:

Language Package/Library Name Install Command Maturity
Node.js @hubspot/api-client npm install @hubspot/api-client Stable
Python hubspot-api-client pip install hubspot-api-client Stable
Ruby hubspot-api-client gem install hubspot-api-client Stable
Java com.hubspot.api.client Maven: Add to pom.xml dependencies
Gradle: Add to build.gradle dependencies
Stable
PHP hubspot/api-client composer require hubspot/api-client Stable
.NET HubSpot.NET dotnet add package HubSpot.NET Stable

Installation

Installing a HubSpot SDK typically involves using the respective language's package manager. Each SDK is published to its ecosystem's central repository, simplifying dependency management and updates. Before installation, ensure your development environment has the correct language runtime and package manager installed.

Node.js

For Node.js projects, the SDK is available via npm. Open your terminal in your project directory and execute:

npm install @hubspot/api-client

This command downloads and adds the @hubspot/api-client package to your project's node_modules directory and updates your package.json file. Node.js SDKs, like those from Cloudflare Workers for KV storage, often follow similar installation patterns.

Python

Python developers can install the SDK using pip, the standard package installer for Python:

pip install hubspot-api-client

After installation, you can import the library in your Python scripts. Pip manages dependencies for thousands of Python packages, including popular data science libraries and web frameworks.

Ruby

The Ruby SDK is distributed as a gem. Install it using the gem command:

gem install hubspot-api-client

Once installed, you can require the gem in your Ruby application files.

Java

For Java projects, the HubSpot API client is available through Maven Central. If you are using Maven, add the following dependency to your pom.xml file:

<dependency>
    <groupId>com.hubspot.api.client</groupId>
    <artifactId>hubspot-api-client</artifactId>
    <version>YOUR_SDK_VERSION</version>
</dependency>

Replace YOUR_SDK_VERSION with the latest stable version available. If you are using Gradle, add the following to your build.gradle file:

implementation 'com.hubspot.api.client:hubspot-api-client:YOUR_SDK_VERSION'

PHP

PHP developers can install the SDK using Composer, the dependency manager for PHP:

composer require hubspot/api-client

This command will add the HubSpot API client to your project's composer.json and download the necessary files into the vendor/ directory.

.NET

For .NET projects, the HubSpot SDK is available as a NuGet package. Use the .NET CLI to add the package to your project:

dotnet add package HubSpot.NET

Alternatively, you can use the Package Manager Console in Visual Studio:

Install-Package HubSpot.NET

Quickstart example

This quickstart example demonstrates how to authenticate and fetch recent contacts using the Node.js SDK. This pattern is broadly applicable across other language SDKs, though syntax will vary. Replace YOUR_HUBSPOT_ACCESS_TOKEN with an actual access token obtained via the OAuth 2.0 flow or a private app API key for production environments. For detailed authentication instructions, refer to the HubSpot API authentication guide.

Node.js Quickstart: Fetching Contacts

First, ensure you have installed the Node.js SDK as described in the installation section.

const hubspot = require('@hubspot/api-client');

const accessToken = 'YOUR_HUBSPOT_ACCESS_TOKEN'; // Replace with your actual access token or API key

const hubspotClient = new hubspot.Client({
  accessToken: accessToken
});

async function getRecentContacts() {
  try {
    const apiResponse = await hubspotClient.crm.contacts.getAll();
    console.log('Recent Contacts:');
    apiResponse.results.forEach(contact => {
      console.log(`  ID: ${contact.id}, Email: ${contact.properties.email || 'N/A'}`);
    });
  } catch (e) {
    e.message === 'HTTP request failed' ?
      console.error(JSON.stringify(e.response, null, 2)) :
      console.error(e)
  }
}

getRecentContacts();

This script initializes the HubSpot client with an access token. It then calls the crm.contacts.getAll() method to retrieve a list of contacts. The results, including contact IDs and email addresses, are then logged to the console. Error handling is included to catch potential API issues, printing detailed response information when an HTTP request fails.

For Python, a similar operation would look like this:

from hubspot import HubSpot

personal_access_token = 'YOUR_HUBSPOT_ACCESS_TOKEN'
hubspot_client = HubSpot(access_token=personal_access_token)

def get_recent_contacts():
    try:
        api_response = hubspot_client.crm.contacts.get_all()
        print("Recent Contacts:")
        for contact in api_response.results:
            email = contact.properties.get('email', 'N/A')
            print(f"  ID: {contact.id}, Email: {email}")
    except Exception as e:
        print(f"Error fetching contacts: {e}")

get_recent_contacts()

This Python example mirrors the Node.js functionality, demonstrating how the SDKs provide a consistent, object-oriented interface across different languages, simplifying API interactions for developers regardless of their preferred programming environment. The use of a personal access token is suitable for quick development and testing. For production applications, OAuth 2.0 is generally recommended for its enhanced security features and user consent mechanisms, as detailed by the OAuth 2.0 authorization framework specification.

Community libraries

While HubSpot provides robust official SDKs, the broader developer community often contributes additional libraries, tools, and integrations that extend functionality or address specific use cases not covered by official offerings. These community-driven projects can range from wrappers for less commonly supported languages to specialized utilities that simplify complex workflows or integrate with other platforms. Community libraries are often found on platforms like GitHub or through language-specific package repositories.

When considering community libraries, it is essential to evaluate their maintenance status, documentation quality, and community support. Unlike official SDKs, community projects may not receive regular updates or direct support from HubSpot. However, they can sometimes offer innovative solutions or pre-built components that accelerate development for niche requirements. Developers should always review the source code and licensing of community libraries before incorporating them into production applications.

Examples of community contributions might include:

  • Client libraries for other languages: While HubSpot officially supports six languages, developers might create clients for languages like Go, Rust, or Elixir.
  • Framework-specific integrations: Libraries that integrate HubSpot APIs more seamlessly with popular web frameworks (e.g., a Django package for HubSpot CRM, or a Laravel package for HubSpot forms).
  • Specialized tools: Utilities for data migration, bulk operations, or custom reporting that leverage HubSpot APIs but are not part of the core SDKs.

To discover community libraries, developers typically search GitHub, relevant language package indexes (e.g., PyPI for Python, npm for Node.js), or developer forums. Always prioritize libraries with active development, clear license terms, and positive community feedback to ensure long-term viability and security. HubSpot's own developer community forums can also be a good resource for finding and discussing unofficial integrations and tools.