|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SevenShores\Hubspot\Resources; |
|
4
|
|
|
|
|
5
|
|
|
class Companies extends Resource |
|
6
|
|
|
{ |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Create a company |
|
10
|
|
|
* @param array $properties Array of company properties. |
|
11
|
|
|
* |
|
12
|
|
|
* @see http://developers.hubspot.com/docs/methods/companies/create_company |
|
13
|
|
|
* |
|
14
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
15
|
|
|
*/ |
|
16
|
|
View Code Duplication |
function create($properties) |
|
|
|
|
|
|
17
|
|
|
{ |
|
18
|
|
|
$endpoint = 'https://api.hubapi.com/companies/v2/companies/'; |
|
19
|
|
|
$options['json'] = ['properties' => $properties]; |
|
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
return $this->client->request('post', $endpoint, $options); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Updates a company |
|
26
|
|
|
* @param int $id The company id. |
|
27
|
|
|
* @param array $properties The company properties to update. |
|
28
|
|
|
* |
|
29
|
|
|
* @see http://developers.hubspot.com/docs/methods/companies/update_company |
|
30
|
|
|
* |
|
31
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
32
|
|
|
*/ |
|
33
|
|
View Code Duplication |
function update($id, $properties) |
|
|
|
|
|
|
34
|
|
|
{ |
|
35
|
|
|
$endpoint = "https://api.hubapi.com/companies/v2/companies/{$id}"; |
|
36
|
|
|
$options['json'] = ['properties' => $properties]; |
|
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
return $this->client->request('put', $endpoint, $options); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Deletes a company |
|
43
|
|
|
* @param int $id The company id |
|
44
|
|
|
* |
|
45
|
|
|
* @see http://developers.hubspot.com/docs/methods/companies/delete_company |
|
46
|
|
|
* |
|
47
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
48
|
|
|
*/ |
|
49
|
|
|
function delete($id) |
|
|
|
|
|
|
50
|
|
|
{ |
|
51
|
|
|
$endpoint = "https://api.hubapi.com/companies/v2/companies/{$id}"; |
|
52
|
|
|
|
|
53
|
|
|
return $this->client->request('delete', $endpoint); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Returns all companies |
|
58
|
|
|
* @param array $params Array of optional parameters ['limit', 'offset', 'properties'] |
|
59
|
|
|
* |
|
60
|
|
|
* @see http://developers.hubspot.com/docs/methods/companies/get-all-companies |
|
61
|
|
|
* |
|
62
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
63
|
|
|
*/ |
|
64
|
|
View Code Duplication |
function all($params = []) |
|
|
|
|
|
|
65
|
|
|
{ |
|
66
|
|
|
$endpoint = 'https://api.hubapi.com/companies/v2/companies/paged'; |
|
67
|
|
|
|
|
68
|
|
|
$queryString = build_query_string($params); |
|
69
|
|
|
|
|
70
|
|
|
return $this->client->request('get', $endpoint, [], $queryString); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Returns the recently modified companies |
|
75
|
|
|
* @param array $params Array of optional parameters ['count', 'offset'] |
|
76
|
|
|
* |
|
77
|
|
|
* @see http://developers.hubspot.com/docs/methods/companies/get_companies_modified |
|
78
|
|
|
* |
|
79
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
80
|
|
|
*/ |
|
81
|
|
View Code Duplication |
function getRecentlyModified($params = []) |
|
|
|
|
|
|
82
|
|
|
{ |
|
83
|
|
|
$endpoint = 'https://api.hubapi.com/companies/v2/companies/recent/modified'; |
|
84
|
|
|
|
|
85
|
|
|
$queryString = build_query_string($params); |
|
86
|
|
|
|
|
87
|
|
|
return $this->client->request('get', $endpoint, [], $queryString); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Returns the recently created companies |
|
92
|
|
|
* @param array $params Array of optional parameters ['count', 'offset'] |
|
93
|
|
|
* |
|
94
|
|
|
* @see http://developers.hubspot.com/docs/methods/companies/get_companies_created |
|
95
|
|
|
* |
|
96
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
97
|
|
|
*/ |
|
98
|
|
|
function getRecentlyCreated($params = []) |
|
|
|
|
|
|
99
|
|
|
{ |
|
100
|
|
|
$endpoint = 'https://api.hubapi.com/companies/v2/companies/recent/created'; |
|
101
|
|
|
|
|
102
|
|
|
$queryString = build_query_string($params); |
|
103
|
|
|
|
|
104
|
|
|
return $this->client->request('get', $endpoint, [], $queryString); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Returns an array of companies that have a matching domain |
|
109
|
|
|
* @param string $domain The domain of the company eq. 'example.com'. |
|
110
|
|
|
* |
|
111
|
|
|
* @see http://developers.hubspot.com/docs/methods/companies/get_companies_by_domain |
|
112
|
|
|
* |
|
113
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
114
|
|
|
*/ |
|
115
|
|
|
function getByDomain($domain) |
|
|
|
|
|
|
116
|
|
|
{ |
|
117
|
|
|
$endpoint = "https://api.hubapi.com/companies/v2/companies/domain/{$domain}"; |
|
118
|
|
|
|
|
119
|
|
|
return $this->client->request('get', $endpoint); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @param string $domain |
|
124
|
|
|
* @param array $properties |
|
125
|
|
|
* @param int $limit |
|
126
|
|
|
* @param int $offset |
|
127
|
|
|
* |
|
128
|
|
|
* @see https://developers.hubspot.com/docs/methods/companies/search_companies_by_domain |
|
129
|
|
|
* |
|
130
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\SevenShores\Hubspot\Http\Response |
|
131
|
|
|
*/ |
|
132
|
|
|
public function searchByDomain($domain, $properties = [], $limit = 100, $offset = 0) |
|
133
|
|
|
{ |
|
134
|
|
|
$endpoint = "https://api.hubapi.com/companies/v2/domains/{$domain}/companies"; |
|
135
|
|
|
$options['json'] = [ |
|
|
|
|
|
|
136
|
|
|
'limit' => $limit, |
|
137
|
|
|
'offset' => [ |
|
138
|
|
|
'isPrimary' => true, |
|
139
|
|
|
'companyId' => $offset |
|
140
|
|
|
], |
|
141
|
|
|
'requestOptions' => [ |
|
142
|
|
|
'properties' => $properties |
|
143
|
|
|
] |
|
144
|
|
|
]; |
|
145
|
|
|
return $this->client->request('post', $endpoint, $options); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* Returns a company with id $id |
|
150
|
|
|
* @param int $id |
|
151
|
|
|
* |
|
152
|
|
|
* @see http://developers.hubspot.com/docs/methods/companies/get_company |
|
153
|
|
|
* |
|
154
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
155
|
|
|
*/ |
|
156
|
|
|
function getById($id) |
|
|
|
|
|
|
157
|
|
|
{ |
|
158
|
|
|
$endpoint = "https://api.hubapi.com/companies/v2/companies/{$id}"; |
|
159
|
|
|
|
|
160
|
|
|
return $this->client->request('get', $endpoint); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* Associates a given contact to a given company |
|
165
|
|
|
* If a contact is already associated to a different company, the contact will be added to the new company |
|
166
|
|
|
* @param int $contactId |
|
167
|
|
|
* @param int $companyId |
|
168
|
|
|
* |
|
169
|
|
|
* @see http://developers.hubspot.com/docs/methods/companies/add_contact_to_company |
|
170
|
|
|
* |
|
171
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
172
|
|
|
*/ |
|
173
|
|
|
function addContact($contactId, $companyId) |
|
|
|
|
|
|
174
|
|
|
{ |
|
175
|
|
|
$endpoint = "https://api.hubapi.com/companies/v2/companies/{$companyId}/contacts/{$contactId}"; |
|
176
|
|
|
|
|
177
|
|
|
return $this->client->request('put', $endpoint); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* Returns an array of the associated contacts for the given company |
|
182
|
|
|
* @param int $companyId The id of the company. |
|
183
|
|
|
* @param array $params Array of optional parameters ['count', 'vidOffset'] |
|
184
|
|
|
* |
|
185
|
|
|
* @see http://developers.hubspot.com/docs/methods/companies/get_company_contacts |
|
186
|
|
|
* |
|
187
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
188
|
|
|
*/ |
|
189
|
|
|
function getAssociatedContacts($companyId, $params = []) |
|
|
|
|
|
|
190
|
|
|
{ |
|
191
|
|
|
$endpoint = "https://api.hubapi.com/companies/v2/companies/{$companyId}/contacts"; |
|
192
|
|
|
|
|
193
|
|
|
$queryString = build_query_string($params); |
|
194
|
|
|
|
|
195
|
|
|
return $this->client->request('get', $endpoint, [], $queryString); |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* Returns all of the contact IDs who are associated with the given company |
|
200
|
|
|
* @param int $companyId The id of the company. |
|
201
|
|
|
* @param array $params Array of optional parameters ['count', 'vidOffset'] |
|
202
|
|
|
* |
|
203
|
|
|
* @see http://developers.hubspot.com/docs/methods/companies/get_company_contacts_by_id |
|
204
|
|
|
* |
|
205
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
206
|
|
|
*/ |
|
207
|
|
|
function getAssociatedContactIds($companyId, $params = []) |
|
|
|
|
|
|
208
|
|
|
{ |
|
209
|
|
|
$endpoint = "https://api.hubapi.com/companies/v2/companies/{$companyId}/vids"; |
|
210
|
|
|
|
|
211
|
|
|
$queryString = build_query_string($params); |
|
212
|
|
|
|
|
213
|
|
|
return $this->client->request('get', $endpoint, [], $queryString); |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* Removes a contact from a company |
|
218
|
|
|
* @param int $contactId |
|
219
|
|
|
* @param int $companyId |
|
220
|
|
|
* |
|
221
|
|
|
* @see http://developers.hubspot.com/docs/methods/companies/remove_contact_from_company |
|
222
|
|
|
* |
|
223
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
224
|
|
|
*/ |
|
225
|
|
|
function removeContact($contactId, $companyId) |
|
|
|
|
|
|
226
|
|
|
{ |
|
227
|
|
|
$endpoint = "https://api.hubapi.com/companies/v2/companies/{$companyId}/contacts/{$contactId}"; |
|
228
|
|
|
|
|
229
|
|
|
return $this->client->request('delete', $endpoint); |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
|
|
233
|
|
|
|
|
234
|
|
|
} |
|
235
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.