Skip to content

Instantly share code, notes, and snippets.

@pedrocunha
Created December 5, 2011 21:25
Show Gist options
  • Save pedrocunha/1435430 to your computer and use it in GitHub Desktop.
Save pedrocunha/1435430 to your computer and use it in GitHub Desktop.
Invoicexpress API - Python Example
import httplib, urllib
account_name = 'XXXX'
api_key = 'XXXXX'
url = account_name + '.invoicexpress.net:443'
endpoint = '/invoices.xml?api_key=' + api_key
headers = {
'Content-type' : 'application/xml; charset=utf-8',
'Accept' : 'text/plain'
}
params = '<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
<invoice>\
<date>19/10/2009</date>\
<due_date>19/10/2009</due_date>\
<client>\
<name>Bruce Norris</name>\
</client>\
<items type=\"array\">\
<item>\
<name>Product 1</name>\
<description>Cleaning product</description>\
<unit_price>10.0</unit_price>\
<quantity>1.0</quantity>\
<unit>unit</unit>\
</item>\
</items>\
</invoice>'
conn = httplib.HTTPSConnection(url)
conn.request("POST", endpoint, params, headers)
response = conn.getresponse()
print response.status, response.reason
data = response.read()
data
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment