Skip to content

ericctsf/go-hubspot

Repository files navigation

Go HubSpot library

This library provides generic methods for interaction with HubSpot Forms, CRM (Contacts, Companies), DealFlow and File APIs.

Usage

You can install the module directly from GitHub.

go get -u github.com/ericctsf/go-hubspot@<version>

Where version can point to a commit hash or a branch, for example:

go get -u github.com/ericctsf/go-hubspot@9302e1d

or

go get -u github.com/ericctsf/go-hubspot@master

Note: specifying the branch will not update the import when updates are made to that branch.

You can then import the library as follows:

import (
	hubspot "github.com/ericctsf/go-hubspot"
)

Examples

Search for form submissions with the first name John:

package main

import (
	hubspot "github.com/ericctsf/go-hubspot"
)

func main() {
	api := hubspot.NewHubspotFormAPI("form-id", "hapikey")
	_, _ = api.SearchForKeyValue("firstname", "John")
}

Get company ID associated with a contact:

package main

import (
	hubspot "github.com/ericctsf/go-hubspot"
)

func main() {
	api := hubspot.NewHubspotCRMAPI("hapikey")
	_, _ = api.GetCompanyForContact("123456")
}

Update move a DealFlow card to another column (i.e. update its dealstage property):

package main

import (
	hubspot "github.com/ericctsf/go-hubspot"
)

func main() {
	api := hubspot.NewHubspotDealFlowAPI("hapikey")
	_ = api.UpdateDealFlowCard(
		"123456",
		map[string]string{
			"dealstage": "another-stage",
        },
    )
}

Upload a file to the HubSpot CRM

package main

import (
	hubspot "github.com/ericctsf/go-hubspot"
)

func main() {
	fileApi := hubspot.NewHubspotFileAPI("hapikey", "portalId")
	fileUrl, err := fileApi.UploadFile(bytes, "folder path", "file name")
}

Mocking

moq is used to generate mocks:

  • Mocks for external interfaces to use within unit tests
  • Mocks for go-hubspot API interfaces, to make testing of applications that use the library easier
go get github.com/matryer/moq
go install github.com/matryer/moq
go generate

Testing

go vet
go test -coverprofile=coverage.out
go tool cover -html=coverage.out # To view test coverage

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages