gospot

package module
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 9, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

README

gospot

Golang Hubspot CRM API Package

Contribution

PRs are welcome

Changelog

For release notes please consult the specific releases here

Usage

Installation
go get github.com/TeamDirector/gospot
Importing
 import "github.com/TeamDirector/gospot"
Init Oauth Connection

Installation of a hubspot plugin and generation of the Oauth Code needs to be interactive by design. Catch the code parameter if the Hubspot Installation Callback to the RedirectURI and perform:

    initClient := gospot.NewInitClient(oauthConfig)
	
	token, err := initClient.ExchangeInitialCode(ctx, code)
	if err != nil {
		return err
	}

    storeToken(token)

Store this token, which includes a refresh token for future use Token refresh and rotation are handled by this client.

Call Endpoints
    func createClient() {
        var oauthConfig = &oauth2.Config{
            ClientID:     "...",
            ClientSecret: "...",
            RedirectURL:  "yourInstallRedirectCallbackURI",
            Scopes:       []string{"..."},
            Endpoint: oauth2.Endpoint{
                TokenURL: "https://api.hubapi.com/oauth/v1/token",
            },
        }

        token := loadToken()
        clientID := "someIdentifier"

        client := gospot.NewClient(oauthConfig, token, &clientID, tokenRefreshCallback)

        // Fetch all companies incl. contacts and some properties. Full reference for supported propperties and associations here https://developers.hubspot.com/docs/guides/crm/understanding-the-crm
        results, err := client.FindMany(ctx, gospot.DataTypeCompanies, token, &gospot.FindManyParams{
            Properties:   &[]string{"address", "address2", "name", "domain", "city", "country", "zip", "state", "about_us"},
            Associations: &[]string{"contacts"},
        })
        if err != nil {
            panic(err)
        }

        HandleResults(results) // parse results to your needs
    }

    func tokenRefreshCallback(ctx context.Context, clientIdentifier *string, token *oauth2.Token) error {
        storeToken(token)
    }

Features

Currently only Authentication and Fetching of CRM Data is supported.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WrapError

func WrapError(err error, message string) error

Types

type APIError

type APIError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Type    string `json:"type"`
}

APIError holds message and statusCode for api errors

func (APIError) Error

func (apiError APIError) Error() string

Error stringifies the APIError

type AssociationResult

type AssociationResult struct {
	Id   string `json:"id"`
	Type string `json:"type"`
}

type AssociationResults

type AssociationResults struct {
	Results []AssociationResult `json:"results"`
}

type Client

type Client struct {
	Server string

	// Doer for performing requests
	RestyClient *resty.Client

	OauthConfig *oauth2.Config

	OauthToken *oauth2.Token

	// Function called, when a token is fetched or refreshed so the using library can store the new refresh_token for furure use. The optional ClientIdentifier, for the using library to know which client called the function
	// Returns
	// error - any errors the Function passed in returned
	TokenRefreshCallback TokenRefreshCallback

	ClientIdetifier *string
}

func NewClient

func NewClient(oauthConfig *oauth2.Config, oAuthToken *oauth2.Token, clientIdentifier *string, tokenRefreshCallback TokenRefreshCallback) *Client

Creates a new Client, with reasonable defaults

func (*Client) FindMany

func (c *Client) FindMany(ctx context.Context, dataType DataType, currentToken *oauth2.Token, params *FindManyParams) ([]*Result, error)

func (*Client) FindOne

func (c *Client) FindOne(ctx context.Context, dataType DataType, currentToken *oauth2.Token, id string, params *FindOneParams) (*Result, error)

func (*Client) GetAPIURL

func (c *Client) GetAPIURL(path ...string) string

func (*Client) GetRequest

func (c *Client) GetRequest(ctx context.Context) *resty.Request

GetRequest returns a request for calling endpoints.

func (*Client) GetRequestWithBearerAuth

func (c *Client) GetRequestWithBearerAuth(ctx context.Context, token string) *resty.Request

func (*Client) GetToken

func (c *Client) GetToken(ctx context.Context, token *oauth2.Token) (*oauth2.Token, error)

type DataType

type DataType string
const (
	DataTypeContacts  DataType = "contacts"
	DataTypeCompanies DataType = "companies"
	DataTypeProjects  DataType = "projects"
	DataTypeDeals     DataType = "deals"
)

type ErrorResponse

type ErrorResponse struct {
	Status        string `json:"status,omitempty"`
	Message       string `json:"message,omitempty"`
	CorrelationId string `json:"correlationId,omitempty"`
	Category      string `json:"category,omitempty"`
}

ErrorResponse is a model of an error response

func (ErrorResponse) NotEmpty

func (e ErrorResponse) NotEmpty() bool

NotEmpty validates that error is not emptyp

func (ErrorResponse) String

func (e ErrorResponse) String() string

String returns a string representation of an error

type FindManyParams

type FindManyParams struct {
	After                 *string   `json:"after,omitempty" url:"after,omitempty"`
	Archived              *bool     `json:"archived,string,omitempty" json:"url,string,omitempty"`
	Associations          *[]string `json:"associations,omitempty" url:"associations,omitempty"`
	Limit                 *int      `json:"limit,string,omitempty" json:"url,string,omitempty"`
	Properties            *[]string `json:"properties,omitempty" url:"properties,omitempty"`
	PropertiesWithHistory *[]string `json:"propertiesWithHistory,omitempty" url:"propertiesWithHistory,omitempty"`
}

type FindOneParams

type FindOneParams struct {
	Archived              *bool     `json:"archived,omitempty" url:"archived,omitempty"`
	Associations          *[]string `json:"associations,omitempty" url:"associations,omitempty"`
	IdProperty            *string   `json:"idProperty,omitempty" url:"idProperty,omitempty"`
	Properties            *[]string `json:"properties,omitempty" url:"properties,omitempty"`
	PropertiesWithHistory *[]string `json:"propertiesWithHistory,omitempty" url:"propertiesWithHistory,omitempty"`
}

type InitClient

type InitClient struct {
	Server      string
	OauthConfig *oauth2.Config
}

func NewInitClient

func NewInitClient(oauthConfig *oauth2.Config) *InitClient

Creates a new Client, with reasonable defaults

func (*InitClient) ExchangeInitialCode

func (c *InitClient) ExchangeInitialCode(ctx context.Context, code string) (*oauth2.Token, error)

type ManyResponse

type ManyResponse struct {
	Results []*Result `json:"results"`
	Paging  *Paging   `json="paging,omitempty"`
}

type OneResponse

type OneResponse = Result

type Paging

type Paging struct {
	Next PagingNext `json:"next"`
	Prev PagingPrev `json:"prev"`
}

type PagingNext

type PagingNext struct {
	After string `json:"after"`
	Link  string `json:"link"`
}

type PagingPrev

type PagingPrev struct {
	Before string `json:"before"`
	Link   string `json:"link"`
}

type Result

type Result struct {
	Archived              bool                          `json:"archived"`
	CreatedAt             string                        `json:"createdAt"`
	Id                    string                        `json:"id"`
	Properties            map[string]string             `json:"properties"`
	UpdatedAt             string                        `json:"updatedAt"`
	ArchivedAt            string                        `json:"archivedAt"`
	Associations          map[string]AssociationResults `json:"associations"`
	ObjectWriteTraceId    string                        `json:"objectWriteTraceId"`
	PropertiesWithHistory map[string]string             `json:"propertiesWithHistory"`
	Url                   string                        `json:"url"`
}

type TokenRefreshCallback

type TokenRefreshCallback func(ctx context.Context, clientIdentifier *string, token *oauth2.Token) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL