have an account? sign in
AssistPhone

FACTURAgem is our invoicing solution specialized in the Spanish market, with customized taxes, options and support for Spain.

If you invoice from a different country, you'd probaly prefer to use our international version: invoicefu.

Heroku integration examples

The following examples show how to create an invoice using the ruby programming language and the restclient library. You should be able to adapt the examples to your favourite language/client easily. All you need is a http client supporting the GET, POST, PUT and DELETE verbs, and a json (or XML) parser.

Creating invoices with the API

There are three REST calls in this example: first you will get information about your account in FACTURAgem, then you will use the API to populate a JSON object with the default values for your account (general account information, currency, invoice number, taxes...). You will finally set values for your client and for the services/goods being invoiced and issue a POST to create the invoice.

require 'rubygems'
require 'restclient'
require 'json'

#read your FACTURAgem credentials from heroku environment
auth_params = {:app_platform=>ENV['INVOICEFU_APP_PLATFORM'], :app_id=> ENV['INVOICEFU_APP_ID'], :api_key=>ENV['INVOICEFU_API_KEY']}

#get information about your FACTURAgem account. It will provide the endpoints for viewing/managing clients and invoices
remote_account = RestClient::Resource.new( "https://facturagem.com/api/v1/accounts.json" ).get :params => auth_params, :content_type => :json
account = JSON.parse( remote_account.to_s )['account']

#get an empty JSON template with the default values for a new invoice
invoice_template_url = account['links'].detect{|l| l['rel']=='new_invoice'}['uri']
remote_template = RestClient::Resource.new( invoice_template_url ).get :params => auth_params, :content_type => :json
invoice = JSON.parse( remote_template.to_s )['invoice']

#fill in the data for your invoice
invoice['cl_name'] = 'aspgems'
invoice['cl_reference_code'] = 'CL01' #for your convenience, you can provide a unique code that identifies this client in your system
invoice['cl_address'] = 'sextante 9'
invoice['cl_city'] = 'madrid'
invoice['cl_postal_code'] = '28023'
invoice['reference_code'] = '0199902' #for your convenience, you can provide a unique code that identifies this in your system, for example the order number

#now we add the lines of the invoice providing amount, description and price for each line
invoice['invoice_lines'] << { :amount=>1, :price=>99.99, :description=>'FACTURAgem yearly premium subscription' }

#and we are ready for sending the JSON to FACTURAgem so the invoice will be created
invoices_url = account['links'].detect{|l| l['rel']=='invoices'}['uri']
remote_invoice = RestClient::Resource.new( invoices_url ).post invoice.merge(auth_params).to_json, :content_type => :json

Account Information Title

There is a single REST call in this example. As a result, you will be getting a JSON (or XML if you prefer) object with general information about your account: business name, address, currency, default taxes.. You will also get the endpoint URLs to use for viewing/managing your invoices and clients.

require 'rubygems'
require 'restclient'
require 'json'

#read your FACTURAgem credentials from heroku environment
auth_params = {:app_platform=>ENV['INVOICEFU_APP_PLATFORM'], :app_id=> ENV['INVOICEFU_APP_ID'], :api_key=>ENV['INVOICEFU_API_KEY']}

#get information about your FACTURAgem account. It will provide the endpoints for viewing/managing clients and invoices
remote_account = RestClient::Resource.new( "https://facturagem.com/api/v1/accounts.json" ).get :params => auth_params, :content_type => :json
account = JSON.parse( remote_account.to_s )['account']