|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SevenShores\Hubspot\Resources; |
|
4
|
|
|
|
|
5
|
|
|
class Workflows extends Resource |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* Get all workflows. |
|
9
|
|
|
* |
|
10
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
11
|
|
|
*/ |
|
12
|
|
|
function all() |
|
|
|
|
|
|
13
|
|
|
{ |
|
14
|
|
|
$endpoint = "https://api.hubapi.com/automation/v2/workflows"; |
|
15
|
|
|
|
|
16
|
|
|
return $this->client->request('get', $endpoint); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Get a specific workflow. |
|
21
|
|
|
* |
|
22
|
|
|
* @param int $id |
|
23
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
24
|
|
|
*/ |
|
25
|
|
|
function getById($id) |
|
|
|
|
|
|
26
|
|
|
{ |
|
27
|
|
|
$endpoint = "https://api.hubapi.com/automation/v2/workflows/{$id}"; |
|
28
|
|
|
|
|
29
|
|
|
return $this->client->request('get', $endpoint); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Enroll a contact in a workflow. |
|
34
|
|
|
* |
|
35
|
|
|
* @param int $workflow_id |
|
36
|
|
|
* @param string $email |
|
37
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
38
|
|
|
*/ |
|
39
|
|
|
function enrollContact($workflow_id, $email) |
|
|
|
|
|
|
40
|
|
|
{ |
|
41
|
|
|
$endpoint = "https://api.hubapi.com/automation/v2/workflows/{$workflow_id}/enrollments/contacts/{$email}"; |
|
42
|
|
|
|
|
43
|
|
|
return $this->client->request('post', $endpoint); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Unenroll a contact from a workflow. |
|
48
|
|
|
* |
|
49
|
|
|
* @param int $workflow_id |
|
50
|
|
|
* @param string $email |
|
51
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
52
|
|
|
*/ |
|
53
|
|
|
function unenrollContact($workflow_id, $email) |
|
|
|
|
|
|
54
|
|
|
{ |
|
55
|
|
|
$endpoint = "https://api.hubapi.com/automation/v2/workflows/{$workflow_id}/enrollments/contacts/{$email}"; |
|
56
|
|
|
|
|
57
|
|
|
return $this->client->request('delete', $endpoint); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Create a new workflow. |
|
62
|
|
|
* |
|
63
|
|
|
* @param array $workflow The workflow properties |
|
64
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
65
|
|
|
*/ |
|
66
|
|
|
function create($workflow) |
|
|
|
|
|
|
67
|
|
|
{ |
|
68
|
|
|
$endpoint = "https://api.hubapi.com/automation/v2/workflows"; |
|
69
|
|
|
|
|
70
|
|
|
$options['json'] = $workflow; |
|
71
|
|
|
|
|
72
|
|
|
return $this->client->request('post', $endpoint, $options); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Delete a workflow. |
|
77
|
|
|
* |
|
78
|
|
|
* @param int $id |
|
79
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
80
|
|
|
*/ |
|
81
|
|
|
function delete($id) |
|
|
|
|
|
|
82
|
|
|
{ |
|
83
|
|
|
$endpoint = "https://api.hubapi.com/automation/v2/workflows/{$id}"; |
|
84
|
|
|
|
|
85
|
|
|
$queryString = build_query_string(['updatedAt' => time()]); |
|
86
|
|
|
|
|
87
|
|
|
return $this->client->request('delete', $endpoint, [], $queryString); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Get current enrollments for a contact. |
|
92
|
|
|
* |
|
93
|
|
|
* @param int $contact_id |
|
94
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
95
|
|
|
*/ |
|
96
|
|
|
function enrollmentsForContact($contact_id) |
|
|
|
|
|
|
97
|
|
|
{ |
|
98
|
|
|
$endpoint = "https://api.hubapi.com/automation/v2/workflows/enrollments/contacts/{$contact_id}"; |
|
99
|
|
|
|
|
100
|
|
|
return $this->client->request('get', $endpoint); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Get past events for contact from a workflow. |
|
105
|
|
|
* |
|
106
|
|
|
* @param int $workflow_id |
|
107
|
|
|
* @param int $contact_id |
|
108
|
|
|
* @param array $params Optional parameters. |
|
109
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
110
|
|
|
*/ |
|
111
|
|
|
function pastEventsForContact($workflow_id, $contact_id, $params = []) |
|
|
|
|
|
|
112
|
|
|
{ |
|
113
|
|
|
$endpoint = " /automation/v2/workflows/{$workflow_id}/logevents/contacts/{$contact_id}/past"; |
|
114
|
|
|
|
|
115
|
|
|
$queryString = build_query_string($params); |
|
116
|
|
|
|
|
117
|
|
|
return $this->client->request('get', $endpoint, [], $queryString); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Get upcoming (scheduled) events for a contact in a workflow. |
|
122
|
|
|
* |
|
123
|
|
|
* @param int $workflow_id |
|
124
|
|
|
* @param int $contact_id |
|
125
|
|
|
* @param array $params |
|
126
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
127
|
|
|
*/ |
|
128
|
|
|
function upcomingEventsForContact($workflow_id, $contact_id, $params = []) |
|
|
|
|
|
|
129
|
|
|
{ |
|
130
|
|
|
$endpoint = "https://api.hubapi.com/automation/v2/workflows/{$workflow_id}/logevents/contacts/{$contact_id}/upcoming"; |
|
131
|
|
|
|
|
132
|
|
|
$queryString = build_query_string($params); |
|
133
|
|
|
|
|
134
|
|
|
return $this->client->request('get', $endpoint, [], $queryString); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
} |
|
138
|
|
|
|
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.