invoice API for Ruby
Invoice API for Ruby
Create an invoice from Ruby with Net::HTTP. Parse the JSON and keep the customer link with the job, not in the log line that includes the API key.
Base URL https://invoicetxt.com Auth Authorization: Bearer itxt_live_…
POST/v1/invoices
Create an invoice
Net::HTTP is in the standard library. The example sets open and read timeouts so a stuck connection fails instead of waiting on the default.
require 'json'
require 'net/http'
uri = URI('https://invoicetxt.com/v1/invoices')
req = Net::HTTP::Post.new(uri)
req['Authorization'] = "Bearer #{ENV.fetch('INVOICETXT_API_KEY')}"
req['Content-Type'] = 'application/json'
req.body = {
client: 'Brightwell Group',
due: 'net 14',
items: [{ description: 'Strategy session', quantity: 4, rate: 225 }]
}.to_json
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true, open_timeout: 5, read_timeout: 12) { |http| http.request(req) }
invoice = JSON.parse(res.body)Record an acknowledgement
When your customer confirms the invoice in your own portal, POST the name to /v1/invoices/{id}/sign. Store the signed_at value from the response next to the job. Do not send a second name. The second call returns 409.