Generate an invoice with a synchronous API response

Here we will make an example of how to create an invoice and return it as a result in the same API call, using a Sync URL.

These are the steps:

Configure the Interface

First, let’s configure the interface, in this case we will use the same payload our CRM will send to Flowize to get the invoice.

  • Request format: JSON
  • Request structure: Custom structure
  • Example data: Use the payload provided below

Payload example:

{
    "client": {
        "first_name": "John",
        "last_name": "Doe",
        "address": "796 Silver Harbour, TX 79273, US",
        "email": "john@example.com",
        "date": "January 17, 2020",
        "duedate": "February 17, 2020"
    },
    "company": {
        "name": "55 Foggy Heights",
        "address": "AZ 85004, US",
        "phone": "(602) 519-0450",
        "email": "company@example.com"
    },
    "invoice": {
        "project": "Website development",
        "invoice_number": "3-2-1",
        "items": [{
            "service": "Design",
            "description": "Creating a recognizable design solution based on the company's existing visual identity",
            "price": "$40.00",
            "quantity": 26,
            "total": "$1,040.00"
        }, {
            "service": "Development",
            "description": "Developing a Content Management System-based Website",
            "price": "$40.00",
            "quantity": 80,
            "total": "$3,200.00"
        }, {
            "service": "SEO",
            "description": "Optimize the site for search engines (SEO)",
            "price": "$40.00",
            "quantity": 20,
            "total": "$800.00"
        }, {
            "service": "Training",
            "description": "Initial training sessions for staff responsible for uploading web content",
            "price": "$40.00",
            "quantity": 4,
            "total": "$160.00"
        }],
        "subtotal": "$5,200.00",
        "taxes": "$1,300.00",
        "grand_total": "$6,500.00"
    }
}

Include the Content

For this example we will use an HTML template to generate the invoices with the App Html to PDF you can find in the section Apps -> Tools.

We will use “attr-dynamic” to print all the items in the invoice, as shown in the example below:

Create the Flow

Our example Flow will use the following Apps:

  • Slack: We will use this app to log the process in a Slack channel.
  • HTML to PDF: This App will convert the HTML content to a PDF, replacing all the variables in it.
  • Decision: We will use this system object to validate the output of the previous app.
  • Sync URL: We will use this app depending on a decision so we give a different API response depending on if the PDF was successfully generated.

Run a test using the Sync URL

Now we can create the Sync URL:

  • Interface: we’ll select the Interface previously created.
  • Flow: we’ll also select the previous Flow.

Click on Save button and you’ll be ready to test the process by using the CURL provided in the following view. You can just use your favourite command-line tool or any software like Postman to test APIs. 

curl -k -i -X POST 'https://demo-api.flowize.com/v1/directurl/1111-2222-3333-4444' \
-H 'Content-Type: application/json' \
-d '{
    "client": {
        "first_name": "John",
        "last_name": "Doe",
        "address": "796 Silver Harbour, TX 79273, US",
        "email": "john@example.com",
        "date": "January 17, 2020",
        "duedate": "February 17, 2020"
    },
    "company": {
        "name": "55 Foggy Heights",
        "address": "AZ 85004, US",
        "phone": "(602) 519-0450",
        "email": "company@example.com"
    },
    "invoice": {
        "project": "Website development",
        "invoice_number": "3-2-1",
        "items": [{
            "service": "Design",
            "description": "Creating a recognizable design solutions",
            "price": "$40.00",
            "quantity": 26,
            "total": "$1,040.00"
        }, {
            "service": "Development",
            "description": "Developing a Content Management System-based Website",
            "price": "$40.00",
            "quantity": 80,
            "total": "$3,200.00"
        }, {
            "service": "SEO",
            "description": "Optimize the site for search engines (SEO)",
            "price": "$40.00",
            "quantity": 20,
            "total": "$800.00"
        }, {
            "service": "Training",
            "description": "Initial training sessions for staff responsible for uploading web content",
            "price": "$40.00",
            "quantity": 4,
            "total": "$160.00"
        }],
        "subtotal": "$5,200.00",
        "taxes": "$1,300.00",
        "grand_total": "$6,500.00"
    }
}'