Skip to main content

A client library for the FreshBooks API

Project description

Refreshbooks provides a simple synchronous API for manipulating FreshBooks
invoices, clients, and other data::

from refreshbooks import api

c = api.OAuthClient(
'example.freshbooks.com',
'consumerkey',
'My Consumer Secret',
'An existing token',
'An existing token secret',
user_agent='Example/1.0'
)

# XML structure inferred from args
response = c.invoice.create( # <request method="invoice.create">
invoice=dict( # <invoice>
client_id='8', # <client_id>8</client_id>
lines=[ # <lines>
api.types.line( # <line>
name='Yard Work', # <name>Yard Work</name>
unit_cost='10', # <unit_cost>10</unit_cost>
quantity='4' # <quantity>4</quantity>
) # </line>
] # </lines>
) # </invoice>
) # </request>

invoice_response = c.invoice.get( # <request method="invoice.get">
invoice_id=response.invoice_id # <invoice_id>...</invoice_id>
) # </request>

print "New invoice created: #%s (id %s)" % (
invoice_response.invoice.number,
invoice_response.invoice.invoice_id
)

invoices_response = c.invoice.list() # <request method="invoice.list" />

print "There are %s pages of invoices." % (
invoices_response.invoices.attrib['pages'],
)

for invoice in invoices_response.invoices.invoice:
print "Invoice %s total: %s" % (
invoice.invoice_id,
invoice.amount
)

Consumer keys and secrets can be obtained from FreshBooks. This library
does not handle negotiating for an OAuth token+secret pair; see the
`oauth` module or the OAuth specification for details.

This library also supports the older token-based API authorization
scheme::

c = api.TokenClient(
'example.freshbooks.com',
'My API token',
user_agent='Example/1.0'
)

# ... as above ...

API methods return lxml.objectify.ObjectifiedDataElement trees, which
can be manipulated as Python objects with the same structure as the
underlying XML.

If you are having trouble accessing items as in:

items_response = c.items.list()
for item in items_response.items.item:
print item.item_id

Adjust your syntax to use dictionary item lookup:

items_response = c.items.list()
for item in items_response['items'].item:
print item.item_id

ObjectifiedDataElement provides a method named items which shadows the
items element in the response. Accessing items with dictionary lookup
syntax is the known work-around.

To run tests:

python setup.py nosetests

To run network-accessing integration tests against httpstat.us:

python setup.py nosetests --attr=integration

References:

- http://developers.freshbooks.com/ - The FreshBooks API
- http://developers.freshbooks.com/authentication-2/#OAuth - FreshBooks and OAuth

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

refreshbooks-1.7.2.tar.gz (13.4 kB view details)

Uploaded Source

Built Distributions

refreshbooks-1.7.2-py2.7.egg (21.4 kB view details)

Uploaded Egg

refreshbooks-1.7.2-py2.6.egg (21.4 kB view details)

Uploaded Egg

File details

Details for the file refreshbooks-1.7.2.tar.gz.

File metadata

  • Download URL: refreshbooks-1.7.2.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for refreshbooks-1.7.2.tar.gz
Algorithm Hash digest
SHA256 1f60f6d51639c7c622ca7014cf0ade4e6865ef0a09408889ce15453e6387bd34
MD5 3f2c98bbe089842d0556a7c3cb740d04
BLAKE2b-256 87f0199c85af0aa87f69db4dfc682cb552e61c6273b84fe02dff3546ef6f5157

See more details on using hashes here.

File details

Details for the file refreshbooks-1.7.2-py2.7.egg.

File metadata

File hashes

Hashes for refreshbooks-1.7.2-py2.7.egg
Algorithm Hash digest
SHA256 057fee4988afacd31bb4ad5c9da51864c85ba6953f772f5d4102851008e47534
MD5 61e36c5cd7c4d9d86b7573e7b13220a9
BLAKE2b-256 b324554dbb10036b325a44573a053196832b7de344c07db124ada83f63261c0e

See more details on using hashes here.

File details

Details for the file refreshbooks-1.7.2-py2.6.egg.

File metadata

File hashes

Hashes for refreshbooks-1.7.2-py2.6.egg
Algorithm Hash digest
SHA256 bce46f9d669c43e8e54054837e4942d242887735f5cf15e2fae0076fa01c54e7
MD5 a0c9f77631f322d789bc49b81c7c34c0
BLAKE2b-256 de0358d4bb63bb596c2870b882fa0d0d6491b1ae9fac2b5b5e192b15cce17ba1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page