MCPcopy Index your code
hub / github.com/belong-inc/go-hubspot

github.com/belong-inc/go-hubspot @v0.11.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.11.0 ↗ · + Follow
405 symbols 871 edges 47 files 99 documented · 24% updated 43d agov0.11.0 · 2026-05-26★ 506 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

go-hubspot

godoc License

HubSpot Go Library that works with HubSpot API v3.
HubSpot officially supports client library of Node.js, PHP, Ruby, and Python but not Go.

Note: go-hubspot currently doesn't cover all the APIs but mainly implemented CRM APIs. Implemented APIs are used in production.

Install

$ go get github.com/belong-inc/go-hubspot

Usage

Authentication

API key

Deprecated

You should take api key in advance. Follow steps in here.

// Initialize hubspot client with apikey.
client, _ := hubspot.NewClient(hubspot.SetAPIKey("YOUR_API_KEY"))

OAuth

You should take refresh token in advance. Follow steps in here.

// Initialize hubspot client with OAuth refresh token.
client, _ := hubspot.NewClient(hubspot.SetOAuth(&hubspot.OAuthConfig{
    GrantType:    hubspot.GrantTypeRefreshToken,
    ClientID:     "YOUR_CLIENT_ID",
    ClientSecret: "YOUR_CLIENT_SECRET",
    RefreshToken: "YOUR_REFRESH_TOKEN",
}))

Private app

You should take access token in advance. Follow steps in here.

// Initialize hubspot client with private app access token.
client, _ := hubspot.NewClient(hubspot.SetPrivateAppToken("YOUR_ACCESS_TOKEN"))

API call

Get contact

// Initialize hubspot client with auth method.
client, _ := hubspot.NewClient(hubspot.SetPrivateAppToken("YOUR_ACCESS_TOKEN"))

// Get a Contact object whose id is `yourContactID`.
// Contact instance needs to be provided to bind response value.
res, _ := client.CRM.Contact.Get("yourContactID", &hubspot.Contact{}, nil)

// Type assertion to convert `interface` to `hubspot.Contact`.
contact, ok := res.Properties.(*hubspot.Contact)
if !ok {
    return errors.New("unable to assert type")
}

// Use contact fields.
fmt.Println(contact.FirstName, contact.LastName)

Create contact

// Initialize hubspot client with auth method.
client, _ := hubspot.NewClient(hubspot.SetPrivateAppToken("YOUR_ACCESS_TOKEN"))

// Create request payload.
req := &hubspot.Contact{
    Email:       hubspot.NewString("yourEmail"),
    FirstName:   hubspot.NewString("yourFirstName"),
    LastName:    hubspot.NewString("yourLastName"),
    MobilePhone: hubspot.NewString("yourMobilePhone"),
    Website:     hubspot.NewString("yourWebsite"),
    Zip:         nil,
}

// Call create contact api.
res, _ := client.CRM.Contact.Create(req)

// Type assertion to convert `interface` to `hubspot.Contact`.
contact, ok := res.Properties.(*hubspot.Contact)
if !ok {
    return errors.New("unable to assert type")
}

// Use contact fields.
fmt.Println(contact.FirstName, contact.LastName)

Associate objects

// Initialize hubspot client with auth method.
client, _ := hubspot.NewClient(hubspot.SetPrivateAppToken("YOUR_ACCESS_TOKEN"))

// Call associate api.
client.CRM.Contact.AssociateAnotherObj("yourContactID", &hubspot.AssociationConfig{
    ToObject:   hubspot.ObjectTypeDeal,
    ToObjectID: "yourDealID",
    Type:       hubspot.AssociationTypeContactToDeal,
})

API call using custom fields

Custom fields are added out of existing object such as Deal or Contact.
Therefore a new struct needs to be created which contain default fields and additional custom field, and set to Properties field of a request. Before using custom field through API, the field needs to be set up in HubSpot web site.

Get deal with custom fields.

type CustomDeal struct {
    hubspot.Deal // embed default fields.
    CustomA string `json:"custom_a,omitempty"`
    CustomB string `json:"custom_b,omitempty"`
}

// Initialize hubspot client with auth method.
client, _ := hubspot.NewClient(hubspot.SetPrivateAppToken("YOUR_ACCESS_TOKEN"))

// Get a Deal object whose id is `yourDealID`.
// CustomDeal instance needs to be provided as to bind response value contained custom fields.
res, _ := client.CRM.Deal.Get("yourDealID", &CustomDeal{}, &hubspot.RequestQueryOption{
    CustomProperties: []string{
        "custom_a",
        "custom_b",
    },
})

