Generate PDF using API

Using the API, we can retrieve almost anything we want from the database - including all relevant details about an invoice. We could theoretically construct a PDF using that information.

However, I’d like an API route that lets us generate it using the built-in generator that Manager uses for the PDF button. This will ensure that any PDFs generated look identical to the ones that are generated from within the app. The route would return a PDF document, rather than a JSON response.

This might be relevant: Link to Stack Overflow question

1 Like

I’d like to bump this topic, if possible, and bring in @lubos to have a quick look at it.

Essentially, if we can request the PDF via the API, we can also implement complex logic in our own applications to save us time generating PDFs manually.

Two main use-cases that I can think of:

  • External application caching invoice PDF, and allowing the customer to re-download whenever they want (e.g. customer portal)
  • Generate and email multiple invoices automatically at the end of the month, solving requests like this one programmatically: Multiple (20) Recurring Sales invoice mailing

This could be possible in the future. Currently I’m trying to separate data model from UI so any report could be queried using API (not just raw data). It makes sense to allow API to convert PDF or send emails too.

2 Likes

@ShaneAU

I am not a programmer so I don;t really understand how application programming interfaces work, but reading what you said it sounds like something that I might be interested in.

To explain what I am doing next month. I have hired a .net programmer to develop a customer relations portal for me. This will consist of things like IT Job Requests, Project Todo Management, IT Visits schedule etc.

On the Finances Page, I am going to have quotes, orders and invoices available for view for everyone of my clients.

If I have understood you correctly, one could use the API to create pdf’s for quotes, orders and invoices for clients and these pdf’s would be viewable in the online database. Potentially I could extract information like pictures of a specific laptop in Manager inventory onto the customer relations portal inventory and things like that.

Have I understood how api works - if so I could ask my programmer when developing the Finances and Inventory sections to look into extracting information from Manager as a lot of information on the customer portal will be in Manager.

Excellent. I’m excited to see the results of these changes in the future - querying a report from the API was not something I had considered, but would certainly open up some interesting possibilities.

You will need to discuss your exact requirements with the programmer directly, after they have had a chance to look at the Manager API. That way, they can help you to determine what is / is not possible.

I am building a customer portal myself. One thing I’ve noticed is that if you access a Sales Invoice using the API, it doesn’t include details on whether or not that invoice has been paid. You will need to have the portal access payments separately if you want to calculate a customer’s current balance. Don’t assume that everything you see when you log into Manager is immediately available via the API in the same way.

Well as the API is not ready yet - the CRM database is being created next month, I don’t think that there will be much point in asking the programmer to integrate with Manager right now. Particularly as he has quoted for a database where we are not pulling information from anywhere other than the calendar.

I was just wondering if the concept was valid and if so, in a couple of years time when I have more money in the budget, I can then start investigating pulling the data from Manager. I think it would be premature to do it now. But certainly sounds like a good idea in the future when little niggles like invoice paid etc is also synced.

Thank you.

In the latest version (18.8.5), you can now retrieve PDF using API.

Let’s say you want to generate PDF for sales invoice. Have a look at the URL of invoice view which would be something like this…

/sales-invoice-view?Key=c738c447-d700-430b-9956-010046a32776&FileID=5fa5dd21-0ca9-4672-b242-486895c40f5e

to get PDF, just add .pdf extension to /sales-invoice-view resource so it’s:

/sales-invoice-view.pdf?Key=c738c447...

2 Likes

Thanks, greatly appreciated. I’ll test it as soon as I can.

@lubos when I generate the files this way, when I try to open then I get an error. The file seems to be corrupted. If I generate it in the classical way everything works fine.

It works for me fine. So what error do you get?

They just don’t open. Adobe Reader says it’s not a pdf file

@Davide If you open it with a text editor does the structure look similar to other pdf files or is it grossly wrong such as an empty file

It’s empty. 0K file

Hello @lubos

This works well for the most part, thanks for implementing it. The only issue I can see is that the business logo does not load:

Using Server Edition 18.12.18

Should be fixed in the latest version (19.1.21)

2 Likes

hey i upgrated to version Server Edition 20.2.83 and now when i add .pdf like myurl.com/sales-invoice-view.pdf?Key=ccd… then nothing happens. it worked like a charm before upgrading

Has this been fixed as I am about to setup an API link to my CRM System and one of the things that I want to do is enable clients to create pdf’s for any of their sales invoices.

Otherwise I will log a bug report to get this fixed.

Hi Shane,
Please give me a heads up, I need to do exactly what you describe here. 1) Create a customer portal where the customers can download invoices and 2) Automate emailing of recurring sales invoices.

Please let me know if you have successfully implemented this and if you can give any advise?

You are going to have trouble doing that:

  1. Recurring sales invoices do not exist until they have been individually created. Recurring sales invoices are templates for creating transactions, not transactions.
  2. Manager does nothing automatically. In a few cases, it notifies you of actions that are due, such as creating those recurring sales invoices. But it does not create them for you.

Thank you for responding Tut. Yes I understand that recurring invoices are templates and they only become transactions once they are Updated. I am thinking along the lines of creating a customer portal via API where a customer can view all his invoices and sending out an email with a link to the customer portal indicating that new invoices exist once I have updated all the recurring invoices. i.e. Not sending out the actual invoices but notifying the customers that new invoices has been created and they should check the customer portal.