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.

#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.