// Type assertion to convert `interface` to `CustomDeal`.
customDeal, ok := res.Properties.(*CustomDeal)
if !ok {
    return errors.New("unable to assert type")
}

// Use custom deal fields.
fmt.Println(customDeal.CustomA, customDeal.CustomB)

Create deal with custom properties.

type CustomDeal struct {
    hubspot.Deal // embed default fields.
    CustomA string `json:"custom_a,omitempty"`
    CustomB string `json:"custom_b,omitempty"`
}

// Initialize hubspot client with auth method.
client, _ := hubspot.NewClient(hubspot.SetPrivateAppToken("YOUR_ACCESS_TOKEN"))

req := &CustomDeal{
    Deal: hubspot.Deal{
        Amount:      hubspot.NewString("yourAmount"),
        DealName:    hubspot.NewString("yourDealName"),
        DealStage:   hubspot.NewString("yourDealStage"),
        DealOwnerID: hubspot.NewString("yourDealOwnerID"),
        PipeLine:    hubspot.NewString("yourPipeLine"),
    },
    CustomA: "yourCustomFieldA",
    CustomB: "yourCustomFieldB",
}

// Call create deal api with custom struct.
res, _ := client.CRM.Deal.Create(req)

// Type assertion to convert `interface` to `CustomDeal`.
customDeal, ok := res.Properties.(*CustomDeal)
if !ok {
    return errors.New("unable to type assertion")
}

// Use custom deal fields.
fmt.Println(customDeal.CustomA, customDeal.CustomB)

API availability

Category API Availability
CRM Deal Available
CRM Company Available
CRM Contact Available
CRM Imports Beta
CRM Schemas Beta
CRM Properties Beta
CRM Tickets Beta
CMS All Not Implemented
Conversations Visitor Identification Available
Events All Not Implemented
Marketing Marketing Email Available
Marketing Transactional Email Available
Files All Not Implemented
Settings All Not Implemented
Webhooks All Not Implemented

Authentication availability

Type Availability
API key Deprecated
OAuth Available
Private apps Available

Contributing

Contributions are generally welcome.
Please refer to CONTRIBUTING.md when making your contribution.

Extension points exported contracts — how you extend this code

NoteService (Interface)
NoteService is an interface of note endpoints of the HubSpot API. HubSpot notes store information about interactions and [3 …
note.go
CrmPropertiesService (Interface)
CrmPropertiesService is an interface of CRM properties endpoints of the HubSpot API. Reference: https://developers.hubsp [2 …
crm_properties.go
DealService (Interface)
DealService is an interface of deal endpoints of the HubSpot API. HubSpot deal can be used to manage transactions. It ca [2 …
deal.go
CrmSchemasService (Interface)
CrmSchemasService is an interface of CRM schemas endpoints of the HubSpot API. Reference: https://developers.hubspot.com [2 …
crm_schemas.go
CompanyService (Interface)
CompanyService is an interface of company endpoints of the HubSpot API. HubSpot companies store information about organi [1 …
company.go
MarketingEmailService (Interface)
MarketingEmailService is an interface of marketing email endpoints of the HubSpot API. As of May 2022, HubSpot provides [1 …
marketing_email.go
ContactService (Interface)
ContactService is an interface of contact endpoints of the HubSpot API. HubSpot contacts store information about individ [1 …
contact.go
CrmTicketsService (Interface)
CrmTicketsService is an interface of CRM tickets endpoints of the HubSpot API. Reference: https://developers.hubspot.com [1 …
crm_tickets.go

Core symbols most depended-on inside this repo

Error
called by 24
error.go
SetPrivateAppToken
called by 22
auth.go
NewClient
called by 21
gohubspot.go
Get
called by 15
deal.go
Post
called by 14
gohubspot.go
NewString
called by 13
type.go
Create
called by 11
deal.go
String
called by 9
type.go

Shape

Method 150
Struct 121
Function 108
Interface 14
TypeAlias 9
FuncType 3

Languages

Go100%

Modules by API surface

crm_tickets.go25 symbols
company.go23 symbols
contact.go22 symbols
legacy/marketing_emails.go21 symbols
deal.go20 symbols
example_test.go18 symbols
crm_schemas.go16 symbols
crm_properties.go16 symbols
type.go15 symbols
note.go15 symbols
gohubspot.go15 symbols
oauth.go13 symbols

For agents

$ claude mcp add go-hubspot \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page