Skip to content

Commit

Permalink
feat: search hubspot deals by name
Browse files Browse the repository at this point in the history
  • Loading branch information
protomolequle committed Feb 17, 2025
1 parent d215ef9 commit cef044e
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions deal.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,25 @@ type DealServiceOp struct {
client *Client
}

// DealSearchRequest represents the request body for searching deals.
type DealSearchRequest struct {
FilterGroups []FilterGroup `json:"filterGroups,omitempty"`
}

// DealSearchResponse represents the structure of the response from the deal search endpoint.
type DealSearchResponse struct {
Total int `json:"total,omitempty"`
Results []DealResponse `json:"results,omitempty"`
}

type DealResponse struct {
ID string `json:"id,omitempty"`
Properties Deal `json:"properties,omitempty"`
CreatedAt string `json:"createdAt,omitempty"`
UpdatedAt string `json:"updatedAt,omitempty"`
Archived bool `json:"archived,omitempty"`
}

var _ DealService = (*DealServiceOp)(nil)

// Deal represents a HubSpot deal.
Expand Down Expand Up @@ -137,3 +156,28 @@ func (s *DealServiceOp) AssociateAnotherObj(dealID string, conf *AssociationConf
}
return resource, nil
}

// SearchDeals searches for deals by deal name.
func (s *DealServiceOp) SearchDeals(dealName string) (*DealSearchResponse, error) {
resource := &DealSearchResponse{Total: 0, Results: []DealResponse{}}
req := &DealSearchRequest{
FilterGroups: []FilterGroup{
{
Filters: []Filter{
{
PropertyName: "dealname",
Operator: "EQ",
Value: dealName,
},
},
},
},
}

// Send the POST request to HubSpot API
if err := s.client.Post(dealBasePath+"/search", req, resource); err != nil {
return nil, err
}

return resource, nil
}

0 comments on commit cef044e

Please sign in to comment.