For plugin writers and others using PHP, here are some basic utility functions which will provide almost everything you need to interact with FeedBlitz to do the following:
- Get a list of active lists
- Start the dual opt-in subscription process for a list
The functions use cURL for maximum compatibility. Click here for insight into the workflow this sample code supports.
<?php // helper function to access the FeedBlitz API via GET function fbz_get_web_page( $url ) { $options = array( CURLOPT_RETURNTRANSFER => true, // return web page CURLOPT_HEADER => false, // don't return headers CURLOPT_FOLLOWLOCATION => true, // follow redirects CURLOPT_ENCODING => "", // handle all encodings CURLOPT_USERAGENT => "PHP FeedBlitz Web Form Handler", // a UA is required CURLOPT_AUTOREFERER => true, // set referer on redirect CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect CURLOPT_TIMEOUT => 120, // timeout on response CURLOPT_MAXREDIRS => 10, // stop after 10 redirects CURLOPT_SSL_VERIFYPEER => false, ); $ch = curl_init( $url ); curl_setopt_array( $ch, $options ); $content = curl_exec( $ch ); $err = curl_errno( $ch ); $errmsg = curl_error( $ch ); curl_close( $ch ); return $content; } // turns the returned XML into a PHP array function fbz_prepare_results($page) { $xml = simplexml_load_string($page, "SimpleXMLElement", LIBXML_NOCDATA); $json = json_encode($xml); $array = json_decode($json,TRUE); return $array; } // returns an array of list IDs, names and current subscriber counts function fbz_get_lists($api_key, $lists) { $url = "https://app.feedblitz.com/f.api/syndications?key=" . $api_key ."&summary=1&status=ok"; $page = fbz_get_web_page($url); $array = fbz_prepare_results($page); if($array['rsp']['@attributes']['stat']=="ok") { $lists_array = $array['syndications']['syndication']; if ( ! empty( $lists_array ) ) { foreach ( $lists_array as $list_data ) { $lists[ $list_data['id'] ]['id'] = $list_data['id']; $lists[ $list_data['id'] ]['name'] = $list_data['name']; $lists[ $list_data['id'] ]['subscribers_count'] = $list_data['subscribersummary']['subscribers']; } } } return $lists; } // get basic custom fields info for the account function fbz_get_fields($api_key, $fields) { $url = "https://app.feedblitz.com/f.api/fields?key=" . $api_key ."&status=ok"; $page = fbz_get_web_page($url); $array = fbz_prepare_results($page); if($array['rsp']['@attributes']['stat']=="ok") { $fields_array = $array['fields']['field']; if ( ! empty( $fields_array ) ) { foreach ( $fields_array as $field_data ) { $fields[ $field_data['id'] ]['id'] = $field_data['id']; $fields[ $field_data['id'] ]['name'] = $field_data['name']; $fields[ $field_data['id'] ]['description'] = $field_data['description']; $fields[ $field_data['id'] ]['hidden'] = $field_data['hidden']; } } } return $fields; } // starts the dual opt-in process for the specified email address function fbz_subscribe($api_key, $email, $listid, $tags) { $url="https://app.feedblitz.com/f/?SimpleApiSubscribe&key=" . $api_key . "&email=" . $email . "&listid=" . $listid; if($tags!="") {$url=$url . "&tags=" . $tags;} $page = fbz_get_web_page($url); $xml = simplexml_load_string($page, "SimpleXMLElement", LIBXML_NOCDATA); $json = json_encode($xml); $array = json_decode($json,TRUE); return $array['rsp']['@attributes']['stat']=="ok"; // true if all is well, false otherwise } // example: Get a publisher's lists $apikey = "{{apikey}}"; // Replace {{apikey}} with the FeedBlitz user's API key. $lists = fbz_get_lists($apikey,$lists); // gets all the active lists var_dump($lists); // for debugging ?>
As always, if you have any questions, please don't hesitate to let us know. You can find all of our great support resources and how to get in touch with us via email, chat or phone on our Support Page.