Ruby API v3 Client files and sample apps

  • API version: v3
  • Package version: 1.0.0
  • Build package: io.swagger.codegen.languages.RubyClientCodegen


Build a gem

To build the Ruby code into a gem:

gem build hubspot-api-client.gemspec

Then either install the gem locally:

gem install ./hubspot-api-client-1.0.0.gem

(for development, run gem install --dev ./hubspot-api-client-1.0.0.gem to install the development dependencies)

or publish the gem to a gem hosting service, e.g. RubyGems.

Finally add this to the Gemfile:

gem 'hubspot-api-client', '~> 1.0.0'

Install from Git

If the Ruby gem is hosted at a git repository:, then add the following in the Gemfile:

gem 'hubspot-api-client', :git => ''

Include the Ruby code directly

Include the Ruby code directly using -I as follows:

ruby -Ilib script.rb

Getting Started

Please follow the installation procedure and then run the following code:

# Load the gem
require 'hubspot-api-client'

# Setup authorization
Hubspot.configure do |config|
  # Configure API key authorization: hapikey
  config.api_key['hapikey'] = 'demo'

# Get contacts
basic_api =
basic_api.get_page(auth_names: 'hapikey')


Get all:

get_all method is available for all major objects (Companies, Contacts, Deals, LineItems, Products, Quotes & Tickets) and works like

basic_api =
all_contacts = basic_api.get_all(auth_names: 'oauth2')

Please note that pagination is used under the hood to get all results.

Error handling

You can set number of retry attempts and delay in seconds before retry on specific status code of response.

Available params:

  • max_retries (maximum number of retries)
  • seconds_delay (pause in seconds between retries)
  • retry_block (block that is executed after every retry)
config = do |config|
  config.access_token = 'YOUR ACCESS TOKEN'

  # Set handlers of statuses you want to handle
  config.error_handler = {
    [429, 430, 442] => { max_retries: 5, seconds_delay: 1 },
    (500..530).to_a => { max_retries: 2, seconds_delay: 2 },
    400 => { max_retries: 3, seconds_delay: 3 },

api_client =
basic_api =