Invoice
Introduction
The objective of this guide is to take you through the process of generating a simple PDF invoice you can send to your customers, in tax regimes that don’t require an electronic reporting or invoicing.
For this example we assuming the following conditions:
-
Our company is VAT registered in the UK.
-
We have the basic information about the invoice: date, supplier, customer, and items with their VAT rates to apply to each.
-
Our invoices do not have a sequential code, but we want one that looks like
TEST-000001
. -
Customers expect a PDF.
-
We want an email copy of our invoice.
You don’t need to be a developer to use this guide, but you will need to have a bit of experience using the command line and know how to create a text file. For sending requests to the server we use the “curl” command, included with most operating systems. You might however find it easier to use a visual tool for sending HTTP requests like Postman.
We assume here that you’ve already followed the steps in the Authentication guide, and have an access token ready to use.
To give you a heads up, these are the stages we’ll be going through:
-
Build a new workflow with a set of steps to execute
-
Upload a document
-
Create a Job
-
Download the results
Let’s get started.
Define a Workflow
A Workflow in Invopop is essentially a list of steps that will be executed one-by-one for an incoming job. Each step is linked with a provider of a given service, like generating a PDF, forwarding invoices to an external tax agency, sending emails, or posting webhooks.
-
Head to the Workflows section.
-
Tap ”+ New”.
-
Then, select Invoice and tap Create Workflow.
-
Use the Name field to give this new workflow an easy way to be identified, like “Process Invoice”.
In the following sections we’ll run through adding each step.
Add Sequential Code
Series are used to assign sequential numbers to documents, typically invoice codes, and guarantee their order.
-
Tap the ”+” button to add a new step to the workflow.
-
From the list of providers on the right, find and click on Add Sequential Code.
-
Ensure the Configuration tab is selected.
-
Select the “dynamic” sequence option in the select box. This will automatically create a new sequential codes for each combination of Supplier Tax ID Code and invoice series.
-
Set the “Name” to “Invoices”.
-
Tap the “Sign document” checkbox at the bottom of the form, this will ensure invoices contain a digital signature.
The configurtion is updated in real-time, so there are no additional steps to perform.
Generate PDF
The Invopop PDF Generator is used to convert GOBL documents into human readable PDF files that can be shared with customers.
-
Tap the ”+” button under the “Add Sequential Code” step.
-
From the list of providers on the right, find Generate PDF and click.
-
Tap “Configure” tab.
-
Choose a language for the invoices and upload a company logo if you have one to hand. Also select or change any of the settings you think might be relevant for you.
Send via email
It can be useful to send emails to customers or billing departments with details about the invoices that have been generated. This example utilizes Invopop’s email sending service to process emails. If you want to use your own email domain for sending, checkout the “Resend” step.
-
Tap the ”+” button under the “Generate PDF” step.
-
From the list of providers, click Send via Email.
-
Click “Configure” tab.
-
Introduce a destination in the “To:” or “BCC:” fields by typing the address either in regular or “mailbox” format. (mailbox format includes name, e.g.
John Smith <john.smith@example.com>
). -
Alter any of the other fields that are appropriate for the email.
-
Tap the “Automatically add invoice customers” checkbox if you’d like to send copies of emails to customers defined in invoices.
Save
Having completed all these sections, you should now have 3 steps in the workflow.
Before leaving, we can check the JSON of the workflow by clicking the toggle next to “Save” in the top bar. This allows us to see and edit the raw JSON workflow definition. It should look like the following:
Return to the visual view, and tap the “Save” button at the top right. In the Workflows list page you should be able to copy the UUID for the new workflow, which we’ll need for later examples.
Upload a Document
We’ve prepared a workflow with a set of integrations to process and convert invoices. Our next step is to upload a document to be processed by the workflow and extract the results.
At Invopop we use GOBL as our base format. It’s been purpose built (by us) to make it easy to create business documents using JSON and contain everything needed to be globally compatible.
If you haven’t had chance to read the GOBL Docs, there are two basic concepts that are important to understand:
-
A GOBL Object represents a payload; an invoice, message, contact details, or some other unit of business data, defined using a JSON Schema that GOBL understands.
-
A GOBL Envelope is a wrapper around a GOBL Object that adds meta-data like a digest and digital signatures.
At Invopop, we only ever store GOBL Envelopes. This is important as it means we can verify the contents and ensure no changes have been made. Most interfaces and APIs in Invopop however will automatically wrap GOBL Objects inside Envelopes, so you don’t need to worry about it when uploading, but you will need to take this into account when downloading.
In the next steps we’re going to need a sample partial GOBL Invoice document to upload, here’s one we created earlier:
The most important bits of data to take away from this document are the:
-
JSON schema that identifies the GOBL invoice type,
-
series and currency,
-
supplier and customer, with their VAT ID codes, and,
-
lines of items of a given quantity and price to which VAT at a “standard” rate needs to be applied.
Note we used the word partial earlier to describe this document. It’s not a complete and valid GOBL object as it doesn’t contain important details like the invoice code, issue date, or tax totals.
A document without the missing required data cannot be signed. Some workflow steps require envelopes to be signed as this offers guarantees that the information has not been modified. As we’ll see shortly, once uploaded to Invopop, the API and workflow we created earlier will automatically assign an invoice code, issue date, and make the required calculations so it can be signed.
For more details on creating Invoices, see the GOBL Documentation Site. You’ll find more guides there on all the different options and configurations available for invoices, including ways you can build complete GOBL Envelopes with signatures.
Let’s upload this document to the Invopop Silo service:
-
Copy and paste the JSON above into you favorite text editor.
-
Save the JSON into a file named
invoice.json
in a temporary folder you can easily find from the command line (Downloads
is usually a safe bet). -
Open the Terminal or command line, and enter the temporary directory, e.g.
cd ~/Downloads
. -
Upload the document using the following Curl command:
The response back from the server will be similar to the following:
Let’s go over some of the important points in that response:
-
everything is wrapped inside a response containing the data and copies of key fields like the schemas, digest, and draft status,
-
we’ve created an entry in the silo. “Silo” is the name we gave to the place where you store your GOBL Envelopes,
-
there is an
id
orsilo_entry_id
property that uniquely identifies this entry in the silo, -
the
data
property includes a complete GOBL Envelope with the invoice, -
the invoice has now been completed with all the totals and tax calculations, and,
-
the invoice’s
code
field is still empty.
We don’t recommend making HTTP POST
calls like in this example as they do
not include an ID that would make the request
idempotent. This is fine for
testing, but in production environments, you should pre-assign a UUID (v1) to
the request and include it in the path in a PUT
call. This way, if for some
reason the request gets repeated, you’ll only have one copy.
Create a Job
Now for the exciting part. But first, let’s recap what we have:
-
A workflow with a set of steps to execute, with an ID.
-
A silo entry ID generated in the last request when we uploaded the Invoice.
Let’s put all these together and execute a job. Here’s the command to perform from the terminal and don’t forget to update the IDs with your values that were generated for the workflow and silo entry:
There is a lot of JSON data there, but let’s break it down into the key bits of data:
-
Everything is wrapped inside a “Job” object with the key fields like
workflow_id
andsilo_entry_id
. -
Job
status
showsOK
indicating that this job has been completed successfully. -
The
intents
list describes all the steps the job has gone through for each of the connectors defined in the workflow. -
envelope
contains a copy of the invoice we uploaded earlier except it has now been assigned a code and signed. -
attachments
includes a link to the PDF file that was generated.
Download the Results
Having completed a job, we can view the results in the
Invopop Console or download the results directly
based on the previous response. Take a look at the attachments
attribute. Each
attachment has a URL attribute that we can use to download the contents and then
open the file:
You can also download the attachment directly in your browser by copying and pasting the URL.