hubspot

package
v0.0.0-...-29fdbbe Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: MIT Imports: 15 Imported by: 0

README

Hubspot connector

This connector has two ways of reading data from Hubspot:

  1. Read
  2. Search

Read

Read is used to list all records of a given type. For example, if you want to list all contacts, you would use the Read method with the contacts object.

Example

To list all contacts with the fields email, firstname, and lastname:

client.Read(context.Background(), &common.ReadParams{
    ObjectName: "contacts",
    Fields:    []string{"email", "firstname", "lastname"},
})

If the 'Since' field in the ReadParams is set, the connector will use the search endpoint to filter records using the lastmodifieddate property. However, this result set is limited to a maximum of 10,000 records. This limit is applicable to any call made via the Search endpoint. Read more @ https://developers.hubspot.com/docs/api/crm/search#limitations.

Search is used to find records of a given type that match a given query. For example, if you want to find all contacts with the name "John", you would use the Search method with the contacts object.

Example

To find all contacts with the firstname "Brian" and a last modified date after "2023-10-26T17:56:14.834Z", sorted by the hs_object_id field in descending order:

result, err := client.Search(context.Background(), hubspot.SearchParams{
    ObjectName: "contacts",
    FilterGroups: []hubspot.FilterGroup{
        {
            Filters: []hubspot.Filter{
                {
                    FieldName: "firstname",
                    Operator:  hubspot.FilterOperatorTypeEQ,
                    Value:     "Brian",
                },
                {
                    FieldName: "lastname",
                    Operator:  hubspot.FilterOperatorTypeEQ,
                    Value:     "Halligan (Sample Contact)",
                },
            },
        },
        {
            Filters: []hubspot.Filter{
                {
                    FieldName: "firstname",
                    Operator:  hubspot.FilterOperatorTypeEQ,
                    Value:     "Maria",
                },
            },
        },
    },
    SortBy: []hubspot.SortBy{
        {
            PropertyName: "hs_object_id",
            Direction:    hubspot.SortDirectionDesc,
        },
    },
})

Documentation

Index

Constants

View Source
const (
	// ModuleEmpty is used for proxying requests through.
	ModuleEmpty common.ModuleID = ""
	// ModuleCRM is the module used for accessing standard CRM objects.
	ModuleCRM common.ModuleID = "CRM"
)
View Source
const (
	SortDirectionAsc  SortDirection = "ASCENDING"
	SortDirectionDesc SortDirection = "DESCENDING"

	FilterOperatorTypeEQ           FilterOperatorType = "EQ"
	FilterOperatorTypeNEQ          FilterOperatorType = "NEQ"
	FilterOperatorTypeGT           FilterOperatorType = "GT"
	FilterOperatorTypeGTE          FilterOperatorType = "GTE"
	FilterOperatorTypeLT           FilterOperatorType = "LT"
	FilterOperatorTypeLTE          FilterOperatorType = "LTE"
	FilterOperatorBetween          FilterOperatorType = "BETWEEN"
	FilterOperatorIN               FilterOperatorType = "IN"
	FilterOperatorNIN              FilterOperatorType = "NIN"
	FilterPropertyHasProperty      FilterOperatorType = "HAS_PROPERTY"
	FilterPropertyNotHasProperty   FilterOperatorType = "NOT_HAS_PROPERTY"
	FilterPropertyContainsToken    FilterOperatorType = "CONTAINS_TOKEN"
	FilterPropertyNotContainsToken FilterOperatorType = "NOT_CONTAINS_TOKEN"
)
View Source
const (
	// DefaultPageSize is the default page size for paginated requests.
	DefaultPageSize = "100"
)

Variables

View Source
var (
	ErrMissingAPIModule = errors.New("missing Hubspot API module")
	ErrMissingClient    = errors.New("JSON http client not set")
	ErrNotArray         = errors.New("results is not an array")
	ErrNotObject        = errors.New("result is not an object")
	ErrNotString        = errors.New("link is not a string")
)

Functions

func GetLastResultId

func GetLastResultId(result *common.ReadResult) string

GetLastResultId returns the last row's id from a result.

Types

type Connector

type Connector struct {
	BaseURL string
	Client  *common.JSONHTTPClient
	Module  common.Module
}

Connector is a Hubspot connector.

func NewConnector

func NewConnector(opts ...Option) (conn *Connector, outErr error)

NewConnector returns a new Hubspot connector.

func (*Connector) Close

func (c *Connector) Close() error

func (*Connector) HTTPClient

func (c *Connector) HTTPClient() *common.HTTPClient

func (*Connector) JSONHTTPClient

func (c *Connector) JSONHTTPClient() *common.JSONHTTPClient

JSONHTTPClient returns the underlying JSON HTTP client.

func (*Connector) ListObjectMetadata

func (c *Connector) ListObjectMetadata(
	ctx context.Context,
	objectNames []string,
) (*common.ListObjectMetadataResult, error)

ListObjectMetadata returns object metadata for each object name provided.

func (*Connector) Provider

func (c *Connector) Provider() providers.Provider

Provider returns the connector provider.

func (*Connector) Read

func (c *Connector) Read(ctx context.Context, config common.ReadParams) (*common.ReadResult, error)

Read reads data from Hubspot. If Since is set, it will use the Search endpoint instead to filter records, but it will be limited to a maximum of 10,000 records. This is a limit of the search endpoint. If Since is not set, it will use the read endpoint. In case Deleted objects won’t appear in any search results. Deleted objects can only be read by using this endpoint.

