├── .gitignore ├── LICENSE ├── README.md ├── composer.json ├── src ├── Client.php ├── Resource.php ├── contacts │ └── Contacts.php ├── deals │ └── Deals.php ├── lists │ └── Lists.php ├── organizations │ └── Organizations.php ├── tags │ └── Tags.php └── tracking │ ├── EventTracking.php │ └── SiteTracking.php └── tests ├── ClientTest.php ├── ResourceTestCase.php ├── bootstrap.example.php ├── contacts └── ContactsTest.php ├── organizations └── OrganizationsTest.php └── tracking └── EventTrackingTest.php /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | /vendor/ 3 | /tests/bootstrap.php 4 | /composer.lock 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Mediatookit 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Active Campaign v3 PHP Wrapper 2 | 3 | Unofficial PHP Wrapper for ActiveCampaign API v3. 4 | 5 | ## Installation: 6 | ``` 7 | composer require mediatoolkit/activecampaign-v3-php 8 | ``` 9 | 10 | ## Basic usage: 11 | #### Create a client: 12 | 13 | ``` 14 | $client = new Client( 15 | $api_url, 16 | $api_token, 17 | $event_tracking_actid, 18 | $event_tracking_key 19 | ); 20 | ``` 21 | 22 | #### Select Contacts endpoint: 23 | ``` 24 | $contacts = new Contacts($client); 25 | ``` 26 | 27 | #### Create new contact: 28 | ``` 29 | $contact = $contacts->create([ 30 | 'email' => 'CONTACT_EMAIL', 31 | 'firstName' => 'CONTACT_FIRST_NAME', 32 | 'lastName' => 'CONTACT_LAST_NAME' 33 | ]); 34 | ``` 35 | 36 | 37 | ## Available endpoints: 38 | * Contacts 39 | * Deals 40 | * Lists 41 | * Organizations 42 | * EventTracking 43 | * SiteTracking 44 | 45 | ## ActiveCampaign Developer Documentation 46 | Official API docs: https://developers.activecampaign.com/reference 47 | 48 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mediatoolkit/activecampaign-v3-php", 3 | "description": "PHP Wrapper for ActiveCampaign", 4 | "require": { 5 | "guzzlehttp/guzzle": "~6.3" 6 | }, 7 | "require-dev": { 8 | "phpunit/phpunit": "^7" 9 | }, 10 | "license": "MIT", 11 | "authors": [ 12 | { 13 | "name": "Mediatoolkit", 14 | "email": "info@mediatoolkit.com" 15 | } 16 | ], 17 | "autoload": { 18 | "psr-4": { 19 | "Mediatoolkit\\ActiveCampaign\\": "src/" 20 | } 21 | }, 22 | "autoload-dev": { 23 | "psr-4": { 24 | "Mediatoolkit\\Tests\\": "tests/" 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Client.php: -------------------------------------------------------------------------------- 1 | Tracking > Event Tracking > Event Tracking API 33 | * @var string 34 | */ 35 | protected $event_tracking_actid; 36 | 37 | /** 38 | * Event Tracking Key 39 | * Get yours from Settings > Tracking > Event Tracking > Event Key 40 | * @var string 41 | */ 42 | protected $event_tracking_key; 43 | 44 | /** 45 | * @var \GuzzleHttp\Client 46 | */ 47 | private $client; 48 | 49 | /** 50 | * @var \GuzzleHttp\Client 51 | */ 52 | private $event_tracking_client; 53 | 54 | public function __construct($api_url, $api_token, $event_tracking_actid = null, $event_tracking_key = null) 55 | { 56 | $this->api_url = $api_url; 57 | $this->api_token = $api_token; 58 | $this->event_tracking_actid = $event_tracking_actid; 59 | $this->event_tracking_key = $event_tracking_key; 60 | 61 | $this->client = new \GuzzleHttp\Client([ 62 | 'base_uri' => $this->api_url, 63 | 'headers' => [ 64 | 'User-Agent' => self::LIB_USER_AGENT, 65 | self::HEADER_AUTH_KEY => $this->api_token, 66 | 'Accept' => 'application/json' 67 | ] 68 | ]); 69 | 70 | if (!is_null($this->event_tracking_actid) && !is_null($this->event_tracking_key)) { 71 | $this->event_tracking_client = new \GuzzleHttp\Client([ 72 | 'base_uri' => self::EVENT_TRACKING_URL, 73 | 'headers' => [ 74 | 'User-Agent' => self::LIB_USER_AGENT, 75 | 'Accept' => 'application/json' 76 | ], 77 | 'form_params' => [ 78 | 'actid' => $this->event_tracking_actid, 79 | 'key' => $this->event_tracking_key 80 | ] 81 | ]); 82 | } 83 | } 84 | 85 | /** 86 | * @return \GuzzleHttp\Client 87 | */ 88 | public function getClient() 89 | { 90 | return $this->client; 91 | } 92 | 93 | /** 94 | * @return \GuzzleHttp\Client|null 95 | */ 96 | public function getEventTrackingClient() 97 | { 98 | if (is_null($this->event_tracking_actid)) { 99 | return null; 100 | } 101 | return $this->event_tracking_client; 102 | } 103 | 104 | /** 105 | * @return string 106 | */ 107 | public function getApiUrl() 108 | { 109 | return $this->api_url; 110 | } 111 | 112 | /** 113 | * @return string 114 | */ 115 | public function getApiToken() 116 | { 117 | return $this->api_token; 118 | } 119 | 120 | /** 121 | * @return string|null 122 | */ 123 | public function getEventTrackingActid() 124 | { 125 | return $this->event_tracking_actid; 126 | } 127 | 128 | } -------------------------------------------------------------------------------- /src/Resource.php: -------------------------------------------------------------------------------- 1 | client = $client; 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /src/contacts/Contacts.php: -------------------------------------------------------------------------------- 1 | client 25 | ->getClient() 26 | ->post('/api/3/contacts', [ 27 | 'json' => [ 28 | 'contact' => $contact 29 | ] 30 | ]); 31 | 32 | return $req->getBody()->getContents(); 33 | } 34 | 35 | /** 36 | * Create or update contact 37 | * @see https://developers.activecampaign.com/reference#create-contact-sync 38 | * 39 | * @param array $contact 40 | * @return string 41 | */ 42 | public function sync(array $contact) 43 | { 44 | $req = $this->client 45 | ->getClient() 46 | ->post('/api/3/contact/sync', [ 47 | 'json' => [ 48 | 'contact' => $contact 49 | ] 50 | ]); 51 | 52 | return $req->getBody()->getContents(); 53 | } 54 | 55 | /** 56 | * Get contact 57 | * @see https://developers.activecampaign.com/reference#get-contact 58 | * 59 | * @param int $id 60 | * @return string 61 | */ 62 | public function get(int $id) 63 | { 64 | $req = $this->client 65 | ->getClient() 66 | ->get('/api/3/contacts/' . $id); 67 | 68 | return $req->getBody()->getContents(); 69 | } 70 | 71 | /** 72 | * Update list status for a contact 73 | * @see https://developers.activecampaign.com/reference#update-list-status-for-contact 74 | * 75 | * @param array $contact_list 76 | * @return string 77 | */ 78 | public function updateListStatus(array $contact_list) 79 | { 80 | $req = $this->client 81 | ->getClient() 82 | ->post('/api/3/contactLists', [ 83 | 'json' => [ 84 | 'contactList' => $contact_list 85 | ] 86 | ]); 87 | 88 | return $req->getBody()->getContents(); 89 | } 90 | 91 | /** 92 | * Update a contact 93 | * @see https://developers.activecampaign.com/reference#update-a-contact 94 | * 95 | * @param int $id 96 | * @param array $contact 97 | * @return string 98 | */ 99 | public function update(int $id, array $contact) 100 | { 101 | $req = $this->client 102 | ->getClient() 103 | ->put('/api/3/contacts/' . $id, [ 104 | 'json' => [ 105 | 'contact' => $contact 106 | ] 107 | ]); 108 | 109 | return $req->getBody()->getContents(); 110 | } 111 | 112 | /** 113 | * Delete a contact 114 | * @see https://developers.activecampaign.com/reference#delete-contact 115 | * 116 | * @param int $id 117 | * @return string 118 | */ 119 | public function delete(int $id) 120 | { 121 | $req = $this->client 122 | ->getClient() 123 | ->delete('/api/3/contacts/' . $id); 124 | 125 | return 200 === $req->getStatusCode(); 126 | } 127 | 128 | /** 129 | * List all automations the contact is in 130 | * @see https://developers.activecampaign.com/reference#list-all-contactautomations-for-contact 131 | * 132 | * @param int $id 133 | * @return string 134 | */ 135 | public function listAutomations(int $id) 136 | { 137 | $req = $this->client 138 | ->getClient() 139 | ->get('/api/3/contacts/' . $id . '/contactAutomations'); 140 | 141 | return $req->getBody()->getContents(); 142 | } 143 | 144 | /** 145 | * Add a tag to contact 146 | * @see https://developers.activecampaign.com/reference#create-contact-tag 147 | * 148 | * @param int $id 149 | * @param int $tag_id 150 | * @return string 151 | */ 152 | public function tag(int $id, int $tag_id) 153 | { 154 | $req = $this->client 155 | ->getClient() 156 | ->post('/api/3/contactTags', [ 157 | 'json' => [ 158 | 'contactTag' => [ 159 | 'contact' => $id, 160 | 'tag' => $tag_id 161 | ] 162 | ] 163 | ]); 164 | 165 | return $req->getBody()->getContents(); 166 | } 167 | 168 | /** 169 | * Remove a tag from a contact 170 | * @see https://developers.activecampaign.com/reference#delete-contact-tag 171 | * 172 | * @param int $contact_tag_id 173 | * @return string 174 | */ 175 | public function untag(int $contact_tag_id) 176 | { 177 | $req = $this->client 178 | ->getClient() 179 | ->delete('/api/3/contactTags/' . $contact_tag_id); 180 | 181 | return $req->getBody()->getContents(); 182 | } 183 | 184 | /** 185 | * List all contacts 186 | * @see https://developers.activecampaign.com/reference#list-all-contacts 187 | * 188 | * @param array $query_params 189 | * @param int $limit 190 | * @param int $offset 191 | * @return string 192 | */ 193 | public function listAll(array $query_params = [], int $limit = 20, int $offset = 0) 194 | { 195 | $query_params = array_merge($query_params, [ 196 | 'limit' => $limit, 197 | 'offset' => $offset 198 | ]); 199 | 200 | $req = $this->client 201 | ->getClient() 202 | ->get('/api/3/contacts', [ 203 | 'query' => $query_params 204 | ]); 205 | 206 | return $req->getBody()->getContents(); 207 | } 208 | 209 | /** 210 | * List all custom fields 211 | * @see https://developers.activecampaign.com/v3/reference#retrieve-fields-1 212 | * @param array $query_params 213 | * @return string 214 | */ 215 | public function listAllCustomFields(array $query_params = []) 216 | { 217 | $req = $this->client 218 | ->getClient() 219 | ->get('/api/3/fields', [ 220 | 'query' => $query_params 221 | ]); 222 | 223 | return $req->getBody()->getContents(); 224 | } 225 | 226 | /** 227 | * Create a custom field value 228 | * @see https://developers.activecampaign.com/v3/reference#create-fieldvalue 229 | * 230 | * @param int $contact_id 231 | * @param int $field_id 232 | * @param string $field_value 233 | * @return string 234 | */ 235 | public function createCustomFieldValue(int $contact_id, int $field_id, string $field_value) 236 | { 237 | $req = $this->client 238 | ->getClient() 239 | ->post('/api/3/fieldValues', [ 240 | 'json' => [ 241 | 'fieldValue' => [ 242 | 'contact' => $contact_id, 243 | 'field' => $field_id, 244 | 'value' => $field_value 245 | ] 246 | ] 247 | ]); 248 | 249 | return $req->getBody()->getContents(); 250 | } 251 | 252 | /** 253 | * Retrieve a custom field value 254 | * @see https://developers.activecampaign.com/v3/reference#retrieve-a-fieldvalues 255 | * 256 | * @param int $field_id 257 | * @return string 258 | */ 259 | public function retrieveCustomFieldValue(int $field_id) 260 | { 261 | $req = $this->client 262 | ->getClient() 263 | ->get('/api/3/fieldValues/' . $field_id); 264 | 265 | return $req->getBody()->getContents(); 266 | } 267 | 268 | /** 269 | * Update a custom field value 270 | * @see https://developers.activecampaign.com/v3/reference#update-a-custom-field-value-for-contact 271 | * 272 | * @param int $field_value_id 273 | * @param int $contact_id 274 | * @param int $field_id 275 | * @param string $field_value 276 | * @return string 277 | */ 278 | public function updateCustomFieldValue(int $field_value_id, int $contact_id, int $field_id, string $field_value) 279 | { 280 | $req = $this->client 281 | ->getClient() 282 | ->put('/api/3/fieldValues/' . $field_value_id, [ 283 | 'json' => [ 284 | 'fieldValue' => [ 285 | 'contact' => $contact_id, 286 | 'field' => $field_id, 287 | 'value' => $field_value 288 | ] 289 | ] 290 | ]); 291 | 292 | return $req->getBody()->getContents(); 293 | } 294 | 295 | /** 296 | * Delete a custom field value 297 | * @see https://developers.activecampaign.com/v3/reference#delete-a-fieldvalue-1 298 | * 299 | * @param int $field_value_id 300 | * @return bool 301 | */ 302 | public function deleteCustomFieldValue(int $field_value_id) 303 | { 304 | $req = $this->client 305 | ->getClient() 306 | ->delete('/api/3/fieldValues/' . $field_value_id); 307 | 308 | return 200 === $req->getStatusCode(); 309 | } 310 | 311 | /** 312 | * Remove contact from automation 313 | * @see https://developers.activecampaign.com/reference#delete-a-contactautomation 314 | * @param int $contactAutomationId 315 | * @return bool 316 | */ 317 | public function removeAutomation(int $contactAutomationId) 318 | { 319 | $req = $this->client 320 | ->getClient() 321 | ->delete('/api/3/contactAutomation/' . $contactAutomationId); 322 | 323 | return 200 === $req->getStatusCode(); 324 | } 325 | 326 | } 327 | -------------------------------------------------------------------------------- /src/deals/Deals.php: -------------------------------------------------------------------------------- 1 | client 26 | ->getClient() 27 | ->post('/api/3/deals', [ 28 | 'json' => [ 29 | 'deal' => $deal 30 | ] 31 | ]); 32 | 33 | return $req->getBody()->getContents(); 34 | } 35 | 36 | /** 37 | * Get a deal by id 38 | * @see https://developers.activecampaign.com/reference#retrieve-a-deal 39 | * 40 | * @param int $id 41 | * @return string 42 | */ 43 | public function get(int $id) 44 | { 45 | $req = $this->client 46 | ->getClient() 47 | ->get('/api/3/deals/' . $id); 48 | 49 | return $req->getBody()->getContents(); 50 | } 51 | 52 | /** 53 | * Update a deal 54 | * @see https://developers.activecampaign.com/reference#update-a-deal 55 | * 56 | * @param int $id 57 | * @param array $deal 58 | * @return string 59 | */ 60 | public function update(int $id, array $deal) 61 | { 62 | $req = $this->client 63 | ->getClient() 64 | ->put('/api/3/deals/' . $id, [ 65 | 'json' => [ 66 | 'deal' => $deal 67 | ] 68 | ]); 69 | 70 | return $req->getBody()->getContents(); 71 | } 72 | 73 | /** 74 | * Delete a deal by id 75 | * @see https://developers.activecampaign.com/reference#delete-a-deal 76 | * 77 | * @param int $id 78 | * @return string 79 | */ 80 | public function delete(int $id) 81 | { 82 | $req = $this->client 83 | ->getClient() 84 | ->delete('/api/3/deals/' . $id); 85 | 86 | return $req->getBody()->getContents(); 87 | } 88 | 89 | /** 90 | * Move deals to another stage 91 | * @see https://developers.activecampaign.com/reference#move-deals-to-another-deal-stage 92 | * 93 | * @param int $id 94 | * @param array $deal 95 | * @return string 96 | */ 97 | public function moveToStage(int $id, array $deal) 98 | { 99 | $req = $this->client 100 | ->getClient() 101 | ->put('/api/3/dealStages/' . $id . '/deals', [ 102 | 'json' => [ 103 | 'deal' => $deal 104 | ] 105 | ]); 106 | 107 | return $req->getBody()->getContents(); 108 | } 109 | 110 | /** 111 | * Create a deal custom field value 112 | * @see https://developers.activecampaign.com/v3/reference#create-dealcustomfielddata-resource 113 | * 114 | * @param int $deal_id 115 | * @param int $field_id 116 | * @param $field_value 117 | * @return string 118 | */ 119 | public function createCustomFieldValue(int $deal_id, int $field_id, $field_value) 120 | { 121 | $req = $this->client 122 | ->getClient() 123 | ->post('/api/3/dealCustomFieldData', [ 124 | 'json' => [ 125 | 'dealCustomFieldDatum' => [ 126 | 'dealId' => $deal_id, 127 | 'custom_field_id' => $field_id, 128 | 'fieldValue' => $field_value 129 | ] 130 | ] 131 | ]); 132 | 133 | return $req->getBody()->getContents(); 134 | } 135 | 136 | /** 137 | * Retrieve a custom field value 138 | * @see https://developers.activecampaign.com/v3/reference#retrieve-a-dealcustomfielddata 139 | * @param int $custom_field_id 140 | * @return string 141 | */ 142 | public function retrieveCustomFieldValue(int $custom_field_id) 143 | { 144 | $req = $this->client 145 | ->getClient() 146 | ->get('/api/3/dealCustomFieldData/' . $custom_field_id); 147 | 148 | return $req->getBody()->getContents(); 149 | } 150 | 151 | /** 152 | * Update a custom field value 153 | * @see https://developers.activecampaign.com/v3/reference#update-a-dealcustomfielddata-resource 154 | * 155 | * @param int $custom_field_id 156 | * @param $field_value 157 | * @return string 158 | */ 159 | public function updateCustomFieldValue(int $custom_field_id, $field_value) 160 | { 161 | $req = $this->client 162 | ->getClient() 163 | ->put('/api/3/dealCustomFieldData/' . $custom_field_id, [ 164 | 'json' => [ 165 | 'dealCustomFieldDatum' => [ 166 | 'fieldValue' => $field_value 167 | ] 168 | ] 169 | ]); 170 | 171 | return $req->getBody()->getContents(); 172 | } 173 | 174 | /** 175 | * Delete a custom field value 176 | * @see https://developers.activecampaign.com/v3/reference#retrieve-a-dealcustomfielddata-resource 177 | * 178 | * @param int $custom_field_id 179 | * @return string 180 | */ 181 | public function deleteCustomFieldValue(int $custom_field_id) 182 | { 183 | $req = $this->client 184 | ->getClient() 185 | ->delete('/api/3/dealCustomFieldData/' . $custom_field_id); 186 | 187 | return $req->getBody()->getContents(); 188 | } 189 | 190 | /** 191 | * List all custom fields 192 | * @see https://developers.activecampaign.com/reference#retrieve-all-dealcustomfielddata-resources 193 | * @param array $query_params 194 | * @return string 195 | */ 196 | public function listAllCustomFields(array $query_params = []) 197 | { 198 | $req = $this->client 199 | ->getClient() 200 | ->get('/api/3/dealCustomFieldMeta', [ 201 | 'query' => $query_params 202 | ]); 203 | 204 | return $req->getBody()->getContents(); 205 | } 206 | 207 | /** 208 | * List all custom field values 209 | * @see https://developers.activecampaign.com/reference#list-all-custom-field-values 210 | * @param array $query_params 211 | * @return string 212 | */ 213 | public function listAllCustomFieldValues(array $query_params) 214 | { 215 | $req = $this->client 216 | ->getClient() 217 | ->get('/api/3/dealCustomFieldData', [ 218 | 'query' => $query_params 219 | ]); 220 | 221 | return $req->getBody()->getContents(); 222 | } 223 | 224 | /** 225 | * List all pipelines 226 | * @see https://developers.activecampaign.com/reference#list-all-pipelines 227 | * @param array $query_params 228 | * @return string 229 | */ 230 | public function listAllPipelines(array $query_params = []) 231 | { 232 | $req = $this->client 233 | ->getClient() 234 | ->get('/api/3/dealGroups', [ 235 | 'query' => $query_params 236 | ]); 237 | 238 | return $req->getBody()->getContents(); 239 | } 240 | 241 | /** 242 | * List all stages 243 | * @see https://developers.activecampaign.com/reference#list-all-deal-stages 244 | * @param array $query_params 245 | * @return string 246 | */ 247 | public function listAllStages(array $query_params = []) 248 | { 249 | $req = $this->client 250 | ->getClient() 251 | ->get('/api/3/dealStages', [ 252 | 'query' => $query_params 253 | ]); 254 | 255 | return $req->getBody()->getContents(); 256 | } 257 | 258 | } -------------------------------------------------------------------------------- /src/lists/Lists.php: -------------------------------------------------------------------------------- 1 | client 25 | ->getClient() 26 | ->post('/api/3/lists', [ 27 | 'json' => [ 28 | 'list' => $list 29 | ] 30 | ]); 31 | 32 | return $req->getBody()->getContents(); 33 | } 34 | 35 | /** 36 | * Retrieve all lists or a list when id is not null 37 | * @see https://developers.activecampaign.com/reference#retrieve-a-list 38 | * @param null $id 39 | * @param array $query_params 40 | * @return string 41 | */ 42 | public function retrieve($id = null, array $query_params = []) 43 | { 44 | $uri = '/api/3/lists'; 45 | if (!is_null($id)) { 46 | $uri .= '/' . $id; 47 | } 48 | $req = $this->client 49 | ->getClient() 50 | ->get($uri, [ 51 | 'query' => $query_params 52 | ]); 53 | 54 | return $req->getBody()->getContents(); 55 | } 56 | 57 | /** 58 | * Delete a list 59 | * @see https://developers.activecampaign.com/reference#delete-a-list 60 | * @param $id 61 | * @return string 62 | */ 63 | public function delete($id) 64 | { 65 | $req = $this->client 66 | ->getClient() 67 | ->delete('/api/3/lists/' . $id); 68 | 69 | return $req->getBody()->getContents(); 70 | } 71 | 72 | } -------------------------------------------------------------------------------- /src/organizations/Organizations.php: -------------------------------------------------------------------------------- 1 | client 25 | ->getClient() 26 | ->post('/api/3/organizations', [ 27 | 'json' => [ 28 | 'organization' => $organization 29 | ] 30 | ]); 31 | 32 | return $req->getBody()->getContents(); 33 | } 34 | 35 | /** 36 | * Get an organization 37 | * @see https://developers.activecampaign.com/reference#get-organization 38 | * 39 | * @param int $id 40 | * @return string 41 | */ 42 | public function get(int $id) 43 | { 44 | $req = $this->client 45 | ->getClient() 46 | ->get('/api/3/organizations/' . $id); 47 | 48 | return $req->getBody()->getContents(); 49 | } 50 | 51 | /** 52 | * Update an organization 53 | * @see https://developers.activecampaign.com/reference#update-organization 54 | * 55 | * @param int $id 56 | * @param array $organization 57 | * @return string 58 | */ 59 | public function update(int $id, array $organization) 60 | { 61 | $req = $this->client 62 | ->getClient() 63 | ->put('/api/3/organizations/' . $id, [ 64 | 'json' => [ 65 | 'organization' => $organization 66 | ] 67 | ]); 68 | 69 | return $req->getBody()->getContents(); 70 | } 71 | 72 | /** 73 | * Delete an organization 74 | * @see https://developers.activecampaign.com/reference#delete-organization 75 | * 76 | * @param int $id 77 | * @return string 78 | */ 79 | public function delete(int $id) 80 | { 81 | $req = $this->client 82 | ->getClient() 83 | ->delete('/api/3/organizations/' . $id); 84 | 85 | return $req->getBody()->getContents(); 86 | } 87 | 88 | /** 89 | * Delete multiple organizations 90 | * @see https://developers.activecampaign.com/reference#delete-multiple-organizations 91 | * 92 | * @param array $ids 93 | * @return string 94 | */ 95 | public function bulkDelete(array $ids) 96 | { 97 | $req = $this->client 98 | ->getClient() 99 | ->delete('/api/3/organizations/bulk_delete', [ 100 | 'query' => [ 101 | 'ids' => $ids 102 | ] 103 | ]); 104 | 105 | return $req->getBody()->getContents(); 106 | } 107 | 108 | public function listAll(array $query_params = [], $limit = 20, $offset = 0) 109 | { 110 | $query_params = array_merge($query_params, [ 111 | 'limit' => $limit, 112 | 'offset' => $offset 113 | ]); 114 | 115 | $req = $this->client 116 | ->getClient() 117 | ->get('/api/3/organizations', [ 118 | 'query' => $query_params 119 | ]); 120 | 121 | return $req->getBody()->getContents(); 122 | } 123 | 124 | 125 | } -------------------------------------------------------------------------------- /src/tags/Tags.php: -------------------------------------------------------------------------------- 1 | client 24 | ->getClient() 25 | ->get('/api/3/tags', [ 26 | 'query' => $query_params 27 | ]); 28 | 29 | return $req->getBody()->getContents(); 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /src/tracking/EventTracking.php: -------------------------------------------------------------------------------- 1 | client 23 | ->getClient() 24 | ->get('api/3/eventTracking'); 25 | 26 | return $req->getBody()->getContents(); 27 | } 28 | 29 | /** 30 | * Create a new event 31 | * @see https://developers.activecampaign.com/v3/reference#create-a-new-event-name-only 32 | * @param string $event_name 33 | * @return string 34 | */ 35 | public function createEvent(string $event_name) 36 | { 37 | $req = $this->client 38 | ->getClient() 39 | ->post('/api/3/eventTrackingEvents', [ 40 | 'json' => [ 41 | 'eventTrackingEvent' => [ 42 | 'name' => $event_name 43 | ] 44 | ] 45 | ]); 46 | 47 | return $req->getBody()->getContents(); 48 | } 49 | 50 | /** 51 | * Delete event 52 | * @see https://developers.activecampaign.com/v3/reference#remove-event-name-only 53 | * 54 | * @param string $event_name 55 | * @return bool 56 | */ 57 | public function deleteEvent(string $event_name) 58 | { 59 | $req = $this->client 60 | ->getClient() 61 | ->delete('/api/3/eventTrackingEvent/' . $event_name); 62 | 63 | return 200 === $req->getStatusCode(); 64 | } 65 | 66 | /** 67 | * List all events 68 | * @see https://developers.activecampaign.com/v3/reference#list-all-event-types 69 | * 70 | * @param array $query_params 71 | * @return string 72 | */ 73 | public function listAllEvents(array $query_params = []) 74 | { 75 | $req = $this->client 76 | ->getClient() 77 | ->get('api/3/eventTrackingEvents', [ 78 | 'query' => $query_params 79 | ]); 80 | 81 | return $req->getBody()->getContents(); 82 | } 83 | 84 | /** 85 | * Enable/Disable event tracking 86 | * @see https://developers.activecampaign.com/v3/reference#enable-disable-event-tracking 87 | * 88 | * @param bool $enabled 89 | * @return string 90 | */ 91 | public function toggleEventTracking(bool $enabled) 92 | { 93 | $req = $this->client 94 | ->getClient() 95 | ->put('/api/3/eventTracking/', [ 96 | 'json' => [ 97 | 'eventTracking' => [ 98 | 'enabled' => $enabled 99 | ] 100 | ] 101 | ]); 102 | 103 | return $req->getBody()->getContents(); 104 | } 105 | 106 | /** 107 | * @param string $event_name 108 | * @param null $event_data 109 | * @param null $email 110 | * @return string 111 | */ 112 | public function trackEvent(string $event_name, $event_data = null, $email = null) 113 | { 114 | $form_params = [ 115 | 'event' => $event_name 116 | ]; 117 | 118 | if (!is_null($event_data)) { 119 | $form_params['eventdata'] = $event_data; 120 | } 121 | 122 | if (!is_null($email)) { 123 | $form_params['visit'] = json_encode([ 124 | 'email' => $email 125 | ]); 126 | } 127 | 128 | $form_params = array_merge( 129 | $form_params, 130 | $this->client->getEventTrackingClient()->getConfig('form_params') 131 | ); 132 | 133 | $req = $this->client 134 | ->getEventTrackingClient() 135 | ->post('', [ 136 | 'form_params' => $form_params 137 | ]); 138 | 139 | return $req->getBody()->getContents(); 140 | } 141 | 142 | } -------------------------------------------------------------------------------- /src/tracking/SiteTracking.php: -------------------------------------------------------------------------------- 1 | client 24 | ->getClient() 25 | ->get('api/3/siteTracking', [ 26 | 'query' => $query_params 27 | ]); 28 | 29 | return $req->getBody()->getContents(); 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /tests/ClientTest.php: -------------------------------------------------------------------------------- 1 | assertEquals($_ENV['API_URL'], $this->client->getApiUrl()); 14 | $this->assertEquals($_ENV['API_TOKEN'], $this->client->getApiToken()); 15 | 16 | $config = $this->client->getClient()->getConfig(); 17 | 18 | $this->assertArrayHasKey(Client::HEADER_AUTH_KEY, $config['headers']); 19 | 20 | $this->assertEquals($_ENV['API_TOKEN'], $config['headers'][Client::HEADER_AUTH_KEY]); 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /tests/ResourceTestCase.php: -------------------------------------------------------------------------------- 1 | client = new Client( 21 | $_ENV['API_URL'], 22 | $_ENV['API_TOKEN'], 23 | $_ENV['EVENT_TRACKING_ACTID'], 24 | $_ENV['EVENT_TRACKING_KEY'] 25 | ); 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /tests/bootstrap.example.php: -------------------------------------------------------------------------------- 1 | client); 34 | $create = $contacts->create([ 35 | 'email' => self::$email, 36 | 'firstName' => self::$firstName, 37 | 'lastName' => self::$lastName 38 | ]); 39 | 40 | $createdContact = json_decode($create, true); 41 | $this->assertEquals(1, count($createdContact)); 42 | 43 | $getContact = $contacts->get($createdContact['contact']['id']); 44 | $getContact = json_decode($getContact, true); 45 | $this->assertEquals(self::$email, $getContact['contact']['email']); 46 | 47 | $listNotExisting = $contacts->listAll([ 48 | 'email' => 'nonexistinguser@mail.tests' 49 | ]); 50 | 51 | $listNotExisting = json_decode($listNotExisting, true); 52 | $this->assertCount(0, $listNotExisting['contacts']); 53 | 54 | $limitWorking = $contacts->listAll([ 55 | 'email' => self::$email 56 | ], 23, 5); 57 | 58 | $limitWorking = json_decode($limitWorking, true); 59 | $this->assertCount(0, $limitWorking['contacts']); 60 | 61 | $deleteContact = $contacts->delete($createdContact['contact']['id']); 62 | $this->assertEquals(true, $deleteContact); 63 | } 64 | 65 | } -------------------------------------------------------------------------------- /tests/organizations/OrganizationsTest.php: -------------------------------------------------------------------------------- 1 | client); 34 | 35 | $create = $organizations->create([ 36 | 'name' => self::$name 37 | ]); 38 | 39 | $org = json_decode($create, true); 40 | $this->assertCount(1, $org); 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /tests/tracking/EventTrackingTest.php: -------------------------------------------------------------------------------- 1 | client); 20 | $track = $tracking 21 | ->trackEvent( 22 | 'test', 23 | null, 24 | null 25 | ); 26 | 27 | $event = json_decode($track, true); 28 | $this->assertArrayHasKey('success', $event); 29 | $this->assertEquals(1, $event['success']); 30 | } 31 | 32 | } --------------------------------------------------------------------------------