-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompanies.go
124 lines (108 loc) · 4.2 KB
/
companies.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package hubspot
import (
"context"
"io/ioutil"
"encoding/json"
"time"
)
type CompaniesService service
type SearchCompanies struct {
Query string `json:"query,omitempty"`
Limit int `json:"limit,omitempty"`
After string `json:"after,omitempty"`
Sorts []string `json:"sorts,omitempty"`
Properties []string `json:"properties,omitempty"`
FilterGroups []SearchFilterGroups `json:"filterGroups,omitempty"`
}
type SearchFilterGroups struct {
Filters []SearchFilters `json:"filters,omitempty"`
}
type SearchFilters struct {
HighValue string `json:"highValue,omitempty"`
PropertyName string `json:"propertyName,omitempty"`
Values []string `json:"values,omitempty"`
Value string `json:"value,omitempty"`
Operator string `json:"operator,omitempty"`
}
type SeachCompaniesResponse struct {
Total int `json:"total,omitempty"`
Results []struct {
ID string `json:"id,omitempty"`
Properties struct {
Createdate time.Time `json:"createdate,omitempty"`
Domain string `json:"domain,omitempty"`
HsLastmodifieddate time.Time `json:"hs_lastmodifieddate,omitempty"`
HsObjectID string `json:"hs_object_id,omitempty"`
Name string `json:"name,omitempty"`
} `json:"properties,omitempty"`
CreatedAt time.Time `json:"createdAt,omitempty"`
UpdatedAt time.Time `json:"updatedAt,omitempty"`
Archived bool `json:"archived,omitempty"`
} `json:"results,omitempty"`
}
type PostCompany struct {
Properties *PostCompanyProperties `json:"properties,omitempty"`
}
type PostCompanyProperties struct {
Domain string `json:"domain,omitempty"`
Name string `json:"name,omitempty"`
ATS string `json:"ats,omitempty"`
CompanySize string `json:"company_size,omitempty"`
}
type PostCompanyResponse struct {
ID string `json:"id,omitempty"`
Properties struct {
Ats string `json:"ats,omitempty"`
CompanySize string `json:"company_size,omitempty"`
Createdate time.Time `json:"createdate,omitempty"`
Domain string `json:"domain,omitempty"`
HsLastmodifieddate time.Time `json:"hs_lastmodifieddate,omitempty"`
HsObjectID string `json:"hs_object_id,omitempty"`
HsObjectSource string `json:"hs_object_source,omitempty"`
HsObjectSourceID string `json:"hs_object_source_id,omitempty"`
HsObjectSourceLabel string `json:"hs_object_source_label,omitempty"`
HsPipeline string `json:"hs_pipeline,omitempty"`
Lifecyclestage string `json:"lifecyclestage,omitempty"`
Name string `json:"name,omitempty"`
Website string `json:"website,omitempty"`
} `json:"properties,omitempty"`
CreatedAt time.Time `json:"createdAt,omitempty"`
UpdatedAt time.Time `json:"updatedAt,omitempty"`
Archived bool `json:"archived,omitempty"`
}
func (s *CompaniesService) SearchCompanies(ctx context.Context, mapping *SearchCompanies) (SeachCompaniesResponse, error) {
req, err := s.client.NewRequest("POST", "crm/v3/objects/companies/search", mapping)
var result SeachCompaniesResponse
if err != nil {
return result, err
}
m := new(SearchCompanies)
resp, err := s.client.Do(ctx, req, m)
if err != nil {
return result, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) // response body is []byte
if err := json.Unmarshal(body, &result); err != nil { // Parse []byte to the go struct pointer
return result, err
}
return result, nil
}
func (s *CompaniesService) PostCompany(ctx context.Context, mapping *PostCompany) (PostCompanyResponse, error) {
req, err := s.client.NewRequest("POST", "crm/v3/objects/companies", mapping)
var result PostCompanyResponse
if err != nil {
return result, err
}
m := new(PostCompany)
resp, err := s.client.Do(ctx, req, m)
if err != nil {
return result, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) // response body is []byte
if err := json.Unmarshal(body, &result); err != nil { // Parse []byte to the go struct pointer
return result, err
}
return result, nil
}