Categorygithub.com/kareHero/go-hubspot
modulepackage
1.0.12
Repository: https://github.com/karehero/go-hubspot.git
Documentation: pkg.go.dev

# 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/kareHero/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

CategoryAPIAvailability
CRMDealAvailable
CRMCompanyAvailable
CRMContactAvailable
CRMImportsBeta
CRMSchemasBeta
CRMPropertiesBeta
CRMTicketsBeta
CMSAllNot Implemented
ConversationsAllNot Implemented
EventsAllNot Implemented
MarketingMarketing EmailAvailable
MarketingTransactional EmailAvailable
FilesAllNot Implemented
SettingsAllNot Implemented
WebhooksAllNot Implemented

Authentication availability

TypeAvailability
API keyDeprecated
OAuthAvailable
Private appsAvailable

Contributing

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

# Packages

Package legacy is the package for legacy APIs in Hubspot.

# Functions

CheckResponseError checks the response, and in case of error, maps it to the error structure.
NewClient returns a new HubSpot API client with APIKey or OAuthConfig.
No description provided by the author
NewMarketingEmail creates a new MarketingEmailService.
NewString returns pointer HsStr(string).
NewTime returns pointer HsTime(time.Time).
Deprecated: Use hubspot.SetPrivateAppToken.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Constants

Default association types Reference: https://legacydocs.hubspot.com/docs/methods/crm-associations/crm-associations-overview.
Default association types Reference: https://legacydocs.hubspot.com/docs/methods/crm-associations/crm-associations-overview.
Default association types Reference: https://legacydocs.hubspot.com/docs/methods/crm-associations/crm-associations-overview.
Default association types Reference: https://legacydocs.hubspot.com/docs/methods/crm-associations/crm-associations-overview.
Default association types Reference: https://legacydocs.hubspot.com/docs/methods/crm-associations/crm-associations-overview.
Default association types Reference: https://legacydocs.hubspot.com/docs/methods/crm-associations/crm-associations-overview.
Default association types Reference: https://legacydocs.hubspot.com/docs/methods/crm-associations/crm-associations-overview.
Default association types Reference: https://legacydocs.hubspot.com/docs/methods/crm-associations/crm-associations-overview.
Default association types Reference: https://legacydocs.hubspot.com/docs/methods/crm-associations/crm-associations-overview.
Default association types Reference: https://legacydocs.hubspot.com/docs/methods/crm-associations/crm-associations-overview.
Default association types Reference: https://legacydocs.hubspot.com/docs/methods/crm-associations/crm-associations-overview.
No description provided by the author
InvalidEmailError is the value of ErrDetail.Error when an error occurs in the Email validation.
MIMETypeFormData is the mimetype for multipart form data.
MIMETypeJSON is the mimetype for JSON.
Default Object types.
Default Object types.
Default Object types.
UnknownDetailError is the value set by go-hubspot when extraction the error details failed.
ValidationError is the APIError.Category.

# Variables

BlankStr should be used to include empty string in HubSpot fields.

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Client manages communication with the HubSpot API.
No description provided by the author
CompanyServiceOp handles communication with the product related methods of the HubSpot API.
No description provided by the author
ContactServiceOp handles communication with the product related methods of the HubSpot API.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
CrmImportsServiceOp handles communication with the bulk CRM import endpoints of the HubSpot API.
No description provided by the author
CrmPropertiesServiceOp handles communication with the CRM properties endpoint.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
CrmSchemasServiceOp handles communication with the CRM schemas endpoint.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
CrmTicketsServivceOp handles communication with the CRM tickets endpoints of the HubSpot API.
Deal represents a HubSpot deal.
DealServiceOp handles communication with the product related methods of the HubSpot API.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
RequestPayload is common request structure for HubSpot APIs.
RequestQueryOption is a set of options to be specified in the query when making a Get request.
ResponseResource is common response structure for HubSpot APIs.
No description provided by the author
No description provided by the author
No description provided by the author
TransactionalServiceOp provides the default implementation of TransactionService.
No description provided by the author

# Interfaces

No description provided by the author
CompanyService is an interface of company endpoints of the HubSpot API.
ContactService is an interface of contact endpoints of the HubSpot API.
CrmImportsService is an interface of CRM bulk import endpoints of the HubSpot API.
CrmPropertiesService is an interface of CRM properties endpoints of the HubSpot API.
CrmSchemasService is an interface of CRM schemas endpoints of the HubSpot API.
CrmTicketsServivce is an interface of CRM tickets endpoints of the HubSpot API.
DealService is an interface of deal endpoints of the HubSpot API.
MarketingEmailService is an interface of marketing email endpoints of the HubSpot API.
No description provided by the author
TransactionalService is an interface for the marketing/transactional service of the HubSpot API.
No description provided by the author

# Type aliases

AssociationType is the name of the key used to associate the objects together.
No description provided by the author
No description provided by the author
No description provided by the author
HsBool is defined to marshal the HubSpot boolean fields of `true`, `"true"`, and so on, into a bool type.
No description provided by the author
HsStr is defined to identify HubSpot's empty string from null.
HsTime is defined to identify HubSpot time fields with null and empty string.
ObjectType is the name used in object association.
No description provided by the author
No description provided by the author