No internet connection
  1. Home
  2. Mutual aid

Rest Api : How to get the pdf of an invoice

By @cedric_hubert
    2024-10-15 09:10:29.780Z

    Hello,

    Is there a way to get the pdf of a specific invoice by the Rest API?

    Best regards

    • 5 replies
    1. Jeroen Hayen @jeroenhayen
        2024-10-15 09:32:21.832Z

        Hello

        Hereby the Rest API documentation link: https://frappeframework.com/docs/user/en/api/rest
        For this to work, you will need to configure a new user in iOi with the correct acces rights, to the required modules.

        When a pdf is attached to an invoice, it is possible to recover it.

        1. C@cedric_hubert
            2024-10-15 09:56:28.494Z

            Thank you for your answer Jeroen

            It isn't an attached pdf. What I need is to launch the printing of the invoice and get the pdf file

            1. V@vincent_vrithof
                2024-10-15 10:01:51.802Z

                Hi Cedric,

                Have you tried something like this (found on the Frappe Forum) ? :

                import requests

                host = 'hostname or ip'
                doctype='Item'
                docname='item.name'
                print_format ='Standard'
                url = f"http://{host}/api/method/frappe.utils.print_format.download_pdf?doctype={doctype}&name={docname}&format={print_format}&no_letterhead=0"
                api_key = 'api-key'
                api_secret = 'api-secret'
                header = {"Authorization": "token {}:{}".format(api_key, api_secret)}
                res = requests.get(url, headers=header, verify=False)
                print(res)
                with open(f'{doctype}-{docname}-{print_format}.pdf', 'wb') as f:
                f.write(res.content)

                1. C@cedric_hubert
                    2024-10-21 14:02:57.691Z

                    Thank you Vincent but unfortunately we doesn't get the good layout that way.

                    We need the default ioi sales invoice layout like this one :

                    1. V@vincent_vrithof
                        2024-10-22 12:05:42.573Z

                        Hello Cedric,

                        I don't know if it's possible then.
                        My colleague @michael_terceno is way more knowledgeable than I am about the reporting and printing technical details.
                        He'll be back in the office in a few days. I think he'll be able to give us a definitive answer.