credentials_test()) { echo "

Access denied: Invalid credentials (URL and/or API key).

"; exit(); } echo "

Credentials valid! Proceeding...

"; /* * VIEW ACCOUNT DETAILS. */ $account = $ac->api("account/view"); echo "
";
	print_r($account);
	echo "
"; /* * 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) { // request failed echo "

Adding list failed. Error returned: " . $list_add->error . "

"; exit(); } // successful request $list_id = (int)$list_add->id; echo "

List added successfully (ID {$list_id})!

"; /* * ADD OR EDIT CONTACT (TO THE NEW LIST CREATED ABOVE). */ $contact = array( "email" => "test@example.com", "first_name" => "Test", "last_name" => "Test", "p[{$list_id}]" => $list_id, "status[{$list_id}]" => 1, // "Active" status ); $contact_sync = $ac->api("contact/sync", $contact); if (!(int)$contact_sync->success) { // request failed echo "

Syncing contact failed. Error returned: " . $contact_sync->error . "

"; exit(); } // successful request $contact_id = (int)$contact_sync->subscriber_id; echo "

Contact synced successfully (ID {$contact_id})!

"; /* * VIEW ALL CONTACTS IN A LIST (RETURNS ID AND EMAIL). */ $ac->version(2); $contacts_view = $ac->api("contact/list?listid=14&limit=500"); $ac->version(1); /* * ADD NEW EMAIL MESSAGE (FOR A CAMPAIGN). */ $message = array( "format" => "mime", "subject" => "Check out our latest deals!", "fromemail" => "newsletter@test.com", "fromname" => "Test from API", "html" => "

My email newsletter.

", "p[{$list_id}]" => $list_id, ); $message_add = $ac->api("message/add", $message); if (!(int)$message_add->success) { // request failed echo "

Adding email message failed. Error returned: " . $message_add->error . "

"; exit(); } // successful request $message_id = (int)$message_add->id; echo "

Message added successfully (ID {$message_id})!

"; /* * CREATE NEW CAMPAIGN (USING THE EMAIL MESSAGE CREATED ABOVE). */ $campaign = array( "type" => "single", "name" => "July Campaign", // internal name (message subject above is what contacts see) "sdate" => "2013-07-01 00:00:00", "status" => 1, "public" => 1, "tracklinks" => "all", "trackreads" => 1, "htmlunsub" => 1, "p[{$list_id}]" => $list_id, "m[{$message_id}]" => 100, // 100 percent of subscribers ); $campaign_create = $ac->api("campaign/create", $campaign); if (!(int)$campaign_create->success) { // request failed echo "

Creating campaign failed. Error returned: " . $campaign_create->error . "

"; exit(); } // successful request $campaign_id = (int)$campaign_create->id; echo "

Campaign created and sent! (ID {$campaign_id})!

"; /* * VIEW CAMPAIGN REPORTS (FOR THE CAMPAIGN CREATED ABOVE). */ $campaign_report_totals = $ac->api("campaign/report/totals?campaignid={$campaign_id}"); echo "

Reports:

"; echo "
";
	print_r($campaign_report_totals);
	echo "
"; ?>

Note: It can also be helpful to check our API documentation for the HTTP method that should be used for a particular endpoint as it can affect the format of your request.

Example:

list_field_view
GET

$ac->api("list/field/view?ids=all");

Query params appended for a GET request.

Example:

list_field_edit
POST

$ac->api("list/field/edit", array(/*POST params here.*/));
View more API examples!