func (*Connector) Search

func (c *Connector) Search(ctx context.Context, config SearchParams) (*common.ReadResult, error)

Search uses the POST /search endpoint to filter object records and return the result. This endpoint has a limit of 10,000 records. If the result has more than 10,000 records, the caller should employ sorting to paginate through the result on the client side. This endpoint paginates using paging.next.after which is to be used as an offset. Archived results do not appear in search results. Read more @ https://developers.hubspot.com/docs/api/crm/search

func (*Connector) String

func (c *Connector) String() string

String returns a string representation of the connector, which is useful for logging / debugging.

func (*Connector) Write

func (c *Connector) Write(ctx context.Context, config common.WriteParams) (*common.WriteResult, error)

type ErrContext

type ErrContext struct {
	ID             []string `json:"id,omitempty"`
	Type           []string `json:"type,omitempty"`
	ObjectType     []string `json:"objectType,omitempty"`
	FromObjectType []string `json:"fromObjectType,omitempty"`
	ToObjectType   []string `json:"toObjectType,omitempty"`
}

type ErrDetail

type ErrDetail struct {
	IsValid bool   `json:"isValid,omitempty"`
	Message string `json:"message,omitempty"`
	Error   string `json:"error,omitempty"`
	Name    string `json:"name,omitempty"`
}
type ErrLinks struct {
	APIKey        string `json:"apiKey,omitempty"`
	KnowledgeBase string `json:"knowledgeBase,omitempty"`
}

type Filter

type Filter struct {
	FieldName string             `json:"propertyName,omitempty"`
	Operator  FilterOperatorType `json:"operator,omitempty"`
	Value     string             `json:"value,omitempty"`
}

func BuildIdFilterGroup

func BuildIdFilterGroup(id string) Filter

BuildIdFilterGroup filters records greater than the given id.

func BuildLastModifiedFilterGroup

func BuildLastModifiedFilterGroup(params *common.ReadParams) Filter

BuildLastModifiedFilterGroup filters records modified since the given time. If the time is zero, it returns an empty filter. For contacts, it uses the lastmodifieddate field. For other objects, it uses the hs_lastmodifieddate. Read more: https://community.hubspot.com/t5/APIs-Integrations/CRM-V3-API-Search-issue-with-Contacts-when-using-Filters/m-p/324617

type FilterGroup

type FilterGroup struct {
	Filters []Filter `json:"filters,omitempty"`
}

type FilterOperatorType

type FilterOperatorType string

type HubspotError

type HubspotError struct {
	HTTPStatusCode int         `json:"httpStatusCode"`
	Status         string      `json:"status,omitempty"`
	Message        string      `json:"message,omitempty"`
	CorrelationID  string      `json:"correlationId,omitempty"`
	Context        ErrContext  `json:"context,omitempty"`
	Category       string      `json:"category,omitempty"`
	SubCategory    string      `json:"subCategory,omitempty"`
	Links          ErrLinks    `json:"links,omitempty"`
	Details        []ErrDetail `json:"details,omitempty"`
}

type ObjectField

type ObjectField string

ObjectField is used to define fields that exist on a hubspot object.

const (
	ObjectFieldHsObjectId         ObjectField = "hs_object_id"
	ObjectFieldHsLastModifiedDate ObjectField = "hs_lastmodifieddate"
	ObjectFieldLastModifiedDate   ObjectField = "lastmodifieddate"
)

type ObjectType

type ObjectType string
const (
	ObjectTypeContact ObjectType = "contacts"
)

type Option

type Option = func(params *parameters)

Option is a function which mutates the hubspot connector configuration.

func WithAuthenticatedClient

func WithAuthenticatedClient(client common.AuthenticatedHTTPClient) Option

WithAuthenticatedClient sets the http client to use for the connector. Its usage is optional.

func WithClient

func WithClient(ctx context.Context, client *http.Client,
	config *oauth2.Config, token *oauth2.Token, opts ...common.OAuthOption,
) Option

WithClient sets the http client to use for the connector. Saves some boilerplate.

func WithModule

func WithModule(module common.ModuleID) Option

WithModule sets the hubspot API module to use for the connector. It's required.

type SearchParams

type SearchParams struct {
	// The name of the object we are reading, e.g. "Account"
	ObjectName string // required
	// NextPage is an opaque token that can be used to get the next page of results.
	NextPage common.NextPageToken // optional, only set this if you want to read the next page of results
	// SortBy is the field to sort by in the direction specified by SortDirection.
	SortBy []SortBy // optional
	// FilterBy is the filter to apply to the search
	FilterGroups []FilterGroup // optional
	// Fields is the list of fields to return in the result.
	Fields datautils.Set[string] // optional
}

func (SearchParams) ValidateParams

func (p SearchParams) ValidateParams() error

type SortBy

type SortBy struct {
	// The name of the field to sort by.
	PropertyName string `json:"propertyName,omitempty"`
	// The direction to sort by.
	Direction SortDirection `json:"direction,omitempty"`
}

func BuildSort

func BuildSort(field ObjectField, dir SortDirection) SortBy

BuildSort builds a sort by clause for the given field and direction.

type SortDirection

type SortDirection string

Jump to

Keyboard shortcuts

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