Skip to content

Latest commit

 

History

History
116 lines (92 loc) · 2.4 KB

README.md

File metadata and controls

116 lines (92 loc) · 2.4 KB

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