Rest Api : How to get the pdf of an invoice
Hello,
Is there a way to get the pdf of a specific invoice by the Rest API?
Best regards
Jeroen Hayen @jeroenhayenHello
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.
- C@cedric_hubert
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

- V@vincent_vrithof
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)- C@cedric_hubert
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 :

- V@vincent_vrithof
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.