Sample Code
Below is some sample code for connecting with our API. Please note you will need to generate an API key for this to work, for more information on this see our API Reference page.
Code
The code below is for a CodeIgniter 2.0 PHP application.
<?php defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Example Project Bubble Backup App
*
* This is an example code that will back up your data.
*
* @package CodeIgniter
* @category Controller
* @author Stu Green
* @link http://projectbubble.com/developers/
*/
class Example extends Controller
{
function backup()
{
// what is your subdomain?
$subdomain = 'test.projectbubble.com';
// what is your key
$key = 'foo123456789';
if (!empty($key))
{
// load libs
$this->load->library('zip');
// add data
$this->zip->add_data('user.xml',
$this->_curl_get($subdomain.'/api/user?X-PROJECTBUBBLE-KEY='.$key));
$this->zip->add_data('company.xml',
$this->_curl_get($subdomain.'/api/company?X-PROJECTBUBBLE-KEY='.$key));
$this->zip->add_data('projects.xml',
$this->_curl_get($subdomain.'/api/projects?X-PROJECTBUBBLE-KEY='.$key));
$this->zip->add_data('tasks.xml',
$this->_curl_get($subdomain.'/api/tasks?X-PROJECTBUBBLE-KEY='.$key));
$this->zip->add_data('time.xml',
$this->_curl_get($subdomain.'/api/time?X-PROJECTBUBBLE-KEY='.$key));
$this->zip->add_data('comments.xml',
$this->_curl_get($subdomain.'/api/comments?X-PROJECTBUBBLE-KEY='.$key));
$this->zip->add_data('clients.xml',
$this->_curl_get($subdomain.'/api/clients?X-PROJECTBUBBLE-KEY='.$key));
$this->zip->add_data('contacts.xml',
$this->_curl_get($subdomain.'/api/contacts?X-PROJECTBUBBLE-KEY='.$key));
$this->zip->add_data('expenses.xml',
$this->_curl_get($subdomain.'/api/expenses?X-PROJECTBUBBLE-KEY='.$key));
$this->zip->add_data('invoices.xml',
$this->_curl_get($subdomain.'/api/invoices?X-PROJECTBUBBLE-KEY='.$key));
$this->zip->add_data('estimates.xml',
$this->_curl_get($subdomain.'/api/estimates?X-PROJECTBUBBLE-KEY='.$key));
// download ZIP
$this->zip->download('pb-backup-'.time());
}
else
{
die('No key');
}
}
function _curl_get($url = '')
{
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 5);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
}




