Appearance
Example
In this document we will show you how to use Cassiopeia to create an invoice as pdf from your app.
Let's say you're developing an app, that generates invoices for your customers. You want to generate a PDF from a template and send it to your customer.
Step 1: Create a word template
You can use multiple template formats as input. In this example we will use a DOCX template. Just write a example invoice in Word and save it as a DOCX file.
Let's say you have a file invoice.docx
that looks like this example file.
Step 2: Add placeholder variables
To keep it simple in this example, we won't replace everything but only the date and the invoice number, but you can replace any text in the document.
Thus we change the DOCX template and replace INVOICE #01010
with INVOICE #{{$invoiceNumber}}
. Also we replace the invoice number in the headline.
Finally we replace the date 12.12.2025
with {{$date}}
.
The template now looks like this file.
Step 3: Implement the API call
We will use curl in the examples, because everyone can read it and can try it on the command line. Of course you would use your favorite HTTP library in your code to communicate with the API.
We need to pass the template file as base64 encoded string in the request body. Therefore we use the base64
command to encode the file.
Also we will provide the values for the variables, that will be used.
Please remember to replace YOUR_API_KEY
with your actual API key.
bash
curl -X POST https://www.cassiopeia-api.cloud/api/documents \
-H "Authorization: Bearer YOUR_API_KEY" \
-F files[]=@docs/public/invoice-example-2.docx \
-F respond_with=download \
-F variables["invoiceNumber"]="1337" \
-F variables["date"]="01.01.2025" \
-o invoice.pdf
Step 4: Get the PDF
The response will contain a PDF file which looks like this: invoice.pdf.