forked from HubSpot/haPiHP
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.php
468 lines (363 loc) · 18.2 KB
/
example.php
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
<?php
/**
* Copyright 2011 HubSpot, Inc.
*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
require_once 'class.leads.php';
require_once 'class.settings.php';
//require_once 'class.events.php';
require_once 'class.leadnurturing.php';
require_once 'class.prospects.php';
require_once 'class.keywords.php';
require_once 'class.blog.php';
require_once 'class.contacts.php';
require_once 'class.workflows.php';
require_once 'class.forms.php';
require_once 'class.lists.php';
require_once 'class.properties.php';
require_once 'class.socialmedia.php';
$HAPIKey = 'demo';
$access_token = 'demooooo-oooo-oooo-oooo-oooooooooooo';
/*
//Exercise Blog API
$blogs = new HubSpot_Blog($HAPIKey);
$content_type = 'json';
//List blogs for a specific portal (API key)
$params = array('max'=>1);
print_r($blogs->get_blogs($params, $content_type));
//Get info about a specific blog
$params = array();
print_r($blogs->get_blog($params, '0d61e4ca-e395-4c1c-8766-afaa48bf68db', $content_type));
//List posts for a specific blog
$params = array('max'=>2);
print_r($blogs->get_posts($params, '0d61e4ca-e395-4c1c-8766-afaa48bf68db', $content_type));
//List comments for a specific blog
$params = array('max'=>2);
print_r($blogs->get_comments($params, '0d61e4ca-e395-4c1c-8766-afaa48bf68db', $content_type));
//Get information about a specific blog post
$params = array();
print_r($blogs->get_post($params, '71e3900b-c02e-420f-9686-49a1706d56a2', $content_type));
//List comments for a specific post
$params = array();
print_r($blogs->get_post_comments($params, '71e3900b-c02e-420f-9686-49a1706d56a2', $content_type));
//Get information about a specific comment
$params = array();
print_r($blogs->get_comment($params, 'a180af6e-39ea-46f2-a751-c56312d48269', $content_type));
//Create a blog post in a specific blog
$tags = array('hapihp tag 1', 'hapihp tag 2');
echo $blogs->create_post('0d61e4ca-e395-4c1c-8766-afaa48bf68db', 'Test Author', '[email protected]', 'find this one', 'testing hapihp summary', 'this is the content for testing hapihp', $tags);
//Update a blog post, identified by its guid
$tags = array('hapihp updated tag 1', 'hapihp updated tag 2');
$keywords = array('i am','a keyword','wow','really?');
//($post_guid, $title, $summary, $post_content, $tags, $meta_desc, $keywords)
echo $blogs->update_post('ae15391a-7bd9-454d-b51b-5c480a010497', 'new improves Updated title', 'updated summary', 'updated content', $tags, 'updated meta desc', $keywords);
//Publish a blog post
date_default_timezone_set('America/New_York');
$future = date('G');
if ($future < 23) {
$future = $future + 1;
} else {
$future = 1;
}
$days = date('Y-m-d');
$times = date('i:s');
$publish_time = $days.'T'.$future.':'.$times.'Z';
echo $blogs->publish_post('ae15391a-7bd9-454d-b51b-5c480a010497', $publish_time, 'false');
//Create a blog comment
echo $blogs->create_comment('ae15391a-7bd9-454d-b51b-5c480a010497', 'hapihp comment Author', '[email protected]', 'http://hubspot.com', 'hapihp test comment created a new one now');
//Exercise Leads API
$leads = new HubSpot_Leads($HAPIKey);
//Get list of leads
$params = array('max'=>5, 'excludeConversionEvents'=>'true');
print_r($leads->get_leads($params));
//Get specific lead
$lead = $leads->get_lead('8a41f2f22913e087012913e0b4b90011');
echo $lead->guid;
//Update a lead
$newvalues = array('firstName'=>'from','lastName'=>'haPiHP');
echo $leads->update_lead('8a41f2f22913e087012913e0b4b90011',$newvalues);
//Close a lead
echo $leads->close_lead('8a41f2f22913e087012913e0b4b90011',1234567890123);
//Add a lead
$postValues = array('email'=>'[email protected]',
'firstName'=>'Posted',
'lastName'=>'By',
'company'=>'haPiHP');
echo $leads->add_lead('http://demohubapi.app6.hubspot.com/?app=leaddirector&FormName=testform', $postValues);
//List Webhooks
print_r($leads->get_webhooks());
//Register Webhook
echo $leads->register_webhook('https://www.example.com');
//Exercise Settings API
$settings = new HubSpot_Settings($HAPIKey);
//Get all settings
print_r($settings->get_settings());
//Get a specific setting
print_r($settings->get_setting('facebeezy'));
//Update a setting
echo $settings->update_setting('BenSmith','true');
echo $settings->delete_setting('BenSmith');
//Exercise Marketing Events API
$events = new HubSpot_Events($HAPIKey);
//Get all events
print_r($events->get_events());
//Add an event
echo $events->add_event('This is my test event',null,'http://www.test.com', 'test');
//Exercise Lead Nurturing API
$nurture = new HubSpot_LeadNurturing($HAPIKey);
//Get all campaigns
print_r($nurture->get_campaigns(false));
//Get members for campaign
print_r($nurture->get_campaign_members('2bb746ad-182f-4a47-a363-5668246f9ce2'));
//Get campaign history for a lead
print_r($nurture->get_campaign_history('8a706adf33a131b40133a1323f46000d'));
//Exercise Prospects API
$prospects = new HubSpot_Prospects($HAPIKey);
//Get prospects timeline
print_r($prospects->get_timeline(null));
//Get org details
print_r($prospects->get_organization_details('murphx innovative solutions'));
//Get typeahead results
print_r($prospects->get_typeahead('murph'));
//Get search results
print_r($prospects->get_search_results('country', 'united kingdom'));
//Add a filter
echo $prospects->add_filter('someorg');
//List filters
print_r($prospects->get_filters());
//Delete a filter
echo $prospects->delete_filter('someorg');
//Exercise Keywords API
$keywords = new HubSpot_Keywords($HAPIKey);
//Add keyword
$addedKeyword = json_decode($keywords->add_keyword('hapiphp'));
print_r($addedKeyword);
$addedGuid = $addedKeyword->keywords[0]->keyword_guid;
//Get list of keywords
print_r($keywords->get_keywords());
//Get specific keyword
print_r($keywords->get_keyword($addedGuid));
//Delete specific keyword
echo $keywords->delete_keyword($addedGuid);
*/
//Excercise Contacts API
/* $contacts = new HubSpot_Contacts($HAPIKey);
$unique_email = 'testemail+'.uniqid().'@emailtest.com';
//Create Contact
$params = array('email' => $unique_email, 'firstname' => 'Webster' );
$createdContact = $contacts->create_contact($params);
print_r($createdContact);
$newly_created_vid = $createdContact->{'vid'};
//Update Contact
$params = array('lastname' => 'Gordon' );
$updatedContact = $contacts->update_contact($newly_created_vid,$params);
print_r($updatedContact);
//Delete Contact
$deletedContact = $contacts->delete_contact($newly_created_vid);
print_r($deletedContact);
//Get all Contacts
$contacts_batch1 = $contacts->get_all_contacts();
print_r($contacts_batch1);
$offset = $contacts_batch1->{'vid-offset'};
$contacts_batch2 = $contacts->get_all_contacts(array('vidOffset'=>$offset));
print_r($contacts_batch2);
//Get recent Contacts
$contacts_recent_batch1 = $contacts->get_recent_contacts();
print_r($contacts_recent_batch1);
$offset = $contacts_recent_batch1->{'vid-offset'};
$contacts_recent_batch2 = $contacts->get_recent_contacts(array('vidOffset'=>$offset));
print_r($contacts_recent_batch2);
//Get Contact by ID, email, usertoken
$contactByID = $contacts->get_contact_by_id('151682');
print_r($contactByID);
$contactByEmail = $contacts->get_contact_by_email('[email protected]');
print_r($contactByEmail);
$contactByUsertoken = $contacts->get_contact_by_usertoken('770f8023b3e6b10fc080155c4ebdfc0e');
print_r($contactByUsertoken);
//Search Contacts
$contactsSearchResult = $contacts->search_contacts(array('q'=>'test'));
print_r($contactsSearchResult);
//Get Contacts statistics
$contactsStats = $contacts->get_contacts_statistics();
print_r($contactsStats);
//Exercise Workflows API
$workflows = new HubSpot_Workflows($HAPIKey);
//Get all Workflows
$all_workflows = $workflows->get_all_workflows();
print_r($all_workflows);
//Get Workflow by ID
$workflow_from_id = $workflows->get_workflow_by_ID('23525');
print_r($workflow_from_id);
//Enroll contact in Workflow
$enrolled_contact = $workflows->enroll_contact_in_workflow('23525','[email protected]');
print_r($enrolled_contact);
//Unenroll contact from Workflow
$unenrolled_contact = $workflows->unenroll_contact_from_workflow('23525','[email protected]');
print_r($unenrolled_contact);
//Get current enrollments for Contact
$contact_enrollments = $workflows->get_current_enrollments('151421');
print_r($contact_enrollments);
//Get log events for contact by ID in Workflow by ID
$workflow_logs = $workflows->get_log_events('23525','151421');
print_r($workflow_logs);
//Get upcoming events for contact by ID in Workflow by ID
$workflow_upcoming = $workflows->get_upcoming_events('23525','151421');
print_r($workflow_upcoming);
//Exercise Forms API
$forms = new HubSpot_Forms($HAPIKey);
$uid = uniqid();
$form_data = array('name'=>'Test Form'.$uid, 'method'=>'POST', 'submitText'=>'Sign Up','notifyRecipients'=>'[email protected]' );
$fields = array(array('name'=>'firstname','label'=>'First Name','description'=>'test field','groupName'=>'contactInformation','type'=>'string','fieldType'=>'text',
'displayOrder'=>0,'required'=>'true','enabled'=>'true','hidden'=>'false','defaultValue'=>'','isSmartField'=>'false','options'=>null,'selectedOptions'=>null),
array('name'=>'email','label'=>'Email','groupName'=>'contactInformation','type'=>'string','fieldType'=>'text',
'displayOrder'=>1,'required'=>'true','enabled'=>'true','hidden'=>'false','defaultValue'=>'','options'=>null));
//Create a form
$new_form = $forms->create_form($form_data,$fields);
print_r($new_form);
$new_form_guid = $new_form->{'guid'};
//Get all forms
//$all_forms = $forms->get_forms();
//print_r($all_forms);
//Update Form
$update_form_data = array('name'=>'Updated test form name'.$uid);
$updated_form = $forms->update_form($new_form_guid,$update_form_data,$fields);
print_r($updated_form);
//Get Form by ID
$specific_form = $forms->get_form_by_id($new_form_guid);
print_r($specific_form);
//Get form fields
$form_fields = $forms->get_form_fields($new_form_guid);
print_r($form_fields);
//Get specific form field
// $specific_form_field = $forms->get_single_form_field($new_form_guid,'firstname');
//print_r($specific_form_field);
//Submit a form
$submitted_form_fields = array('firstname'=>'Webster','lastname'=>'Gordon','email'=>'newtestemail'.$uid.'@testing.com');
$hs_context = array('hutk'=>'12345678'.$uid,'ipAddress'=>'1.2.3.4','pageUrl'=>'http://demo.hubapi.com/contact',
'pageName'=>'Contact Us','redirectUrl'=>'http://demo.hubapi.com/thank-you');
$submitted_form = $forms->submit_form('62515',$new_form_guid,$submitted_form_fields,$hs_context);
print_r($submitted_form);
//Delete a Form
$deleted_form = $forms->delete_form($new_form_guid);
print_r($deleted_form);
*/
//Exercise Lists API
$lists = new HubSpot_Lists(array('access_token'=>$access_token));
//Create a contact List
$list_array = array('name'=>'Tweeters','dynamic'=>false,'portalId'=>'62515','filters'=>
array(array(array('operator'=>'IS_NOT_EMPTY','property'=>'twitterhandle','type'=>'string'))));
$new_list = $lists->create_list($list_array);
$list_id = $new_list->{'listId'};
print_r($new_list);
//Update a contact List
$updated_list_array = array('name'=>'Tweeters and Hubspotters','dynamic'=>false,'portalId'=>'62515','filters'=>
array(array(array('operator'=>'IS_NOT_EMPTY','property'=>'twitterhandle','type'=>'string'),
array('operator'=>'EQ','value'=>'Hubspot','property'=>'company','type'=>'string'))));
$updated_list = $lists->update_list($list_id,$updated_list_array);
print_r($updated_list);
//Get List by ID
print_r($lists->get_list($list_id));
//Get Lists
$some_lists = $lists->get_lists(array('offset'=>5));
var_dump($some_lists);
//Get Static Lists
$static_lists = $lists->get_static_lists(null);
print_r($static_lists);
//Get dynamic Lists
$dynamic_lists = $lists->get_dynamic_lists(null);
print_r($dynamic_lists);
//Get Contacts from List
$contacts_from_list = $lists->get_contacts_in_list(null,$list_id);
print_r($contacts_from_list);
if($contacts_from_list->{'has-more'}){
$next_contacts_batch = $lists->get_contacts_in_list(array('vidOffset'=>$contacts_from_list->{'vid-offset'}));
print_r($next_contacts_batch);
}
//Get recent Contacts from List
$recent_contacts = $lists->get_recent_contacts_in_list(null,$list_id);
print_r($recent_contacts);
//Refresh list
$refreshed_list = $lists->refresh_list($list_id);
print_r($refreshed_list);
//Add contact to List
$contacts_to_add = array(152842,152843);
$added_contacts = $lists->add_contacts_to_list($contacts_to_add,$list_id);
print_r($added_contacts);
//Remove contacts from List
$removed_contacts = $lists->remove_contacts_from_list(array(152842),$list_id);
print_r($removed_contacts);
//Delete List
$deleted_list = $lists->delete_list($list_id);
print_r($deleted_list);
//Exercise Properties API
$properties = new HubSpot_Properties(array('HAPIKey'=>$HAPIKey));
//Get all Properties
$all_props = $properties->get_all_properties();
print_r($all_props);
//Create new Property
$new_prop_info = array('label'=>'Favorite Boston NBA Team','name'=>'favbostonnbateam','description'=>'Your favorite NBA team in the Boston Area',
'groupName'=>'contactinformation','type'=>'enumeration','fieldType'=>'checkbox','formField'=>'true','displayOrder'=>0,
'options'=>array(array('label'=>'Boston Celtics','value'=>'Boston Celtics','displayOrder'=>0)));
$new_prop = $properties->create_property('favbostonnbateam',$new_prop_info);
print_r($new_prop);
//Update property
$updated_prop_info = array('label'=>'Favorite Boston NBA Team','name'=>'favbostonnbateam','description'=>'Your favorite NBA team in the Boston Area',
'groupName'=>'contactinformation','type'=>'enumeration','fieldType'=>'checkbox','formField'=>'true','displayOrder'=>0,
'options'=>array(array('label'=>'Boston Celtics','value'=>'Boston Celtics','displayOrder'=>0),
array('label'=>'I do not watch basketball','value'=>'I do not watch basketball','displayOrder'=>1)));
$updated_prop = $properties->update_property('favbostonnbateam',$updated_prop_info);
//Delete property
$deleted_prop = $properties->delete_property('favbostonnbateam');
print_r($deleted_prop);
//Get Property Group
$group = $properties->get_property_group('contactinformation');
print_r($group);
//Create Property Group
$group_info = array('name'=>'newpropgroup','displayName'=>'A New Property Group','displayOrder'=>4);
$new_group = $properties->create_property_group('newpropgroup',$group_info);
print_r($new_group);
//Update Property Group
$updated_group_info = array('name'=>'newpropgroup','displayName'=>'A Newer Property Group','displayOrder'=>4);
$updated_group = $properties->update_property_group('newpropgroup',$updated_group_info);
print_r($updated_group);
//Delete Property Group
$deleted_group = $properties->delete_property_group('newpropgroup');
print_r($deleted_group);
/*
//Exercise Social Media API
$social = new HubSpot_SocialMedia(array('access_token'=>'demooooo-oooo-oooo-oooo-oooooooooooo'));
//Get Publishing Channels
$channels = $social->get_publishing_channels();
print_r($channels);
//Get specific Channel
$channel = $social->get_publishing_channel('7c13e300-e43f-3aa0-a842-93956cb214e9');
print_r($channel);
//Get Broadcasts
$broadcasts = $social->get_broadcasts(array('status'=>'success','since','1356036460644','count'=>'100'));
print_r($broadcasts);
//Get specific Broadcast
$broadcast = $social->get_broadcast('8c3dc6fb-2c7e-4719-b4b9-521794289cfc');
print_r($broadcast);
//Create a Broadcast
$new_broadcast = $social->create_broadcast(array('channelGuid'=>'7c13e300-e43f-3aa0-a842-93956cb214e9','triggerAt'=>strval(time()*1000+50000),
'content'=>array('body'=>'Here is an awesome new Social Media message')));
print_r($new_broadcast);
//Cancel a Broadcast
$broadcast_guid = $new_broadcast->{'broadcastGuid'};
$deleted_broadcast = $social->cancel_broadcast($broadcast_guid);
print_r($deleted_broadcast);
*/
?>