|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SevenShores\Hubspot\Resources; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
class Contacts extends Resource |
|
7
|
|
|
{ |
|
8
|
|
|
/** |
|
9
|
|
|
* @param array $properties Array of contact properties. |
|
10
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
11
|
|
|
*/ |
|
12
|
|
View Code Duplication |
function create($properties) |
|
|
|
|
|
|
13
|
|
|
{ |
|
14
|
|
|
$endpoint = "https://api.hubapi.com/contacts/v1/contact"; |
|
15
|
|
|
|
|
16
|
|
|
$options['json'] = ['properties' => $properties]; |
|
17
|
|
|
|
|
18
|
|
|
return $this->client->request('post', $endpoint, $options); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @param int $id The contact id. |
|
23
|
|
|
* @param array $properties The contact properties to update. |
|
24
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
25
|
|
|
*/ |
|
26
|
|
View Code Duplication |
function update($id, $properties) |
|
|
|
|
|
|
27
|
|
|
{ |
|
28
|
|
|
$endpoint = "https://api.hubapi.com/contacts/v1/contact/vid/{$id}/profile"; |
|
29
|
|
|
|
|
30
|
|
|
$options['json'] = ['properties' => $properties]; |
|
31
|
|
|
|
|
32
|
|
|
return $this->client->request('post', $endpoint, $options); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param string $email The contact's email address. |
|
37
|
|
|
* @param array $properties The contact properties to update. |
|
38
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
39
|
|
|
*/ |
|
40
|
|
View Code Duplication |
function updateByEmail($email, $properties) |
|
|
|
|
|
|
41
|
|
|
{ |
|
42
|
|
|
$endpoint = "https://api.hubapi.com/contacts/v1/contact/email/{$email}/profile"; |
|
43
|
|
|
|
|
44
|
|
|
$options['json'] = ['properties' => $properties]; |
|
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
return $this->client->request('post', $endpoint, $options); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param string $email The contact's email address. |
|
51
|
|
|
* @param array $properties The contact properties. |
|
52
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
53
|
|
|
*/ |
|
54
|
|
View Code Duplication |
function createOrUpdate($email, $properties = []) |
|
|
|
|
|
|
55
|
|
|
{ |
|
56
|
|
|
$endpoint = "https://api.hubapi.com/contacts/v1/contact/createOrUpdate/email/{$email}"; |
|
57
|
|
|
|
|
58
|
|
|
$options['json'] = ['properties' => $properties]; |
|
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
return $this->client->request('post', $endpoint, $options); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param array $contacts The contacts and properties. |
|
65
|
|
|
* @param array $params Array of optional parameters ['auditId'] |
|
66
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
67
|
|
|
*/ |
|
68
|
|
|
function createOrUpdateBatch($contacts, $params = []) |
|
|
|
|
|
|
69
|
|
|
{ |
|
70
|
|
|
$endpoint = "https://api.hubapi.com/contacts/v1/contact/batch"; |
|
71
|
|
|
|
|
72
|
|
|
$queryString = build_query_string($params); |
|
73
|
|
|
|
|
74
|
|
|
$options['json'] = $contacts; |
|
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
return $this->client->request('post', $endpoint, $options, $queryString); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param int $id |
|
81
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
82
|
|
|
*/ |
|
83
|
|
|
function delete($id) |
|
|
|
|
|
|
84
|
|
|
{ |
|
85
|
|
|
$endpoint = "https://api.hubapi.com/contacts/v1/contact/vid/{$id}"; |
|
86
|
|
|
|
|
87
|
|
|
return $this->client->request('delete', $endpoint); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* For a given portal, return all contacts that have been created in the portal. |
|
92
|
|
|
* |
|
93
|
|
|
* A paginated list of contacts will be returned to you, with a maximum of 100 contacts per page. |
|
94
|
|
|
* |
|
95
|
|
|
* Please Note: There are 2 fields here to pay close attention to: the "has-more" field that will let you know |
|
96
|
|
|
* whether there are more contacts that you can pull from this portal, and the "vid-offset" field which will let |
|
97
|
|
|
* you know where you are in the list of contacts. You can then use the "vid-offset" field in the "vidOffset" |
|
98
|
|
|
* parameter described below. |
|
99
|
|
|
* |
|
100
|
|
|
* @see http://developers.hubspot.com/docs/methods/contacts/get_contacts |
|
101
|
|
|
* |
|
102
|
|
|
* @param array $params Array of optional parameters ['count', 'property', 'vidOffset'] |
|
103
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
104
|
|
|
*/ |
|
105
|
|
|
function all($params = []) |
|
|
|
|
|
|
106
|
|
|
{ |
|
107
|
|
|
$endpoint = "https://api.hubapi.com/contacts/v1/lists/all/contacts/all"; |
|
108
|
|
|
|
|
109
|
|
|
$queryString = build_query_string($params); |
|
110
|
|
|
|
|
111
|
|
|
return $this->client->request('get', $endpoint, [], $queryString); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* For a given portal, return all contacts that have been recently updated or created. |
|
116
|
|
|
* A paginated list of contacts will be returned to you, with a maximum of 100 contacts per page, as specified by |
|
117
|
|
|
* the "count" parameter. The endpoint only scrolls back in time 30 days. |
|
118
|
|
|
* |
|
119
|
|
|
* @see http://developers.hubspot.com/docs/methods/contacts/get_recently_updated_contacts |
|
120
|
|
|
* |
|
121
|
|
|
* @param array $params Array of optional parameters ['count', 'timeOffset', 'vidOffset', 'property', |
|
122
|
|
|
* 'propertyMode', 'formSubmissionMode', 'showListMemberships'] |
|
123
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
124
|
|
|
*/ |
|
125
|
|
|
function recent($params = []) |
|
|
|
|
|
|
126
|
|
|
{ |
|
127
|
|
|
$endpoint = "https://api.hubapi.com/contacts/v1/lists/recently_updated/contacts/recent"; |
|
128
|
|
|
|
|
129
|
|
|
$queryString = build_query_string($params); |
|
130
|
|
|
|
|
131
|
|
|
return $this->client->request('get', $endpoint, [], $queryString); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* @param int $id |
|
136
|
|
|
* @param array $params Array of optional parameters ['property', 'propertyMode', 'formSubmissionMode', |
|
137
|
|
|
* 'showListMemberships'] |
|
138
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
139
|
|
|
*/ |
|
140
|
|
|
function getById($id, $params = []) |
|
|
|
|
|
|
141
|
|
|
{ |
|
142
|
|
|
$endpoint = "https://api.hubapi.com/contacts/v1/contact/vid/{$id}/profile"; |
|
143
|
|
|
|
|
144
|
|
|
$queryString = build_query_string($params); |
|
145
|
|
|
|
|
146
|
|
|
return $this->client->request('get', $endpoint, [], $queryString); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* For a given portal, return information about a group of contacts by their unique ID's. A contact's unique ID's |
|
151
|
|
|
* is stored in a field called 'vid' which stands for 'visitor ID'. |
|
152
|
|
|
* |
|
153
|
|
|
* This method will also return you much of the HubSpot lead "intelligence" for each requested contact record. The |
|
154
|
|
|
* endpoint accepts many query parameters that allow for customization based on a variety of integration use cases. |
|
155
|
|
|
* |
|
156
|
|
|
* @see http://developers.hubspot.com/docs/methods/contacts/get_batch_by_vid |
|
157
|
|
|
* |
|
158
|
|
|
* @param array $vids Array of visitor IDs |
|
159
|
|
|
* @param array $params Array of optional parameters ['property', 'propertyMode', 'formSubmissionMode', |
|
160
|
|
|
* 'showListMemberships', 'includeDeletes'] |
|
161
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
162
|
|
|
*/ |
|
163
|
|
|
function getBatchByIds($vids, $params = []) |
|
|
|
|
|
|
164
|
|
|
{ |
|
165
|
|
|
$endpoint = "https://api.hubapi.com/contacts/v1/contact/vids/batch/"; |
|
166
|
|
|
|
|
167
|
|
|
$params['vid'] = $vids; |
|
168
|
|
|
|
|
169
|
|
|
$queryString = build_query_string($params); |
|
170
|
|
|
|
|
171
|
|
|
return $this->client->request('get', $endpoint, [], $queryString); |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* @param string $email |
|
176
|
|
|
* @param array $params Array of optional parameters ['property', 'propertyMode', 'formSubmissionMode', |
|
177
|
|
|
* 'showListMemberships'] |
|
178
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
179
|
|
|
*/ |
|
180
|
|
|
function getByEmail($email, $params = []) |
|
|
|
|
|
|
181
|
|
|
{ |
|
182
|
|
|
$endpoint = "https://api.hubapi.com/contacts/v1/contact/email/{$email}/profile"; |
|
183
|
|
|
|
|
184
|
|
|
$queryString = build_query_string($params); |
|
185
|
|
|
|
|
186
|
|
|
return $this->client->request('get', $endpoint, [], $queryString); |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
/** |
|
190
|
|
|
* For a given portal, return information about a group of contacts by their email addresses. |
|
191
|
|
|
* |
|
192
|
|
|
* This method will also return you much of the HubSpot lead "intelligence" for each requested contact record. The |
|
193
|
|
|
* endpoint accepts many query parameters that allow for customization based on a variety of integration use cases. |
|
194
|
|
|
* |
|
195
|
|
|
* @see http://developers.hubspot.com/docs/methods/contacts/get_batch_by_email |
|
196
|
|
|
* |
|
197
|
|
|
* @param array $emails Array of email adresses |
|
198
|
|
|
* @param array $params Array of optional parameters ['property', 'propertyMode', 'formSubmissionMode', |
|
199
|
|
|
* 'showListMemberships', 'includeDeletes'] |
|
200
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
201
|
|
|
*/ |
|
202
|
|
|
function getBatchByEmails($emails, $params = []) |
|
|
|
|
|
|
203
|
|
|
{ |
|
204
|
|
|
$endpoint = "https://api.hubapi.com/contacts/v1/contact/emails/batch/"; |
|
205
|
|
|
|
|
206
|
|
|
$params['email'] = $emails; |
|
207
|
|
|
|
|
208
|
|
|
$queryString = build_query_string($params); |
|
209
|
|
|
|
|
210
|
|
|
return $this->client->request('get', $endpoint, [], $queryString); |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
/** |
|
214
|
|
|
* @param string $utk |
|
215
|
|
|
* @param array $params Array of optional parameters ['property', 'propertyMode', 'formSubmissionMode', |
|
216
|
|
|
* 'showListMemberships'] |
|
217
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
218
|
|
|
*/ |
|
219
|
|
|
function getByToken($utk, $params = []) |
|
|
|
|
|
|
220
|
|
|
{ |
|
221
|
|
|
$endpoint = "https://api.hubapi.com/contacts/v1/contact/utk/{$utk}/profile"; |
|
222
|
|
|
|
|
223
|
|
|
$queryString = build_query_string($params); |
|
224
|
|
|
|
|
225
|
|
|
return $this->client->request('get', $endpoint, [], $queryString); |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
/** |
|
229
|
|
|
* For a given portal, return information about a group of contacts by their user tokens (hubspotutk). |
|
230
|
|
|
* |
|
231
|
|
|
* This method will also return you much of the HubSpot lead "intelligence" for each requested contact |
|
232
|
|
|
* record. The endpoint accepts many query parameters that allow for customization based on a variety of |
|
233
|
|
|
* integration use cases. |
|
234
|
|
|
* |
|
235
|
|
|
* The endpoint does not allow for CORS, so if you are looking up contacts from their user token on the client, |
|
236
|
|
|
* you'll need to spin up a proxy server to interact with the API. |
|
237
|
|
|
* |
|
238
|
|
|
* @see http://developers.hubspot.com/docs/methods/contacts/get_batch_by_utk |
|
239
|
|
|
* |
|
240
|
|
|
* @param array $utks Array of hubspot user tokens (hubspotutk) |
|
241
|
|
|
* @param array $params Array of optional parameters ['property', 'propertyMode', 'formSubmissionMode', |
|
242
|
|
|
* 'showListMemberships', 'includeDeletes'] |
|
243
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
244
|
|
|
*/ |
|
245
|
|
|
function getBatchByTokens($utks, $params = []) |
|
|
|
|
|
|
246
|
|
|
{ |
|
247
|
|
|
$endpoint = "https://api.hubapi.com/contacts/v1/contact/utks/batch/"; |
|
248
|
|
|
|
|
249
|
|
|
$params['utk'] = $utks; |
|
250
|
|
|
|
|
251
|
|
|
$queryString = build_query_string($params); |
|
252
|
|
|
|
|
253
|
|
|
return $this->client->request('get', $endpoint, [], $queryString); |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
/** |
|
257
|
|
|
* For a given portal, return contacts and some data associated with |
|
258
|
|
|
* those contacts by the contact's email address or name. |
|
259
|
|
|
* |
|
260
|
|
|
* Please note that you should expect this method to only return a small |
|
261
|
|
|
* subset of data about the contact. One piece of data that the method will |
|
262
|
|
|
* return is the contact ID (vid) that you can then use to look up much |
|
263
|
|
|
* more data about that particular contact by its ID. |
|
264
|
|
|
* |
|
265
|
|
|
* @see http://developers.hubspot.com/docs/methods/contacts/search_contacts |
|
266
|
|
|
* |
|
267
|
|
|
* @param string $query Search query |
|
268
|
|
|
* @param array $params Array of optional parameters ['count', 'offset'] |
|
269
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
270
|
|
|
*/ |
|
271
|
|
|
function search($query, $params = []) |
|
|
|
|
|
|
272
|
|
|
{ |
|
273
|
|
|
$endpoint = "https://api.hubapi.com/contacts/v1/search/query"; |
|
274
|
|
|
|
|
275
|
|
|
$params['q'] = $query; |
|
276
|
|
|
|
|
277
|
|
|
$queryString = build_query_string($params); |
|
278
|
|
|
|
|
279
|
|
|
return $this->client->request('get', $endpoint, [], $queryString); |
|
280
|
|
|
} |
|
281
|
|
|
|
|
282
|
|
|
/** |
|
283
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
284
|
|
|
*/ |
|
285
|
|
|
function statistics() |
|
|
|
|
|
|
286
|
|
|
{ |
|
287
|
|
|
$endpoint = "https://api.hubapi.com/contacts/v1/contacts/statistics"; |
|
288
|
|
|
|
|
289
|
|
|
return $this->client->request('get', $endpoint); |
|
290
|
|
|
} |
|
291
|
|
|
|
|
292
|
|
|
/** |
|
293
|
|
|
* Merge two contact records. The contact ID in the URL will be treated as the |
|
294
|
|
|
* primary contact, and the contact ID in the request body will be treated as |
|
295
|
|
|
* the secondary contact. |
|
296
|
|
|
* |
|
297
|
|
|
* @param int $id Primary contact id. |
|
298
|
|
|
* @param int $vidToMerge Contact ID of the secondary contact. |
|
299
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
300
|
|
|
*/ |
|
301
|
|
View Code Duplication |
function merge($id, $vidToMerge) |
|
|
|
|
|
|
302
|
|
|
{ |
|
303
|
|
|
$endpoint = "https://api.hubapi.com/contacts/v1/contact/merge-vids/{$id}/"; |
|
304
|
|
|
|
|
305
|
|
|
$options['json'] = ['vidToMerge' => $vidToMerge]; |
|
|
|
|
|
|
306
|
|
|
|
|
307
|
|
|
return $this->client->request('post', $endpoint, $options); |
|
308
|
|
|
} |
|
309
|
|
|
|
|
310
|
|
|
} |
|
311
|
|
|
|
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.