protected function activeCampaignAPI($api, $data) { $config_array = Config::get('services.activecampaign'); $config = new \AC\Arguments\Config($config_array); $ac = new ActiveCampaign($config); if (!(int) $ac->credentials_test()) { Log::info('ActiveCampaign: Access denied, Invalid credentials (URL and/or API key).'); } $result = $ac->api($api, $data); if ((int) $result->success) { if (property_exists($result, 'subscriber_id')) { Log::info("ActiveCampaign successful API call (ID " . (int) $result->subscriber_id . ")!"); return ['ok', (int) $result->subscriber_id]; } else { Log::info("ActiveCampaign successful API call. " . var_export($result, true)); return ['ok', '']; } } else { Log::info("ActiveCampaign ERROR: API call failed. " . $result->error); // request failed return ['error', $result->error]; } }
$ac = new ActiveCampaign($conf); $out = array(); /* * TEST API CREDENTIALS. */ if (!(int) $ac->credentials_test()) { echo "<p>Access denied: Invalid credentials (URL and/or API key).</p>"; exit; } else { $out[] = 'Credentials valid! Proceeding...'; //echo "<p>Credentials valid! Proceeding...</p>"; } /* * VIEW ACCOUNT DETAILS. */ $account = $ac->api("user/view?id=2"); $out[] = $account; /* echo "<pre>"; print_r($account); echo "</pre>";*/ /* * ADD NEW LIST. */ $list = array("name" => "List 3", "sender_name" => "My Company", "sender_addr1" => "123 S. Street", "sender_city" => "Chicago", "sender_zip" => "60601", "sender_country" => "USA"); $list_add = $ac->api("list/add", $list); if ((int) $list_add->success) { // successful request $list_id = (int) $list_add->id; $out[] = 'List added successfully (ID ' . $list_id . ')!'; //echo "<p>List added successfully (ID {$list_id})!</p>";