HubspotClient

Gem
Version Rspec and Rubocop Maintainability Test Coverage

A Hubspot Client. Currently we only support the following CRM Parts:

  • Contact
  • Company
  • Properties

Also:

  • Communication Preferences

Installation

Add this line to your application's Gemfile:

gem 'hubspot_client'

And then execute:

$ bundle

Or install it yourself as:

$ gem install hubspot_client

Usage

You need to configure the hubspot_client first:

HubspotClient.configure do |config|
  config.access_token = 'PRIVATE_APP_ACCESS_TOKEN'
end

Models

The following models exists and should be mainly used. However you can also use the clients itself, if you like, but you need to understand the code by yourself.

Contact

Hubspot- API

find

You can find by hubspot_id or email

HubspotClient::Model::Contact.find(hubspot_id: '1337')
=> #<HubspotClient::Model::Contact createdate="2022-11-11T11:57:15.901Z", email="[email protected]", firstname="Darth", hs_object_id="1337", lastmodifieddate="2022-11-17T13:31:00.526Z", lastname="Vader">

HubspotClient::Model::Contact.find(email: '[email protected]')
=> #<HubspotClient::Model::Contact createdate="2022-11-11T11:57:15.901Z", email="[email protected]", firstname="Darth", hs_object_id="1337", lastmodifieddate="2022-11-17T13:31:00.526Z", lastname="Vader">

associate_primary_company

hubspot_contact = HubspotClient::Model::Contact.find(hubspot_id: '1337')
=> #<HubspotClient::Model::Contact createdate="2022-11-11T11:57:15.901Z", email="[email protected]", firstname="Darth", hs_object_id="1337", lastmodifieddate="2022-11-17T13:31:00.526Z", lastname="Vader"> 

hubspot_contact.associate_primary_company(6582942445)
=> true

Company

Here you can find the Hubspot-Companies-API-Documentation

find

Find a company be hubspot_id

HubspotClient::Model::Company.find(hubspot_id: '6614067165')
=> #<HubspotClient::Model::Company address="Todesternstraße 1", city="Todestern", createdate="2022-11-28T13:45:40.989Z", hs_lastmodifieddate="2022-11-28T13:45:44.933Z", hs_object_id="6614067165", name="Todesternverwaltungs GmbH", phone="0152123456789", zip="1337">

create

example_properties = { name: 'Todesternverwaltungs GmbH',
                       phone: '0152123456789',
                       address: 'Todesternstraße 1',
                       city: 'Todestern',
                       zip: '1337' }

HubspotClient::Model::Company.create(example_properties)
=> #<HubspotClient::Model::Company address="Todesternstraße 1", city="Todestern", createdate="2022-11-28T13:45:40.989Z", hs_lastmodifieddate="2022-11-28T13:45:40.989Z", hs_object_id="6614067165", hs_pipeline="companies-lifecycle-pipeline", lifecyclestage="lead", name="Todesternverwaltungs GmbH", phone="0152123456789", zip="1337">  

update

hubspot_company = HubspotClient::Model::Company.find(hubspot_id: '6614067165')

# You can change the attribute like so:
hubspot_company.name = 'Blubber'

# or like so:
hubspot_company.assign_attributes(name: 'Blubber')

# then you can run:
hubspot_company.update

# you can also do it directly in the update method:
hubspot_company.update({ name: 'Blubber' })

Communication-Preference

Hubspot- API

Clients

Clients are normally under the hood of models. However you can use them directly if you like.

Submission

forms/submit_form_v3_authentication

With the HubspotClient::Client::Form.all_forms method you can get all forms from your hubspot instance. Checkout which fields you need.

HubspotClient::Client::Submission.new(portal_id: '1337', form_guid: '1337', fields: fields).submit

The fields parameter is a list of objects with the following properties:

[
  {
    "objectTypeId": '0-1', # Optional
    "name": 'email',
    "value": '[email protected]'
  }
]

the context parameter is a hash of the following attributes:

{
  "pageUri": 'https://example.com',
  "pageName": 'Example page'
}

The leagalConsentOptions parameter is a hash of the following attributes:

{
    consent: {
      consentToProcess: true,
      text: "I agree to allow #{company_name} to store and process my personal data.",
      communications: []
    }
}

Development

After checking out the repo, run

bundle install

Then, run

bundle exec rspec spec

to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

You need a .env file looks like, if you want to test it against your hubspot instance:

ACCESS_TOKEN=<youur_private_app_access_token>

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/farbfox/hubspot_client. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the HubspotClient project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.