Documentation ¶
Overview ¶
Package hubspot is a Go client library for accessing the HubSpot API v3.
Index ¶
- Constants
- Variables
- type Client
- func (c *Client) Create(ctx context.Context, resource string, item map[string]any) error
- func (c *Client) Delete(ctx context.Context, resource, itemID string) error
- func (c *Client) List(ctx context.Context, resource string, opts *ListOptions) (*ListResponse, error)
- func (c *Client) ListByNextLink(ctx context.Context, nextLink string) (*ListResponse, error)
- func (c *Client) Search(ctx context.Context, resource string, request *SearchRequest) (*ListResponse, error)
- func (c *Client) SearchByCreatedBefore(ctx context.Context, resource string, createdBefore time.Time, ...) (*ListResponse, error)
- func (c *Client) SearchByUpdatedAfter(ctx context.Context, resource string, updatedAfter time.Time, limit int, ...) (*ListResponse, error)
- func (c *Client) Update(ctx context.Context, resource, itemID string, item map[string]any) error
- type FieldNotExistError
- type ListOptions
- type ListResponse
- type ListResponsePaging
- type ListResponsePagingNext
- type ListResponseResult
- func (r ListResponseResult) GetCreatedAt(resource string) (time.Time, error)
- func (r ListResponseResult) GetDeletedAt(resource string) (time.Time, error)
- func (r ListResponseResult) GetTimeField(name string) (time.Time, error)
- func (r ListResponseResult) GetUpdatedAt(resource string) (time.Time, error)
- type ResourceUpdatePath
- type SearchRequest
- type SearchRequestFilterGroup
- type SearchRequestFilterGroupFilter
- type SearchRequestSort
- type SearchResource
- type TimestampResource
- type UnexpectedStatusCodeError
- type UnsupportedResourceError
Constants ¶
const ( // ResultsFieldID defines a field key for item ID. ResultsFieldID string = "id" // ResultsFieldCreatedAt defines a field key for item creation date. ResultsFieldCreatedAt string = "createdAt" )
const ( // GTEOperator is a greater then operator for search endpoints. GTEOperator = "GTE" // EQOperator is an equal operator for search endpoints. EQOperator = "EQ" // LTEOperator is a less then or equal to operator for search endpoints. LTEOperator = "LTE" )
const ASCSortDirection = "ASCENDING"
ASCSortDirection stands for ascending sorting order.
Variables ¶
var ResourcesCreatePaths = map[string]string{
"cms.blogs.authors": "/cms/v3/blogs/authors",
"cms.blogs.posts": "/cms/v3/blogs/posts",
"cms.blogs.tags": "/cms/v3/blogs/tags",
"cms.pages.landing": "/cms/v3/pages/landing-pages",
"cms.pages.site": "/cms/v3/pages/site-pages",
"cms.hubdb.tables": "/cms/v3/hubdb/tables",
"cms.urlRedirects": "/cms/v3/url-redirects",
"crm.companies": "/crm/v3/objects/companies",
"crm.contacts": "/crm/v3/objects/contacts",
"crm.deals": "/crm/v3/objects/deals",
"crm.feedbackSubmissions": "/crm/v3/objects/feedback_submissions",
"crm.lineItems": "/crm/v3/objects/line_items",
"crm.products": "/crm/v3/objects/products",
"crm.tickets": "/crm/v3/objects/tickets",
"crm.quotes": "/crm/v3/objects/quotes",
"crm.calls": "/crm/v3/objects/calls",
"crm.emails": "/crm/v3/objects/emails",
"crm.meetings": "/crm/v3/objects/meetings",
"crm.notes": "/crm/v3/objects/notes",
"crm.tasks": "/crm/v3/objects/tasks",
}
ResourcesCreatePaths holds a mapping of supported resources and their create endpoints.
var ResourcesDeletePaths = map[string]string{
"cms.blogs.authors": "/cms/v3/blogs/authors/{objectId}",
"cms.blogs.posts": "/cms/v3/blogs/posts/{objectId}",
"cms.blogs.tags": "/cms/v3/blogs/tags/{objectId}",
"cms.pages.landing": "/cms/v3/pages/landing-pages/{objectId}",
"cms.pages.site": "/cms/v3/pages/site-pages/{objectId}",
"cms.hubdb.tables": "/cms/v3/hubdb/tables/{objectId}/draft",
"cms.urlRedirects": "/cms/v3/url-redirects/{objectId}",
"crm.companies": "/crm/v3/objects/companies/{objectId}",
"crm.contacts": "/crm/v3/objects/contacts/{objectId}",
"crm.deals": "/crm/v3/objects/deals/{objectId}",
"crm.feedbackSubmissions": "/crm/v3/objects/feedback_submissions/{objectId}",
"crm.lineItems": "/crm/v3/objects/line_items/{objectId}",
"crm.products": "/crm/v3/objects/products/{objectId}",
"crm.tickets": "/crm/v3/objects/tickets/{objectId}",
"crm.quotes": "/crm/v3/objects/quotes/{objectId}",
"crm.calls": "/crm/v3/objects/calls/{objectId}",
"crm.emails": "/crm/v3/objects/emails/{objectId}",
"crm.meetings": "/crm/v3/objects/meetings/{objectId}",
"crm.notes": "/crm/v3/objects/notes/{objectId}",
"crm.tasks": "/crm/v3/objects/tasks/{objectId}",
}
ResourcesDeletePaths holds a mapping of supported resources and their delete endpoints.
var ResourcesListPaths = map[string]string{
"cms.blogs.authors": "/cms/v3/blogs/authors",
"cms.blogs.posts": "/cms/v3/blogs/posts",
"cms.blogs.tags": "/cms/v3/blogs/tags",
"cms.pages.landing": "/cms/v3/pages/landing-pages",
"cms.pages.site": "/cms/v3/pages/site-pages",
"cms.hubdb.tables": "/cms/v3/hubdb/tables",
"cms.urlRedirects": "/cms/v3/url-redirects",
"crm.companies": "/crm/v3/objects/companies",
"crm.contacts": "/crm/v3/objects/contacts",
"crm.deals": "/crm/v3/objects/deals",
"crm.feedbackSubmissions": "/crm/v3/objects/feedback_submissions",
"crm.lineItems": "/crm/v3/objects/line_items",
"crm.products": "/crm/v3/objects/products",
"crm.tickets": "/crm/v3/objects/tickets",
"crm.quotes": "/crm/v3/objects/quotes",
"crm.calls": "/crm/v3/objects/calls",
"crm.emails": "/crm/v3/objects/emails",
"crm.meetings": "/crm/v3/objects/meetings",
"crm.notes": "/crm/v3/objects/notes",
"crm.tasks": "/crm/v3/objects/tasks",
}
ResourcesListPaths holds a mapping of supported resources and their list endpoints.
var ResourcesUpdatePaths = map[string]ResourceUpdatePath{ "cms.blogs.authors": { Path: "/cms/v3/blogs/authors/{objectId}", Method: http.MethodPatch, }, "cms.blogs.posts": { Path: "/cms/v3/blogs/posts/{objectId}", Method: http.MethodPatch, }, "cms.blogs.tags": { Path: "/cms/v3/blogs/tags/{objectId}", Method: http.MethodPatch, }, "cms.pages.landing": { Path: "/cms/v3/pages/landing-pages/{objectId}", Method: http.MethodPatch, }, "cms.pages.site": { Path: "/cms/v3/pages/site-pages/{objectId}", Method: http.MethodPatch, }, "cms.hubdb.tables": { Path: "/cms/v3/hubdb/tables/{objectId}/draft", Method: http.MethodPatch, }, "cms.urlRedirects": { Path: "/cms/v3/url-redirects/{objectId}", Method: http.MethodPatch, }, "crm.companies": { Path: "/crm/v3/objects/companies/{objectId}", Method: http.MethodPatch, }, "crm.contacts": { Path: "/crm/v3/objects/contacts/{objectId}", Method: http.MethodPatch, }, "crm.deals": { Path: "/crm/v3/objects/deals/{objectId}", Method: http.MethodPatch, }, "crm.feedbackSubmissions": { Path: "/crm/v3/objects/feedback_submissions/{objectId}", Method: http.MethodPatch, }, "crm.lineItems": { Path: "/crm/v3/objects/line_items/{objectId}", Method: http.MethodPatch, }, "crm.products": { Path: "/crm/v3/objects/products/{objectId}", Method: http.MethodPatch, }, "crm.tickets": { Path: "/crm/v3/objects/tickets/{objectId}", Method: http.MethodPatch, }, "crm.quotes": { Path: "/crm/v3/objects/quotes/{objectId}", Method: http.MethodPatch, }, "crm.calls": { Path: "/crm/v3/objects/calls/{objectId}", Method: http.MethodPatch, }, "crm.emails": { Path: "/crm/v3/objects/emails/{objectId}", Method: http.MethodPatch, }, "crm.meetings": { Path: "/crm/v3/objects/meetings/{objectId}", Method: http.MethodPatch, }, "crm.notes": { Path: "/crm/v3/objects/notes/{objectId}", Method: http.MethodPatch, }, "crm.tasks": { Path: "/crm/v3/objects/tasks/{objectId}", Method: http.MethodPatch, }, }
ResourcesUpdatePaths holds a mapping of supported resources, their update endpoints and HTTP methods.
var SearchResources = map[string]SearchResource{
"crm.companies": {
Path: "/crm/v3/objects/companies/search",
CreatedAtFieldName: "createdAt",
UpdatedAtFieldName: "updatedAt",
CreatedAtSortName: "createdate",
UpdatedAtSortName: "hs_lastmodifieddate",
ObjectIDFilterName: "hs_object_id",
},
"crm.contacts": {
Path: "/crm/v3/objects/contacts/search",
CreatedAtFieldName: "createdAt",
UpdatedAtFieldName: "updatedAt",
CreatedAtSortName: "createdate",
UpdatedAtSortName: "lastmodifieddate",
ObjectIDFilterName: "hs_object_id",
},
"crm.deals": {
Path: "/crm/v3/objects/deals/search",
CreatedAtFieldName: "createdAt",
UpdatedAtFieldName: "updatedAt",
CreatedAtSortName: "createdate",
UpdatedAtSortName: "hs_lastmodifieddate",
ObjectIDFilterName: "hs_object_id",
},
"crm.feedbackSubmissions": {
Path: "/crm/v3/objects/feedback_submissions/search",
CreatedAtFieldName: "createdAt",
UpdatedAtFieldName: "updatedAt",
CreatedAtSortName: "hs_createdate",
UpdatedAtSortName: "hs_lastmodifieddate",
ObjectIDFilterName: "hs_object_id",
},
"crm.lineItems": {
Path: "/crm/v3/objects/line_items/search",
CreatedAtFieldName: "createdAt",
UpdatedAtFieldName: "updatedAt",
CreatedAtSortName: "createdate",
UpdatedAtSortName: "hs_lastmodifieddate",
ObjectIDFilterName: "hs_object_id",
},
"crm.products": {
Path: "/crm/v3/objects/products/search",
CreatedAtFieldName: "createdAt",
UpdatedAtFieldName: "updatedAt",
CreatedAtSortName: "createdate",
UpdatedAtSortName: "hs_lastmodifieddate",
ObjectIDFilterName: "hs_object_id",
},
"crm.tickets": {
Path: "/crm/v3/objects/tickets/search",
CreatedAtFieldName: "createdAt",
UpdatedAtFieldName: "updatedAt",
CreatedAtSortName: "createdate",
UpdatedAtSortName: "hs_lastmodifieddate",
ObjectIDFilterName: "hs_object_id",
},
"crm.quotes": {
Path: "/crm/v3/objects/quotes/search",
CreatedAtFieldName: "createdAt",
UpdatedAtFieldName: "updatedAt",
CreatedAtSortName: "hs_createdate",
UpdatedAtSortName: "hs_lastmodifieddate",
ObjectIDFilterName: "hs_object_id",
},
"crm.calls": {
Path: "/crm/v3/objects/calls/search",
CreatedAtFieldName: "createdAt",
UpdatedAtFieldName: "updatedAt",
CreatedAtSortName: "hs_createdate",
UpdatedAtSortName: "hs_lastmodifieddate",
ObjectIDFilterName: "hs_object_id",
},
"crm.emails": {
Path: "/crm/v3/objects/emails/search",
CreatedAtFieldName: "createdAt",
UpdatedAtFieldName: "updatedAt",
CreatedAtSortName: "hs_createdate",
UpdatedAtSortName: "hs_lastmodifieddate",
ObjectIDFilterName: "hs_object_id",
},
"crm.meetings": {
Path: "/crm/v3/objects/meetings/search",
CreatedAtFieldName: "createdAt",
UpdatedAtFieldName: "updatedAt",
CreatedAtSortName: "hs_createdate",
UpdatedAtSortName: "hs_lastmodifieddate",
ObjectIDFilterName: "hs_object_id",
},
"crm.notes": {
Path: "/crm/v3/objects/notes/search",
CreatedAtFieldName: "createdAt",
UpdatedAtFieldName: "updatedAt",
CreatedAtSortName: "hs_createdate",
UpdatedAtSortName: "hs_lastmodifieddate",
ObjectIDFilterName: "hs_object_id",
},
"crm.tasks": {
Path: "/crm/v3/objects/tasks/search",
CreatedAtFieldName: "createdAt",
UpdatedAtFieldName: "updatedAt",
CreatedAtSortName: "hs_createdate",
UpdatedAtSortName: "hs_lastmodifieddate",
ObjectIDFilterName: "hs_object_id",
},
}
SearchResources holds a mapping of resources that have search endpoints.
var TimestampResources = map[string]TimestampResource{
"cms.blogs.authors": {
CreatedAtFieldName: "created",
UpdatedAtFieldName: "updated",
DeletedAtFieldName: "deletedAt",
},
"cms.blogs.posts": {
CreatedAtFieldName: "created",
UpdatedAtFieldName: "updated",
DeletedAtFieldName: "deletedAt",
},
"cms.blogs.tags": {
CreatedAtFieldName: "created",
UpdatedAtFieldName: "updated",
DeletedAtFieldName: "deletedAt",
},
"cms.pages.landing": {
CreatedAtFieldName: "createdAt",
UpdatedAtFieldName: "updatedAt",
DeletedAtFieldName: "deletedAt",
},
"cms.pages.site": {
CreatedAtFieldName: "createdAt",
UpdatedAtFieldName: "updatedAt",
DeletedAtFieldName: "deletedAt",
},
"cms.hubdb.tables": {
CreatedAtFieldName: "createdAt",
UpdatedAtFieldName: "updatedAt",
},
"cms.urlRedirects": {
CreatedAtFieldName: "createdAt",
UpdatedAtFieldName: "updatedAt",
},
}
TimestampResources holds a list of resources that support timestamp-based filtering.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
A Client manages communication with the HubSpot API.
func (*Client) Create ¶
Create creates a new item of a specific resource. The method raises an *UnsupportedResourceError if a provided resource is unsupported.
func (*Client) Delete ¶
Delete tries to dekete an existing item of a specific resource. The method raises an *UnsupportedResourceError if a provided resource is unsupported.
func (*Client) List ¶
func (c *Client) List(ctx context.Context, resource string, opts *ListOptions) (*ListResponse, error)
List retrieves a list of items of a specific resource. The method raises an *UnsupportedResourceError if a provided resource is unsupported. If everything is okay, the method will return a *ListResponse.
func (*Client) ListByNextLink ¶
ListByNextLink retrieves a list of items by a next link. It doesn't require specifying filters and resources manually.
func (*Client) Search ¶
func (c *Client) Search(ctx context.Context, resource string, request *SearchRequest) (*ListResponse, error)
Search performs an object search with filtering and returns the ListResponse.
func (*Client) SearchByCreatedBefore ¶
func (c *Client) SearchByCreatedBefore( ctx context.Context, resource string, createdBefore time.Time, limit, after int, properties []string, ) (*ListResponse, error)
SearchByCreatedBefore is a wrapper that calls the [Search] method returning only those results that were created before a specific date and ordering them ascendingly by createdAt field.
func (*Client) SearchByUpdatedAfter ¶
func (c *Client) SearchByUpdatedAfter( ctx context.Context, resource string, updatedAfter time.Time, limit int, properties []string, ) (*ListResponse, error)
SearchByUpdatedAfter is a wrapper that calls the [Search] method returning only those results that were updated after a specific date and ordering them ascendingly by updatedAt field.
type FieldNotExistError ¶
type FieldNotExistError struct {
FieldName string
}
FieldNotExistError occurs when trying to get a field by a field name that doesn't exist within a map.
func (*FieldNotExistError) Error ¶
func (e *FieldNotExistError) Error() string
Error returns a formated error message for the FieldNotExistError.
type ListOptions ¶
type ListOptions struct { Limit int `url:"limit,omitempty"` After string `url:"after,omitempty"` CreatedAfter *time.Time `url:"createdAfter,omitempty" layout:"2006-01-02T15:04:05.000Z"` UpdatedAfter *time.Time `url:"updatedAfter,omitempty" layout:"2006-01-02T15:04:05.000Z"` CreatedBefore *time.Time `url:"createdBefore,omitempty" layout:"2006-01-02T15:04:05.000Z"` Sort string `url:"sort,omitempty"` Archived bool `url:"archived,omitempty"` }
ListOptions holds optional params for the [List] method.
type ListResponse ¶
type ListResponse struct { Total int `json:"total,omitempty"` Results []ListResponseResult `json:"results"` Paging *ListResponsePaging `json:"paging,omitempty"` }
ListResponse is a common response model for endpoints that returns a list of results. It consists of a results list, paging info, and the total number of items.
type ListResponsePaging ¶
type ListResponsePaging struct {
Next ListResponsePagingNext `json:"next"`
}
ListResponsePaging is a paging info model for the ListResponse.
type ListResponsePagingNext ¶
ListResponsePagingNext is a next model for the ListResponsePaging.
type ListResponseResult ¶
ListResponseResult is a result object for the ListResponse.
func (ListResponseResult) GetCreatedAt ¶
func (r ListResponseResult) GetCreatedAt(resource string) (time.Time, error)
GetCreatedAt returns the item's createdAt field value.
func (ListResponseResult) GetDeletedAt ¶
func (r ListResponseResult) GetDeletedAt(resource string) (time.Time, error)
GetDeletedAt returns the item's deletedAt field value.
func (ListResponseResult) GetTimeField ¶
func (r ListResponseResult) GetTimeField(name string) (time.Time, error)
GetTimeField returns a field by a provided field name and parses it into time.Time.
func (ListResponseResult) GetUpdatedAt ¶
func (r ListResponseResult) GetUpdatedAt(resource string) (time.Time, error)
GetUpdatedAt returns the item's updatedAt field value.
type ResourceUpdatePath ¶
ResourceUpdatePath holds a path and a corresponding method for updating a specific resource.
type SearchRequest ¶
type SearchRequest struct { Limit string `json:"limit,omitempty"` Properties []string `json:"properties,omitempty"` FilterGroups []SearchRequestFilterGroup `json:"filterGroups,omitempty"` Sorts []SearchRequestSort `json:"sorts,omitempty"` }
SearchRequest is a request model for the [Search] method.
type SearchRequestFilterGroup ¶
type SearchRequestFilterGroup struct {
Filters []SearchRequestFilterGroupFilter `json:"filters"`
}
SearchRequestFilterGroup is a fiterGroup object for the SearchRequest.
type SearchRequestFilterGroupFilter ¶
type SearchRequestFilterGroupFilter struct { PropertyName string `json:"propertyName"` Operator string `json:"operator"` Value string `json:"value"` }
SearchRequestFilterGroupFilter is a filter object for the SearchRequestFilterGroup.
type SearchRequestSort ¶
type SearchRequestSort struct { PropertyName string `json:"propertyName"` Direction string `json:"direction"` }
SearchRequestSort is a sort object for the SearchRequest.
type SearchResource ¶
type SearchResource struct { Path string CreatedAtFieldName string UpdatedAtFieldName string CreatedAtSortName string UpdatedAtSortName string ObjectIDFilterName string }
SearchResource holds a path, createdAt, and updatedAt field names.
type TimestampResource ¶
type TimestampResource struct { CreatedAtFieldName string UpdatedAtFieldName string DeletedAtFieldName string }
TimestampResource holds a createdAt, and updatedAt field names.
type UnexpectedStatusCodeError ¶
UnexpectedStatusCodeError occurs when a response from the HubSpot API has non-200 status code.
func (*UnexpectedStatusCodeError) Error ¶
func (e *UnexpectedStatusCodeError) Error() string
Error returns a formated error message for the UnexpectedStatusCodeError.
type UnsupportedResourceError ¶
type UnsupportedResourceError struct {
Resource string
}
UnsupportedResourceError occurs when an unsupported resource is provided.
func (*UnsupportedResourceError) Error ¶
func (e *UnsupportedResourceError) Error() string
Error returns a formated error message for the UnsupportedResourceError.