Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 87 lines (76 sloc) 2.566 kb
c840490 initial
Jordan Boesch authored
1 # FreshBooksRequest PHP API
2
3 This class is meant to give you the ability to quickly access the FreshBooks API.
4
5 ## Usage
6
7 * You need to know the method names and params when you're creating a new FreshBooksRequest instance. See all here http://developers.freshbooks.com/
8 * The XML tag parameters you see on the freshbooks API page are the ones you pass to $fb->post() (as an array)
9 * Require the lib and setup with your credentials (domain and token)
10
11 ```php
12 require('lib/FreshBooksRequest.php');
13
14 $domain = 'your-subdomain'; // https://your-subdomain.freshbooks.com/
15 $token = '1234567890'; // your api token found in your account
4f60a9e fixing readme
Jordan Boesch authored
16 FreshBooksRequest::init($domain, $token);
c840490 initial
Jordan Boesch authored
17 ```
18 * Now let's say we want to list clients with an email of some@email.com
19
20 ```php
21 /**********************************************
22 * Fetch all clients by a specific id
23 **********************************************/
24 // Method name found on the freshbooks API
25 $fb = new FreshBooksRequest('client.list');
26 // Any arguments you want to pass it
27 $fb->post(array(
28 'email' => 'some@email.com'
29 ));
30 // Make the request
31 $fb->request();
32 if($fb->success())
33 {
34 echo 'successful! the full response is in an array below';
35 print_r($fb->getResponse());
36 }
37 else
38 {
39 echo $fb->getError();
40 print_r($fb->getResponse());
41 }
42 ```
43 * If you're creating a recurring profile with multiple line items, it might look something like this:
44
45 ```php
46 /**********************************************
47 * Create a recurring profile with multiple line items
48 **********************************************/
49 $fb = new FreshBooksRequest('recurring.create');
50 $fb->post(array(
51 'recurring' => array(
52 'client_id' => 41,
53 'lines' => array(
54 'line' => array(
55 array(
56 'name' => 'A prod name',
57 'description' => 'The description',
58 'unit_cost' => 10,
59 'quantity' => 2
60 ),
61 array(
62 'name' => 'Another prod name',
63 'description' => 'The other description',
64 'unit_cost' => 20,
65 'quantity' => 1
66 )
67 )
68 )
69 )
70 ));
71 // You can view what the XML looks like that we're about to send over the wire
72 //print_r($fb->getGeneratedXML());
73 $fb->request();
74 if($fb->success())
75 {
76 $res = $fb->getResponse();
77 $recurrng_id = $res['recurring_id'];
78 // Do something with the recurring_id you were returned
79 }
80 ```
81
82 ## Change Log
83
84 ### Changes in 1.0 (Sept 18, 2011)
85
86 * Launched!
Something went wrong with that request. Please try again.